ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 28 | // Handle id counters. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 29 | var next_handle_ = 0; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 30 | var next_transient_handle_ = -1; |
| 31 | |
| 32 | // Mirror cache. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 33 | var mirror_cache_ = []; |
| 34 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 35 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 36 | /** |
| 37 | * Clear the mirror handle cache. |
| 38 | */ |
| 39 | function ClearMirrorCache() { |
| 40 | next_handle_ = 0; |
| 41 | mirror_cache_ = []; |
| 42 | } |
| 43 | |
| 44 | |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 45 | /** |
| 46 | * Returns the mirror for a specified value or object. |
| 47 | * |
| 48 | * @param {value or Object} value the value or object to retreive the mirror for |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 49 | * @param {boolean} transient indicate whether this object is transient and |
| 50 | * should not be added to the mirror cache. The default is not transient. |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 51 | * @returns {Mirror} the mirror reflects the passed value or object |
| 52 | */ |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 53 | function MakeMirror(value, opt_transient) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 54 | var mirror; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 55 | |
| 56 | // Look for non transient mirrors in the mirror cache. |
| 57 | if (!opt_transient) { |
| 58 | for (id in mirror_cache_) { |
| 59 | mirror = mirror_cache_[id]; |
| 60 | if (mirror.value() === value) { |
| 61 | return mirror; |
| 62 | } |
| 63 | // Special check for NaN as NaN == NaN is false. |
| 64 | if (mirror.isNumber() && isNaN(mirror.value()) && |
| 65 | typeof value == 'number' && isNaN(value)) { |
| 66 | return mirror; |
| 67 | } |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 68 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 69 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 70 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 71 | if (IS_UNDEFINED(value)) { |
| 72 | mirror = new UndefinedMirror(); |
| 73 | } else if (IS_NULL(value)) { |
| 74 | mirror = new NullMirror(); |
| 75 | } else if (IS_BOOLEAN(value)) { |
| 76 | mirror = new BooleanMirror(value); |
| 77 | } else if (IS_NUMBER(value)) { |
| 78 | mirror = new NumberMirror(value); |
| 79 | } else if (IS_STRING(value)) { |
| 80 | mirror = new StringMirror(value); |
| 81 | } else if (IS_ARRAY(value)) { |
| 82 | mirror = new ArrayMirror(value); |
| 83 | } else if (IS_DATE(value)) { |
| 84 | mirror = new DateMirror(value); |
| 85 | } else if (IS_FUNCTION(value)) { |
| 86 | mirror = new FunctionMirror(value); |
| 87 | } else if (IS_REGEXP(value)) { |
| 88 | mirror = new RegExpMirror(value); |
| 89 | } else if (IS_ERROR(value)) { |
| 90 | mirror = new ErrorMirror(value); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 91 | } else if (IS_SCRIPT(value)) { |
| 92 | mirror = new ScriptMirror(value); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 93 | } else { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 94 | mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | mirror_cache_[mirror.handle()] = mirror; |
| 98 | return mirror; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /** |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 103 | * Returns the mirror for a specified mirror handle. |
| 104 | * |
| 105 | * @param {number} handle the handle to find the mirror for |
| 106 | * @returns {Mirror or undefiend} the mirror with the requested handle or |
| 107 | * undefined if no mirror with the requested handle was found |
| 108 | */ |
| 109 | function LookupMirror(handle) { |
| 110 | return mirror_cache_[handle]; |
| 111 | } |
| 112 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 113 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 114 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 115 | * Returns the mirror for the undefined value. |
| 116 | * |
| 117 | * @returns {Mirror} the mirror reflects the undefined value |
| 118 | */ |
| 119 | function GetUndefinedMirror() { |
| 120 | return MakeMirror(void 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
| 124 | /** |
| 125 | * Inherit the prototype methods from one constructor into another. |
| 126 | * |
| 127 | * The Function.prototype.inherits from lang.js rewritten as a standalone |
| 128 | * function (not on Function.prototype). NOTE: If this file is to be loaded |
| 129 | * during bootstrapping this function needs to be revritten using some native |
| 130 | * functions as prototype setup using normal JavaScript does not work as |
| 131 | * expected during bootstrapping (see mirror.js in r114903). |
| 132 | * |
| 133 | * @param {function} ctor Constructor function which needs to inherit the |
| 134 | * prototype |
| 135 | * @param {function} superCtor Constructor function to inherit prototype from |
| 136 | */ |
| 137 | function inherits(ctor, superCtor) { |
| 138 | var tempCtor = function(){}; |
| 139 | tempCtor.prototype = superCtor.prototype; |
| 140 | ctor.super_ = superCtor.prototype; |
| 141 | ctor.prototype = new tempCtor(); |
| 142 | ctor.prototype.constructor = ctor; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | // Type names of the different mirrors. |
| 147 | const UNDEFINED_TYPE = 'undefined'; |
| 148 | const NULL_TYPE = 'null'; |
| 149 | const BOOLEAN_TYPE = 'boolean'; |
| 150 | const NUMBER_TYPE = 'number'; |
| 151 | const STRING_TYPE = 'string'; |
| 152 | const OBJECT_TYPE = 'object'; |
| 153 | const FUNCTION_TYPE = 'function'; |
| 154 | const REGEXP_TYPE = 'regexp'; |
| 155 | const ERROR_TYPE = 'error'; |
| 156 | const PROPERTY_TYPE = 'property'; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 157 | const FRAME_TYPE = 'frame'; |
| 158 | const SCRIPT_TYPE = 'script'; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 159 | const CONTEXT_TYPE = 'context'; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 160 | const SCOPE_TYPE = 'scope'; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 161 | |
| 162 | // Maximum length when sending strings through the JSON protocol. |
| 163 | const kMaxProtocolStringLength = 80; |
| 164 | |
| 165 | // Different kind of properties. |
| 166 | PropertyKind = {}; |
| 167 | PropertyKind.Named = 1; |
| 168 | PropertyKind.Indexed = 2; |
| 169 | |
| 170 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 171 | // A copy of the PropertyType enum from global.h |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 172 | PropertyType = {}; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 173 | PropertyType.Normal = 0; |
| 174 | PropertyType.Field = 1; |
| 175 | PropertyType.ConstantFunction = 2; |
| 176 | PropertyType.Callbacks = 3; |
| 177 | PropertyType.Interceptor = 4; |
| 178 | PropertyType.MapTransition = 5; |
| 179 | PropertyType.ConstantTransition = 6; |
| 180 | PropertyType.NullDescriptor = 7; |
| 181 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 182 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 183 | // Different attributes for a property. |
| 184 | PropertyAttribute = {}; |
| 185 | PropertyAttribute.None = NONE; |
| 186 | PropertyAttribute.ReadOnly = READ_ONLY; |
| 187 | PropertyAttribute.DontEnum = DONT_ENUM; |
| 188 | PropertyAttribute.DontDelete = DONT_DELETE; |
| 189 | |
| 190 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 191 | // A copy of the scope types from runtime.cc. |
| 192 | ScopeType = { Global: 0, |
| 193 | Local: 1, |
| 194 | With: 2, |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 195 | Closure: 3, |
| 196 | Catch: 4 }; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 197 | |
| 198 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | // Mirror hierarchy: |
| 200 | // - Mirror |
| 201 | // - ValueMirror |
| 202 | // - UndefinedMirror |
| 203 | // - NullMirror |
| 204 | // - NumberMirror |
| 205 | // - StringMirror |
| 206 | // - ObjectMirror |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 207 | // - FunctionMirror |
| 208 | // - UnresolvedFunctionMirror |
| 209 | // - ArrayMirror |
| 210 | // - DateMirror |
| 211 | // - RegExpMirror |
| 212 | // - ErrorMirror |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 213 | // - PropertyMirror |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 214 | // - FrameMirror |
| 215 | // - ScriptMirror |
| 216 | |
| 217 | |
| 218 | /** |
| 219 | * Base class for all mirror objects. |
| 220 | * @param {string} type The type of the mirror |
| 221 | * @constructor |
| 222 | */ |
| 223 | function Mirror(type) { |
| 224 | this.type_ = type; |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | Mirror.prototype.type = function() { |
| 229 | return this.type_; |
| 230 | }; |
| 231 | |
| 232 | |
| 233 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 234 | * Check whether the mirror reflects a value. |
| 235 | * @returns {boolean} True if the mirror reflects a value. |
| 236 | */ |
| 237 | Mirror.prototype.isValue = function() { |
| 238 | return this instanceof ValueMirror; |
| 239 | } |
| 240 | |
| 241 | |
| 242 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | * Check whether the mirror reflects the undefined value. |
| 244 | * @returns {boolean} True if the mirror reflects the undefined value. |
| 245 | */ |
| 246 | Mirror.prototype.isUndefined = function() { |
| 247 | return this instanceof UndefinedMirror; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | /** |
| 252 | * Check whether the mirror reflects the null value. |
| 253 | * @returns {boolean} True if the mirror reflects the null value |
| 254 | */ |
| 255 | Mirror.prototype.isNull = function() { |
| 256 | return this instanceof NullMirror; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | /** |
| 261 | * Check whether the mirror reflects a boolean value. |
| 262 | * @returns {boolean} True if the mirror reflects a boolean value |
| 263 | */ |
| 264 | Mirror.prototype.isBoolean = function() { |
| 265 | return this instanceof BooleanMirror; |
| 266 | } |
| 267 | |
| 268 | |
| 269 | /** |
| 270 | * Check whether the mirror reflects a number value. |
| 271 | * @returns {boolean} True if the mirror reflects a number value |
| 272 | */ |
| 273 | Mirror.prototype.isNumber = function() { |
| 274 | return this instanceof NumberMirror; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | /** |
| 279 | * Check whether the mirror reflects a string value. |
| 280 | * @returns {boolean} True if the mirror reflects a string value |
| 281 | */ |
| 282 | Mirror.prototype.isString = function() { |
| 283 | return this instanceof StringMirror; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | /** |
| 288 | * Check whether the mirror reflects an object. |
| 289 | * @returns {boolean} True if the mirror reflects an object |
| 290 | */ |
| 291 | Mirror.prototype.isObject = function() { |
| 292 | return this instanceof ObjectMirror; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | /** |
| 297 | * Check whether the mirror reflects a function. |
| 298 | * @returns {boolean} True if the mirror reflects a function |
| 299 | */ |
| 300 | Mirror.prototype.isFunction = function() { |
| 301 | return this instanceof FunctionMirror; |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /** |
| 306 | * Check whether the mirror reflects an unresolved function. |
| 307 | * @returns {boolean} True if the mirror reflects an unresolved function |
| 308 | */ |
| 309 | Mirror.prototype.isUnresolvedFunction = function() { |
| 310 | return this instanceof UnresolvedFunctionMirror; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | /** |
| 315 | * Check whether the mirror reflects an array. |
| 316 | * @returns {boolean} True if the mirror reflects an array |
| 317 | */ |
| 318 | Mirror.prototype.isArray = function() { |
| 319 | return this instanceof ArrayMirror; |
| 320 | } |
| 321 | |
| 322 | |
| 323 | /** |
| 324 | * Check whether the mirror reflects a date. |
| 325 | * @returns {boolean} True if the mirror reflects a date |
| 326 | */ |
| 327 | Mirror.prototype.isDate = function() { |
| 328 | return this instanceof DateMirror; |
| 329 | } |
| 330 | |
| 331 | |
| 332 | /** |
| 333 | * Check whether the mirror reflects a regular expression. |
| 334 | * @returns {boolean} True if the mirror reflects a regular expression |
| 335 | */ |
| 336 | Mirror.prototype.isRegExp = function() { |
| 337 | return this instanceof RegExpMirror; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | /** |
| 342 | * Check whether the mirror reflects an error. |
| 343 | * @returns {boolean} True if the mirror reflects an error |
| 344 | */ |
| 345 | Mirror.prototype.isError = function() { |
| 346 | return this instanceof ErrorMirror; |
| 347 | } |
| 348 | |
| 349 | |
| 350 | /** |
| 351 | * Check whether the mirror reflects a property. |
| 352 | * @returns {boolean} True if the mirror reflects a property |
| 353 | */ |
| 354 | Mirror.prototype.isProperty = function() { |
| 355 | return this instanceof PropertyMirror; |
| 356 | } |
| 357 | |
| 358 | |
| 359 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | * Check whether the mirror reflects a stack frame. |
| 361 | * @returns {boolean} True if the mirror reflects a stack frame |
| 362 | */ |
| 363 | Mirror.prototype.isFrame = function() { |
| 364 | return this instanceof FrameMirror; |
| 365 | } |
| 366 | |
| 367 | |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 368 | /** |
| 369 | * Check whether the mirror reflects a script. |
| 370 | * @returns {boolean} True if the mirror reflects a script |
| 371 | */ |
| 372 | Mirror.prototype.isScript = function() { |
| 373 | return this instanceof ScriptMirror; |
| 374 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | |
| 376 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 377 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 378 | * Check whether the mirror reflects a context. |
| 379 | * @returns {boolean} True if the mirror reflects a context |
| 380 | */ |
| 381 | Mirror.prototype.isContext = function() { |
| 382 | return this instanceof ContextMirror; |
| 383 | } |
| 384 | |
| 385 | |
| 386 | /** |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 387 | * Check whether the mirror reflects a scope. |
| 388 | * @returns {boolean} True if the mirror reflects a scope |
| 389 | */ |
| 390 | Mirror.prototype.isScope = function() { |
| 391 | return this instanceof ScopeMirror; |
| 392 | } |
| 393 | |
| 394 | |
| 395 | /** |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 396 | * Allocate a handle id for this object. |
| 397 | */ |
| 398 | Mirror.prototype.allocateHandle_ = function() { |
| 399 | this.handle_ = next_handle_++; |
| 400 | } |
| 401 | |
| 402 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 403 | /** |
| 404 | * Allocate a transient handle id for this object. Transient handles are |
| 405 | * negative. |
| 406 | */ |
| 407 | Mirror.prototype.allocateTransientHandle_ = function() { |
| 408 | this.handle_ = next_transient_handle_--; |
| 409 | } |
| 410 | |
| 411 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 412 | Mirror.prototype.toText = function() { |
| 413 | // Simpel to text which is used when on specialization in subclass. |
| 414 | return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; |
| 415 | } |
| 416 | |
| 417 | |
| 418 | /** |
| 419 | * Base class for all value mirror objects. |
| 420 | * @param {string} type The type of the mirror |
| 421 | * @param {value} value The value reflected by this mirror |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 422 | * @param {boolean} transient indicate whether this object is transient with a |
| 423 | * transient handle |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 424 | * @constructor |
| 425 | * @extends Mirror |
| 426 | */ |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 427 | function ValueMirror(type, value, transient) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 428 | Mirror.call(this, type); |
| 429 | this.value_ = value; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 430 | if (!transient) { |
| 431 | this.allocateHandle_(); |
| 432 | } else { |
| 433 | this.allocateTransientHandle_(); |
| 434 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 435 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 436 | inherits(ValueMirror, Mirror); |
| 437 | |
| 438 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 439 | Mirror.prototype.handle = function() { |
| 440 | return this.handle_; |
| 441 | }; |
| 442 | |
| 443 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 444 | /** |
| 445 | * Check whether this is a primitive value. |
| 446 | * @return {boolean} True if the mirror reflects a primitive value |
| 447 | */ |
| 448 | ValueMirror.prototype.isPrimitive = function() { |
| 449 | var type = this.type(); |
| 450 | return type === 'undefined' || |
| 451 | type === 'null' || |
| 452 | type === 'boolean' || |
| 453 | type === 'number' || |
| 454 | type === 'string'; |
| 455 | }; |
| 456 | |
| 457 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 458 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 459 | * Get the actual value reflected by this mirror. |
| 460 | * @return {value} The value reflected by this mirror |
| 461 | */ |
| 462 | ValueMirror.prototype.value = function() { |
| 463 | return this.value_; |
| 464 | }; |
| 465 | |
| 466 | |
| 467 | /** |
| 468 | * Mirror object for Undefined. |
| 469 | * @constructor |
| 470 | * @extends ValueMirror |
| 471 | */ |
| 472 | function UndefinedMirror() { |
| 473 | ValueMirror.call(this, UNDEFINED_TYPE, void 0); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 474 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | inherits(UndefinedMirror, ValueMirror); |
| 476 | |
| 477 | |
| 478 | UndefinedMirror.prototype.toText = function() { |
| 479 | return 'undefined'; |
| 480 | } |
| 481 | |
| 482 | |
| 483 | /** |
| 484 | * Mirror object for null. |
| 485 | * @constructor |
| 486 | * @extends ValueMirror |
| 487 | */ |
| 488 | function NullMirror() { |
| 489 | ValueMirror.call(this, NULL_TYPE, null); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 490 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | inherits(NullMirror, ValueMirror); |
| 492 | |
| 493 | |
| 494 | NullMirror.prototype.toText = function() { |
| 495 | return 'null'; |
| 496 | } |
| 497 | |
| 498 | |
| 499 | /** |
| 500 | * Mirror object for boolean values. |
| 501 | * @param {boolean} value The boolean value reflected by this mirror |
| 502 | * @constructor |
| 503 | * @extends ValueMirror |
| 504 | */ |
| 505 | function BooleanMirror(value) { |
| 506 | ValueMirror.call(this, BOOLEAN_TYPE, value); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 507 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 508 | inherits(BooleanMirror, ValueMirror); |
| 509 | |
| 510 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 511 | BooleanMirror.prototype.toText = function() { |
| 512 | return this.value_ ? 'true' : 'false'; |
| 513 | } |
| 514 | |
| 515 | |
| 516 | /** |
| 517 | * Mirror object for number values. |
| 518 | * @param {number} value The number value reflected by this mirror |
| 519 | * @constructor |
| 520 | * @extends ValueMirror |
| 521 | */ |
| 522 | function NumberMirror(value) { |
| 523 | ValueMirror.call(this, NUMBER_TYPE, value); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 524 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | inherits(NumberMirror, ValueMirror); |
| 526 | |
| 527 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 528 | NumberMirror.prototype.toText = function() { |
| 529 | return %NumberToString(this.value_); |
| 530 | } |
| 531 | |
| 532 | |
| 533 | /** |
| 534 | * Mirror object for string values. |
| 535 | * @param {string} value The string value reflected by this mirror |
| 536 | * @constructor |
| 537 | * @extends ValueMirror |
| 538 | */ |
| 539 | function StringMirror(value) { |
| 540 | ValueMirror.call(this, STRING_TYPE, value); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 541 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 542 | inherits(StringMirror, ValueMirror); |
| 543 | |
| 544 | |
| 545 | StringMirror.prototype.length = function() { |
| 546 | return this.value_.length; |
| 547 | }; |
| 548 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 549 | StringMirror.prototype.getTruncatedValue = function(maxLength) { |
| 550 | if (maxLength != -1 && this.length() > maxLength) { |
| 551 | return this.value_.substring(0, maxLength) + |
| 552 | '... (length: ' + this.length() + ')'; |
| 553 | } |
| 554 | return this.value_; |
| 555 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 556 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | StringMirror.prototype.toText = function() { |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 558 | return this.getTruncatedValue(kMaxProtocolStringLength); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | |
| 562 | /** |
| 563 | * Mirror object for objects. |
| 564 | * @param {object} value The object reflected by this mirror |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 565 | * @param {boolean} transient indicate whether this object is transient with a |
| 566 | * transient handle |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 567 | * @constructor |
| 568 | * @extends ValueMirror |
| 569 | */ |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 570 | function ObjectMirror(value, type, transient) { |
| 571 | ValueMirror.call(this, type || OBJECT_TYPE, value, transient); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 572 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | inherits(ObjectMirror, ValueMirror); |
| 574 | |
| 575 | |
| 576 | ObjectMirror.prototype.className = function() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 577 | return %_ClassOf(this.value_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | }; |
| 579 | |
| 580 | |
| 581 | ObjectMirror.prototype.constructorFunction = function() { |
| 582 | return MakeMirror(%DebugGetProperty(this.value_, 'constructor')); |
| 583 | }; |
| 584 | |
| 585 | |
| 586 | ObjectMirror.prototype.prototypeObject = function() { |
| 587 | return MakeMirror(%DebugGetProperty(this.value_, 'prototype')); |
| 588 | }; |
| 589 | |
| 590 | |
| 591 | ObjectMirror.prototype.protoObject = function() { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 592 | return MakeMirror(%DebugGetPrototype(this.value_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | |
| 596 | ObjectMirror.prototype.hasNamedInterceptor = function() { |
| 597 | // Get information on interceptors for this object. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 598 | var x = %GetInterceptorInfo(this.value_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 599 | return (x & 2) != 0; |
| 600 | }; |
| 601 | |
| 602 | |
| 603 | ObjectMirror.prototype.hasIndexedInterceptor = function() { |
| 604 | // Get information on interceptors for this object. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 605 | var x = %GetInterceptorInfo(this.value_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 606 | return (x & 1) != 0; |
| 607 | }; |
| 608 | |
| 609 | |
| 610 | /** |
| 611 | * Return the property names for this object. |
| 612 | * @param {number} kind Indicate whether named, indexed or both kinds of |
| 613 | * properties are requested |
| 614 | * @param {number} limit Limit the number of names returend to the specified |
| 615 | value |
| 616 | * @return {Array} Property names for this object |
| 617 | */ |
| 618 | ObjectMirror.prototype.propertyNames = function(kind, limit) { |
| 619 | // Find kind and limit and allocate array for the result |
| 620 | kind = kind || PropertyKind.Named | PropertyKind.Indexed; |
| 621 | |
| 622 | var propertyNames; |
| 623 | var elementNames; |
| 624 | var total = 0; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 625 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 626 | // Find all the named properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 627 | if (kind & PropertyKind.Named) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 628 | // Get the local property names. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 629 | propertyNames = %GetLocalPropertyNames(this.value_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | total += propertyNames.length; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 631 | |
| 632 | // Get names for named interceptor properties if any. |
| 633 | if (this.hasNamedInterceptor() && (kind & PropertyKind.Named)) { |
| 634 | var namedInterceptorNames = |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 635 | %GetNamedInterceptorPropertyNames(this.value_); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 636 | if (namedInterceptorNames) { |
| 637 | propertyNames = propertyNames.concat(namedInterceptorNames); |
| 638 | total += namedInterceptorNames.length; |
| 639 | } |
| 640 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 641 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 642 | |
| 643 | // Find all the indexed properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 644 | if (kind & PropertyKind.Indexed) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 645 | // Get the local element names. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 646 | elementNames = %GetLocalElementNames(this.value_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 647 | total += elementNames.length; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 648 | |
| 649 | // Get names for indexed interceptor properties. |
| 650 | if (this.hasIndexedInterceptor() && (kind & PropertyKind.Indexed)) { |
| 651 | var indexedInterceptorNames = |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 652 | %GetIndexedInterceptorElementNames(this.value_); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 653 | if (indexedInterceptorNames) { |
| 654 | elementNames = elementNames.concat(indexedInterceptorNames); |
| 655 | total += indexedInterceptorNames.length; |
| 656 | } |
| 657 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 658 | } |
| 659 | limit = Math.min(limit || total, total); |
| 660 | |
| 661 | var names = new Array(limit); |
| 662 | var index = 0; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 663 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 664 | // Copy names for named properties. |
| 665 | if (kind & PropertyKind.Named) { |
| 666 | for (var i = 0; index < limit && i < propertyNames.length; i++) { |
| 667 | names[index++] = propertyNames[i]; |
| 668 | } |
| 669 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 670 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 671 | // Copy names for indexed properties. |
| 672 | if (kind & PropertyKind.Indexed) { |
| 673 | for (var i = 0; index < limit && i < elementNames.length; i++) { |
| 674 | names[index++] = elementNames[i]; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | return names; |
| 679 | }; |
| 680 | |
| 681 | |
| 682 | /** |
| 683 | * Return the properties for this object as an array of PropertyMirror objects. |
| 684 | * @param {number} kind Indicate whether named, indexed or both kinds of |
| 685 | * properties are requested |
| 686 | * @param {number} limit Limit the number of properties returend to the |
| 687 | specified value |
| 688 | * @return {Array} Property mirrors for this object |
| 689 | */ |
| 690 | ObjectMirror.prototype.properties = function(kind, limit) { |
| 691 | var names = this.propertyNames(kind, limit); |
| 692 | var properties = new Array(names.length); |
| 693 | for (var i = 0; i < names.length; i++) { |
| 694 | properties[i] = this.property(names[i]); |
| 695 | } |
| 696 | |
| 697 | return properties; |
| 698 | }; |
| 699 | |
| 700 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | ObjectMirror.prototype.property = function(name) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 702 | var details = %DebugGetPropertyDetails(this.value_, %ToString(name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 703 | if (details) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 704 | return new PropertyMirror(this, name, details); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | // Nothing found. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 708 | return GetUndefinedMirror(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | }; |
| 710 | |
| 711 | |
| 712 | |
| 713 | /** |
| 714 | * Try to find a property from its value. |
| 715 | * @param {Mirror} value The property value to look for |
| 716 | * @return {PropertyMirror} The property with the specified value. If no |
| 717 | * property was found with the specified value UndefinedMirror is returned |
| 718 | */ |
| 719 | ObjectMirror.prototype.lookupProperty = function(value) { |
| 720 | var properties = this.properties(); |
| 721 | |
| 722 | // Look for property value in properties. |
| 723 | for (var i = 0; i < properties.length; i++) { |
| 724 | |
| 725 | // Skip properties which are defined through assessors. |
| 726 | var property = properties[i]; |
| 727 | if (property.propertyType() != PropertyType.Callbacks) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 728 | if (%_ObjectEquals(property.value_, value.value_)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 729 | return property; |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | // Nothing found. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 735 | return GetUndefinedMirror(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 736 | }; |
| 737 | |
| 738 | |
| 739 | /** |
| 740 | * Returns objects which has direct references to this object |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 741 | * @param {number} opt_max_objects Optional parameter specifying the maximum |
| 742 | * number of referencing objects to return. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 743 | * @return {Array} The objects which has direct references to this object. |
| 744 | */ |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 745 | ObjectMirror.prototype.referencedBy = function(opt_max_objects) { |
| 746 | // Find all objects with direct references to this object. |
| 747 | var result = %DebugReferencedBy(this.value_, |
| 748 | Mirror.prototype, opt_max_objects || 0); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 749 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 750 | // Make mirrors for all the references found. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 751 | for (var i = 0; i < result.length; i++) { |
| 752 | result[i] = MakeMirror(result[i]); |
| 753 | } |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 754 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 755 | return result; |
| 756 | }; |
| 757 | |
| 758 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 759 | ObjectMirror.prototype.toText = function() { |
| 760 | var name; |
| 761 | var ctor = this.constructorFunction(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 762 | if (!ctor.isFunction()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 763 | name = this.className(); |
| 764 | } else { |
| 765 | name = ctor.name(); |
| 766 | if (!name) { |
| 767 | name = this.className(); |
| 768 | } |
| 769 | } |
| 770 | return '#<' + builtins.GetInstanceName(name) + '>'; |
| 771 | }; |
| 772 | |
| 773 | |
| 774 | /** |
| 775 | * Mirror object for functions. |
| 776 | * @param {function} value The function object reflected by this mirror. |
| 777 | * @constructor |
| 778 | * @extends ObjectMirror |
| 779 | */ |
| 780 | function FunctionMirror(value) { |
| 781 | ObjectMirror.call(this, value, FUNCTION_TYPE); |
| 782 | this.resolved_ = true; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 783 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 784 | inherits(FunctionMirror, ObjectMirror); |
| 785 | |
| 786 | |
| 787 | /** |
| 788 | * Returns whether the function is resolved. |
| 789 | * @return {boolean} True if the function is resolved. Unresolved functions can |
| 790 | * only originate as functions from stack frames |
| 791 | */ |
| 792 | FunctionMirror.prototype.resolved = function() { |
| 793 | return this.resolved_; |
| 794 | }; |
| 795 | |
| 796 | |
| 797 | /** |
| 798 | * Returns the name of the function. |
| 799 | * @return {string} Name of the function |
| 800 | */ |
| 801 | FunctionMirror.prototype.name = function() { |
| 802 | return %FunctionGetName(this.value_); |
| 803 | }; |
| 804 | |
| 805 | |
| 806 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 807 | * Returns the inferred name of the function. |
| 808 | * @return {string} Name of the function |
| 809 | */ |
| 810 | FunctionMirror.prototype.inferredName = function() { |
| 811 | return %FunctionGetInferredName(this.value_); |
| 812 | }; |
| 813 | |
| 814 | |
| 815 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 816 | * Returns the source code for the function. |
| 817 | * @return {string or undefined} The source code for the function. If the |
| 818 | * function is not resolved undefined will be returned. |
| 819 | */ |
| 820 | FunctionMirror.prototype.source = function() { |
| 821 | // Return source if function is resolved. Otherwise just fall through to |
| 822 | // return undefined. |
| 823 | if (this.resolved()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 824 | return builtins.FunctionSourceString(this.value_); |
| 825 | } |
| 826 | }; |
| 827 | |
| 828 | |
| 829 | /** |
| 830 | * Returns the script object for the function. |
| 831 | * @return {ScriptMirror or undefined} Script object for the function or |
| 832 | * undefined if the function has no script |
| 833 | */ |
| 834 | FunctionMirror.prototype.script = function() { |
| 835 | // Return script if function is resolved. Otherwise just fall through |
| 836 | // to return undefined. |
| 837 | if (this.resolved()) { |
| 838 | var script = %FunctionGetScript(this.value_); |
| 839 | if (script) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 840 | return MakeMirror(script); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | }; |
| 844 | |
| 845 | |
| 846 | /** |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 847 | * Returns the script source position for the function. Only makes sense |
| 848 | * for functions which has a script defined. |
| 849 | * @return {Number or undefined} in-script position for the function |
| 850 | */ |
| 851 | FunctionMirror.prototype.sourcePosition_ = function() { |
| 852 | // Return script if function is resolved. Otherwise just fall through |
| 853 | // to return undefined. |
| 854 | if (this.resolved()) { |
| 855 | return %FunctionGetScriptSourcePosition(this.value_); |
| 856 | } |
| 857 | }; |
| 858 | |
| 859 | |
| 860 | /** |
| 861 | * Returns the script source location object for the function. Only makes sense |
| 862 | * for functions which has a script defined. |
| 863 | * @return {Location or undefined} in-script location for the function begin |
| 864 | */ |
| 865 | FunctionMirror.prototype.sourceLocation = function() { |
| 866 | if (this.resolved() && this.script()) { |
| 867 | return this.script().locationFromPosition(this.sourcePosition_(), |
| 868 | true); |
| 869 | } |
| 870 | }; |
| 871 | |
| 872 | |
| 873 | /** |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 874 | * Returns objects constructed by this function. |
| 875 | * @param {number} opt_max_instances Optional parameter specifying the maximum |
| 876 | * number of instances to return. |
| 877 | * @return {Array or undefined} The objects constructed by this function. |
| 878 | */ |
| 879 | FunctionMirror.prototype.constructedBy = function(opt_max_instances) { |
| 880 | if (this.resolved()) { |
| 881 | // Find all objects constructed from this function. |
| 882 | var result = %DebugConstructedBy(this.value_, opt_max_instances || 0); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 883 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | // Make mirrors for all the instances found. |
| 885 | for (var i = 0; i < result.length; i++) { |
| 886 | result[i] = MakeMirror(result[i]); |
| 887 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 888 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | return result; |
| 890 | } else { |
| 891 | return []; |
| 892 | } |
| 893 | }; |
| 894 | |
| 895 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | FunctionMirror.prototype.toText = function() { |
| 897 | return this.source(); |
| 898 | } |
| 899 | |
| 900 | |
| 901 | /** |
| 902 | * Mirror object for unresolved functions. |
| 903 | * @param {string} value The name for the unresolved function reflected by this |
| 904 | * mirror. |
| 905 | * @constructor |
| 906 | * @extends ObjectMirror |
| 907 | */ |
| 908 | function UnresolvedFunctionMirror(value) { |
| 909 | // Construct this using the ValueMirror as an unresolved function is not a |
| 910 | // real object but just a string. |
| 911 | ValueMirror.call(this, FUNCTION_TYPE, value); |
| 912 | this.propertyCount_ = 0; |
| 913 | this.elementCount_ = 0; |
| 914 | this.resolved_ = false; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 915 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 916 | inherits(UnresolvedFunctionMirror, FunctionMirror); |
| 917 | |
| 918 | |
| 919 | UnresolvedFunctionMirror.prototype.className = function() { |
| 920 | return 'Function'; |
| 921 | }; |
| 922 | |
| 923 | |
| 924 | UnresolvedFunctionMirror.prototype.constructorFunction = function() { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 925 | return GetUndefinedMirror(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 926 | }; |
| 927 | |
| 928 | |
| 929 | UnresolvedFunctionMirror.prototype.prototypeObject = function() { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 930 | return GetUndefinedMirror(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 931 | }; |
| 932 | |
| 933 | |
| 934 | UnresolvedFunctionMirror.prototype.protoObject = function() { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 935 | return GetUndefinedMirror(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | }; |
| 937 | |
| 938 | |
| 939 | UnresolvedFunctionMirror.prototype.name = function() { |
| 940 | return this.value_; |
| 941 | }; |
| 942 | |
| 943 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 944 | UnresolvedFunctionMirror.prototype.inferredName = function() { |
| 945 | return undefined; |
| 946 | }; |
| 947 | |
| 948 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 949 | UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) { |
| 950 | return []; |
| 951 | } |
| 952 | |
| 953 | |
| 954 | /** |
| 955 | * Mirror object for arrays. |
| 956 | * @param {Array} value The Array object reflected by this mirror |
| 957 | * @constructor |
| 958 | * @extends ObjectMirror |
| 959 | */ |
| 960 | function ArrayMirror(value) { |
| 961 | ObjectMirror.call(this, value); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 962 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 963 | inherits(ArrayMirror, ObjectMirror); |
| 964 | |
| 965 | |
| 966 | ArrayMirror.prototype.length = function() { |
| 967 | return this.value_.length; |
| 968 | }; |
| 969 | |
| 970 | |
| 971 | ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index, opt_to_index) { |
| 972 | var from_index = opt_from_index || 0; |
| 973 | var to_index = opt_to_index || this.length() - 1; |
| 974 | if (from_index > to_index) return new Array(); |
| 975 | var values = new Array(to_index - from_index + 1); |
| 976 | for (var i = from_index; i <= to_index; i++) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 977 | var details = %DebugGetPropertyDetails(this.value_, %ToString(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 978 | var value; |
| 979 | if (details) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 980 | value = new PropertyMirror(this, i, details); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 981 | } else { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 982 | value = GetUndefinedMirror(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 983 | } |
| 984 | values[i - from_index] = value; |
| 985 | } |
| 986 | return values; |
| 987 | } |
| 988 | |
| 989 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | /** |
| 991 | * Mirror object for dates. |
| 992 | * @param {Date} value The Date object reflected by this mirror |
| 993 | * @constructor |
| 994 | * @extends ObjectMirror |
| 995 | */ |
| 996 | function DateMirror(value) { |
| 997 | ObjectMirror.call(this, value); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 998 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 999 | inherits(DateMirror, ObjectMirror); |
| 1000 | |
| 1001 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1002 | DateMirror.prototype.toText = function() { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1003 | var s = JSON.stringify(this.value_); |
| 1004 | return s.substring(1, s.length - 1); // cut quotes |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | /** |
| 1009 | * Mirror object for regular expressions. |
| 1010 | * @param {RegExp} value The RegExp object reflected by this mirror |
| 1011 | * @constructor |
| 1012 | * @extends ObjectMirror |
| 1013 | */ |
| 1014 | function RegExpMirror(value) { |
| 1015 | ObjectMirror.call(this, value, REGEXP_TYPE); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1016 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1017 | inherits(RegExpMirror, ObjectMirror); |
| 1018 | |
| 1019 | |
| 1020 | /** |
| 1021 | * Returns the source to the regular expression. |
| 1022 | * @return {string or undefined} The source to the regular expression |
| 1023 | */ |
| 1024 | RegExpMirror.prototype.source = function() { |
| 1025 | return this.value_.source; |
| 1026 | }; |
| 1027 | |
| 1028 | |
| 1029 | /** |
| 1030 | * Returns whether this regular expression has the global (g) flag set. |
| 1031 | * @return {boolean} Value of the global flag |
| 1032 | */ |
| 1033 | RegExpMirror.prototype.global = function() { |
| 1034 | return this.value_.global; |
| 1035 | }; |
| 1036 | |
| 1037 | |
| 1038 | /** |
| 1039 | * Returns whether this regular expression has the ignore case (i) flag set. |
| 1040 | * @return {boolean} Value of the ignore case flag |
| 1041 | */ |
| 1042 | RegExpMirror.prototype.ignoreCase = function() { |
| 1043 | return this.value_.ignoreCase; |
| 1044 | }; |
| 1045 | |
| 1046 | |
| 1047 | /** |
| 1048 | * Returns whether this regular expression has the multiline (m) flag set. |
| 1049 | * @return {boolean} Value of the multiline flag |
| 1050 | */ |
| 1051 | RegExpMirror.prototype.multiline = function() { |
| 1052 | return this.value_.multiline; |
| 1053 | }; |
| 1054 | |
| 1055 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | RegExpMirror.prototype.toText = function() { |
| 1057 | // Simpel to text which is used when on specialization in subclass. |
| 1058 | return "/" + this.source() + "/"; |
| 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | /** |
| 1063 | * Mirror object for error objects. |
| 1064 | * @param {Error} value The error object reflected by this mirror |
| 1065 | * @constructor |
| 1066 | * @extends ObjectMirror |
| 1067 | */ |
| 1068 | function ErrorMirror(value) { |
| 1069 | ObjectMirror.call(this, value, ERROR_TYPE); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1070 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1071 | inherits(ErrorMirror, ObjectMirror); |
| 1072 | |
| 1073 | |
| 1074 | /** |
| 1075 | * Returns the message for this eror object. |
| 1076 | * @return {string or undefined} The message for this eror object |
| 1077 | */ |
| 1078 | ErrorMirror.prototype.message = function() { |
| 1079 | return this.value_.message; |
| 1080 | }; |
| 1081 | |
| 1082 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1083 | ErrorMirror.prototype.toText = function() { |
| 1084 | // Use the same text representation as in messages.js. |
| 1085 | var text; |
| 1086 | try { |
| 1087 | str = builtins.ToDetailString(this.value_); |
| 1088 | } catch (e) { |
| 1089 | str = '#<an Error>'; |
| 1090 | } |
| 1091 | return str; |
| 1092 | } |
| 1093 | |
| 1094 | |
| 1095 | /** |
| 1096 | * Base mirror object for properties. |
| 1097 | * @param {ObjectMirror} mirror The mirror object having this property |
| 1098 | * @param {string} name The name of the property |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1099 | * @param {Array} details Details about the property |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1100 | * @constructor |
| 1101 | * @extends Mirror |
| 1102 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1103 | function PropertyMirror(mirror, name, details) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1104 | Mirror.call(this, PROPERTY_TYPE); |
| 1105 | this.mirror_ = mirror; |
| 1106 | this.name_ = name; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1107 | this.value_ = details[0]; |
| 1108 | this.details_ = details[1]; |
| 1109 | if (details.length > 2) { |
| 1110 | this.exception_ = details[2] |
| 1111 | this.getter_ = details[3]; |
| 1112 | this.setter_ = details[4]; |
| 1113 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1114 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1115 | inherits(PropertyMirror, Mirror); |
| 1116 | |
| 1117 | |
| 1118 | PropertyMirror.prototype.isReadOnly = function() { |
| 1119 | return (this.attributes() & PropertyAttribute.ReadOnly) != 0; |
| 1120 | } |
| 1121 | |
| 1122 | |
| 1123 | PropertyMirror.prototype.isEnum = function() { |
| 1124 | return (this.attributes() & PropertyAttribute.DontEnum) == 0; |
| 1125 | } |
| 1126 | |
| 1127 | |
| 1128 | PropertyMirror.prototype.canDelete = function() { |
| 1129 | return (this.attributes() & PropertyAttribute.DontDelete) == 0; |
| 1130 | } |
| 1131 | |
| 1132 | |
| 1133 | PropertyMirror.prototype.name = function() { |
| 1134 | return this.name_; |
| 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | PropertyMirror.prototype.isIndexed = function() { |
| 1139 | for (var i = 0; i < this.name_.length; i++) { |
| 1140 | if (this.name_[i] < '0' || '9' < this.name_[i]) { |
| 1141 | return false; |
| 1142 | } |
| 1143 | } |
| 1144 | return true; |
| 1145 | } |
| 1146 | |
| 1147 | |
| 1148 | PropertyMirror.prototype.value = function() { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1149 | return MakeMirror(this.value_, false); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | |
| 1153 | /** |
| 1154 | * Returns whether this property value is an exception. |
| 1155 | * @return {booolean} True if this property value is an exception |
| 1156 | */ |
| 1157 | PropertyMirror.prototype.isException = function() { |
| 1158 | return this.exception_ ? true : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | |
| 1162 | PropertyMirror.prototype.attributes = function() { |
| 1163 | return %DebugPropertyAttributesFromDetails(this.details_); |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | PropertyMirror.prototype.propertyType = function() { |
| 1168 | return %DebugPropertyTypeFromDetails(this.details_); |
| 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | PropertyMirror.prototype.insertionIndex = function() { |
| 1173 | return %DebugPropertyIndexFromDetails(this.details_); |
| 1174 | } |
| 1175 | |
| 1176 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1177 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1178 | * Returns whether this property has a getter defined through __defineGetter__. |
| 1179 | * @return {booolean} True if this property has a getter |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1180 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1181 | PropertyMirror.prototype.hasGetter = function() { |
| 1182 | return this.getter_ ? true : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1187 | * Returns whether this property has a setter defined through __defineSetter__. |
| 1188 | * @return {booolean} True if this property has a setter |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1189 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1190 | PropertyMirror.prototype.hasSetter = function() { |
| 1191 | return this.setter_ ? true : false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | |
| 1195 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1196 | * Returns the getter for this property defined through __defineGetter__. |
| 1197 | * @return {Mirror} FunctionMirror reflecting the getter function or |
| 1198 | * UndefinedMirror if there is no getter for this property |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1199 | */ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1200 | PropertyMirror.prototype.getter = function() { |
| 1201 | if (this.hasGetter()) { |
| 1202 | return MakeMirror(this.getter_); |
| 1203 | } else { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1204 | return GetUndefinedMirror(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | /** |
| 1210 | * Returns the setter for this property defined through __defineSetter__. |
| 1211 | * @return {Mirror} FunctionMirror reflecting the setter function or |
| 1212 | * UndefinedMirror if there is no setter for this property |
| 1213 | */ |
| 1214 | PropertyMirror.prototype.setter = function() { |
| 1215 | if (this.hasSetter()) { |
| 1216 | return MakeMirror(this.setter_); |
| 1217 | } else { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1218 | return GetUndefinedMirror(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | |
| 1223 | /** |
| 1224 | * Returns whether this property is natively implemented by the host or a set |
| 1225 | * through JavaScript code. |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1226 | * @return {boolean} True if the property is |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1227 | * UndefinedMirror if there is no setter for this property |
| 1228 | */ |
| 1229 | PropertyMirror.prototype.isNative = function() { |
| 1230 | return (this.propertyType() == PropertyType.Interceptor) || |
| 1231 | ((this.propertyType() == PropertyType.Callbacks) && |
| 1232 | !this.hasGetter() && !this.hasSetter()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1236 | const kFrameDetailsFrameIdIndex = 0; |
| 1237 | const kFrameDetailsReceiverIndex = 1; |
| 1238 | const kFrameDetailsFunctionIndex = 2; |
| 1239 | const kFrameDetailsArgumentCountIndex = 3; |
| 1240 | const kFrameDetailsLocalCountIndex = 4; |
| 1241 | const kFrameDetailsSourcePositionIndex = 5; |
| 1242 | const kFrameDetailsConstructCallIndex = 6; |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1243 | const kFrameDetailsAtReturnIndex = 7; |
| 1244 | const kFrameDetailsDebuggerFrameIndex = 8; |
| 1245 | const kFrameDetailsFirstDynamicIndex = 9; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1246 | |
| 1247 | const kFrameDetailsNameIndex = 0; |
| 1248 | const kFrameDetailsValueIndex = 1; |
| 1249 | const kFrameDetailsNameValueSize = 2; |
| 1250 | |
| 1251 | /** |
| 1252 | * Wrapper for the frame details information retreived from the VM. The frame |
| 1253 | * details from the VM is an array with the following content. See runtime.cc |
| 1254 | * Runtime_GetFrameDetails. |
| 1255 | * 0: Id |
| 1256 | * 1: Receiver |
| 1257 | * 2: Function |
| 1258 | * 3: Argument count |
| 1259 | * 4: Local count |
| 1260 | * 5: Source position |
| 1261 | * 6: Construct call |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1262 | * 7: Is at return |
| 1263 | * 8: Debugger frame |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | * Arguments name, value |
| 1265 | * Locals name, value |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1266 | * Return value if any |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1267 | * @param {number} break_id Current break id |
| 1268 | * @param {number} index Frame number |
| 1269 | * @constructor |
| 1270 | */ |
| 1271 | function FrameDetails(break_id, index) { |
| 1272 | this.break_id_ = break_id; |
| 1273 | this.details_ = %GetFrameDetails(break_id, index); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1274 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1275 | |
| 1276 | |
| 1277 | FrameDetails.prototype.frameId = function() { |
| 1278 | %CheckExecutionState(this.break_id_); |
| 1279 | return this.details_[kFrameDetailsFrameIdIndex]; |
| 1280 | } |
| 1281 | |
| 1282 | |
| 1283 | FrameDetails.prototype.receiver = function() { |
| 1284 | %CheckExecutionState(this.break_id_); |
| 1285 | return this.details_[kFrameDetailsReceiverIndex]; |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | FrameDetails.prototype.func = function() { |
| 1290 | %CheckExecutionState(this.break_id_); |
| 1291 | return this.details_[kFrameDetailsFunctionIndex]; |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | FrameDetails.prototype.isConstructCall = function() { |
| 1296 | %CheckExecutionState(this.break_id_); |
| 1297 | return this.details_[kFrameDetailsConstructCallIndex]; |
| 1298 | } |
| 1299 | |
| 1300 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1301 | FrameDetails.prototype.isAtReturn = function() { |
| 1302 | %CheckExecutionState(this.break_id_); |
| 1303 | return this.details_[kFrameDetailsAtReturnIndex]; |
| 1304 | } |
| 1305 | |
| 1306 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1307 | FrameDetails.prototype.isDebuggerFrame = function() { |
| 1308 | %CheckExecutionState(this.break_id_); |
| 1309 | return this.details_[kFrameDetailsDebuggerFrameIndex]; |
| 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | FrameDetails.prototype.argumentCount = function() { |
| 1314 | %CheckExecutionState(this.break_id_); |
| 1315 | return this.details_[kFrameDetailsArgumentCountIndex]; |
| 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | FrameDetails.prototype.argumentName = function(index) { |
| 1320 | %CheckExecutionState(this.break_id_); |
| 1321 | if (index >= 0 && index < this.argumentCount()) { |
| 1322 | return this.details_[kFrameDetailsFirstDynamicIndex + |
| 1323 | index * kFrameDetailsNameValueSize + |
| 1324 | kFrameDetailsNameIndex] |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | |
| 1329 | FrameDetails.prototype.argumentValue = function(index) { |
| 1330 | %CheckExecutionState(this.break_id_); |
| 1331 | if (index >= 0 && index < this.argumentCount()) { |
| 1332 | return this.details_[kFrameDetailsFirstDynamicIndex + |
| 1333 | index * kFrameDetailsNameValueSize + |
| 1334 | kFrameDetailsValueIndex] |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | FrameDetails.prototype.localCount = function() { |
| 1340 | %CheckExecutionState(this.break_id_); |
| 1341 | return this.details_[kFrameDetailsLocalCountIndex]; |
| 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | FrameDetails.prototype.sourcePosition = function() { |
| 1346 | %CheckExecutionState(this.break_id_); |
| 1347 | return this.details_[kFrameDetailsSourcePositionIndex]; |
| 1348 | } |
| 1349 | |
| 1350 | |
| 1351 | FrameDetails.prototype.localName = function(index) { |
| 1352 | %CheckExecutionState(this.break_id_); |
| 1353 | if (index >= 0 && index < this.localCount()) { |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1354 | var locals_offset = kFrameDetailsFirstDynamicIndex + |
| 1355 | this.argumentCount() * kFrameDetailsNameValueSize |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1356 | return this.details_[locals_offset + |
| 1357 | index * kFrameDetailsNameValueSize + |
| 1358 | kFrameDetailsNameIndex] |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | |
| 1363 | FrameDetails.prototype.localValue = function(index) { |
| 1364 | %CheckExecutionState(this.break_id_); |
| 1365 | if (index >= 0 && index < this.localCount()) { |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1366 | var locals_offset = kFrameDetailsFirstDynamicIndex + |
| 1367 | this.argumentCount() * kFrameDetailsNameValueSize |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1368 | return this.details_[locals_offset + |
| 1369 | index * kFrameDetailsNameValueSize + |
| 1370 | kFrameDetailsValueIndex] |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1375 | FrameDetails.prototype.returnValue = function() { |
| 1376 | %CheckExecutionState(this.break_id_); |
| 1377 | var return_value_offset = |
| 1378 | kFrameDetailsFirstDynamicIndex + |
| 1379 | (this.argumentCount() + this.localCount()) * kFrameDetailsNameValueSize; |
| 1380 | if (this.details_[kFrameDetailsAtReturnIndex]) { |
| 1381 | return this.details_[return_value_offset]; |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1386 | FrameDetails.prototype.scopeCount = function() { |
| 1387 | return %GetScopeCount(this.break_id_, this.frameId()); |
| 1388 | } |
| 1389 | |
| 1390 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1391 | /** |
| 1392 | * Mirror object for stack frames. |
| 1393 | * @param {number} break_id The break id in the VM for which this frame is |
| 1394 | valid |
| 1395 | * @param {number} index The frame index (top frame is index 0) |
| 1396 | * @constructor |
| 1397 | * @extends Mirror |
| 1398 | */ |
| 1399 | function FrameMirror(break_id, index) { |
| 1400 | Mirror.call(this, FRAME_TYPE); |
| 1401 | this.break_id_ = break_id; |
| 1402 | this.index_ = index; |
| 1403 | this.details_ = new FrameDetails(break_id, index); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1404 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1405 | inherits(FrameMirror, Mirror); |
| 1406 | |
| 1407 | |
| 1408 | FrameMirror.prototype.index = function() { |
| 1409 | return this.index_; |
| 1410 | }; |
| 1411 | |
| 1412 | |
| 1413 | FrameMirror.prototype.func = function() { |
| 1414 | // Get the function for this frame from the VM. |
| 1415 | var f = this.details_.func(); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1416 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1417 | // Create a function mirror. NOTE: MakeMirror cannot be used here as the |
| 1418 | // value returned from the VM might be a string if the function for the |
| 1419 | // frame is unresolved. |
| 1420 | if (IS_FUNCTION(f)) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1421 | return MakeMirror(f); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1422 | } else { |
| 1423 | return new UnresolvedFunctionMirror(f); |
| 1424 | } |
| 1425 | }; |
| 1426 | |
| 1427 | |
| 1428 | FrameMirror.prototype.receiver = function() { |
| 1429 | return MakeMirror(this.details_.receiver()); |
| 1430 | }; |
| 1431 | |
| 1432 | |
| 1433 | FrameMirror.prototype.isConstructCall = function() { |
| 1434 | return this.details_.isConstructCall(); |
| 1435 | }; |
| 1436 | |
| 1437 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1438 | FrameMirror.prototype.isAtReturn = function() { |
| 1439 | return this.details_.isAtReturn(); |
| 1440 | }; |
| 1441 | |
| 1442 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1443 | FrameMirror.prototype.isDebuggerFrame = function() { |
| 1444 | return this.details_.isDebuggerFrame(); |
| 1445 | }; |
| 1446 | |
| 1447 | |
| 1448 | FrameMirror.prototype.argumentCount = function() { |
| 1449 | return this.details_.argumentCount(); |
| 1450 | }; |
| 1451 | |
| 1452 | |
| 1453 | FrameMirror.prototype.argumentName = function(index) { |
| 1454 | return this.details_.argumentName(index); |
| 1455 | }; |
| 1456 | |
| 1457 | |
| 1458 | FrameMirror.prototype.argumentValue = function(index) { |
| 1459 | return MakeMirror(this.details_.argumentValue(index)); |
| 1460 | }; |
| 1461 | |
| 1462 | |
| 1463 | FrameMirror.prototype.localCount = function() { |
| 1464 | return this.details_.localCount(); |
| 1465 | }; |
| 1466 | |
| 1467 | |
| 1468 | FrameMirror.prototype.localName = function(index) { |
| 1469 | return this.details_.localName(index); |
| 1470 | }; |
| 1471 | |
| 1472 | |
| 1473 | FrameMirror.prototype.localValue = function(index) { |
| 1474 | return MakeMirror(this.details_.localValue(index)); |
| 1475 | }; |
| 1476 | |
| 1477 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1478 | FrameMirror.prototype.returnValue = function() { |
| 1479 | return MakeMirror(this.details_.returnValue()); |
| 1480 | }; |
| 1481 | |
| 1482 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1483 | FrameMirror.prototype.sourcePosition = function() { |
| 1484 | return this.details_.sourcePosition(); |
| 1485 | }; |
| 1486 | |
| 1487 | |
| 1488 | FrameMirror.prototype.sourceLocation = function() { |
| 1489 | if (this.func().resolved() && this.func().script()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1490 | return this.func().script().locationFromPosition(this.sourcePosition(), |
| 1491 | true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1492 | } |
| 1493 | }; |
| 1494 | |
| 1495 | |
| 1496 | FrameMirror.prototype.sourceLine = function() { |
| 1497 | if (this.func().resolved()) { |
| 1498 | var location = this.sourceLocation(); |
| 1499 | if (location) { |
| 1500 | return location.line; |
| 1501 | } |
| 1502 | } |
| 1503 | }; |
| 1504 | |
| 1505 | |
| 1506 | FrameMirror.prototype.sourceColumn = function() { |
| 1507 | if (this.func().resolved()) { |
| 1508 | var location = this.sourceLocation(); |
| 1509 | if (location) { |
| 1510 | return location.column; |
| 1511 | } |
| 1512 | } |
| 1513 | }; |
| 1514 | |
| 1515 | |
| 1516 | FrameMirror.prototype.sourceLineText = function() { |
| 1517 | if (this.func().resolved()) { |
| 1518 | var location = this.sourceLocation(); |
| 1519 | if (location) { |
| 1520 | return location.sourceText(); |
| 1521 | } |
| 1522 | } |
| 1523 | }; |
| 1524 | |
| 1525 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1526 | FrameMirror.prototype.scopeCount = function() { |
| 1527 | return this.details_.scopeCount(); |
| 1528 | }; |
| 1529 | |
| 1530 | |
| 1531 | FrameMirror.prototype.scope = function(index) { |
| 1532 | return new ScopeMirror(this, index); |
| 1533 | }; |
| 1534 | |
| 1535 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 1536 | FrameMirror.prototype.evaluate = function(source, disable_break) { |
| 1537 | var result = %DebugEvaluate(this.break_id_, this.details_.frameId(), |
| 1538 | source, Boolean(disable_break)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1539 | return MakeMirror(result); |
| 1540 | }; |
| 1541 | |
| 1542 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1543 | FrameMirror.prototype.invocationText = function() { |
| 1544 | // Format frame invoaction (receiver, function and arguments). |
| 1545 | var result = ''; |
| 1546 | var func = this.func(); |
| 1547 | var receiver = this.receiver(); |
| 1548 | if (this.isConstructCall()) { |
| 1549 | // For constructor frames display new followed by the function name. |
| 1550 | result += 'new '; |
| 1551 | result += func.name() ? func.name() : '[anonymous]'; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1552 | } else if (this.isDebuggerFrame()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1553 | result += '[debugger]'; |
| 1554 | } else { |
| 1555 | // If the receiver has a className which is 'global' don't display it. |
| 1556 | var display_receiver = !receiver.className || receiver.className() != 'global'; |
| 1557 | if (display_receiver) { |
| 1558 | result += receiver.toText(); |
| 1559 | } |
| 1560 | // Try to find the function as a property in the receiver. Include the |
| 1561 | // prototype chain in the lookup. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1562 | var property = GetUndefinedMirror(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1563 | if (!receiver.isUndefined()) { |
| 1564 | for (var r = receiver; !r.isNull() && property.isUndefined(); r = r.protoObject()) { |
| 1565 | property = r.lookupProperty(func); |
| 1566 | } |
| 1567 | } |
| 1568 | if (!property.isUndefined()) { |
| 1569 | // The function invoked was found on the receiver. Use the property name |
| 1570 | // for the backtrace. |
| 1571 | if (!property.isIndexed()) { |
| 1572 | if (display_receiver) { |
| 1573 | result += '.'; |
| 1574 | } |
| 1575 | result += property.name(); |
| 1576 | } else { |
| 1577 | result += '['; |
| 1578 | result += property.name(); |
| 1579 | result += ']'; |
| 1580 | } |
| 1581 | // Also known as - if the name in the function doesn't match the name |
| 1582 | // under which it was looked up. |
| 1583 | if (func.name() && func.name() != property.name()) { |
| 1584 | result += '(aka ' + func.name() + ')'; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1585 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1586 | } else { |
| 1587 | // The function invoked was not found on the receiver. Use the function |
| 1588 | // name if available for the backtrace. |
| 1589 | if (display_receiver) { |
| 1590 | result += '.'; |
| 1591 | } |
| 1592 | result += func.name() ? func.name() : '[anonymous]'; |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | // Render arguments for normal frames. |
| 1597 | if (!this.isDebuggerFrame()) { |
| 1598 | result += '('; |
| 1599 | for (var i = 0; i < this.argumentCount(); i++) { |
| 1600 | if (i != 0) result += ', '; |
| 1601 | if (this.argumentName(i)) { |
| 1602 | result += this.argumentName(i); |
| 1603 | result += '='; |
| 1604 | } |
| 1605 | result += this.argumentValue(i).toText(); |
| 1606 | } |
| 1607 | result += ')'; |
| 1608 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1609 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1610 | if (this.isAtReturn()) { |
| 1611 | result += ' returning '; |
| 1612 | result += this.returnValue().toText(); |
| 1613 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 1614 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1615 | return result; |
| 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | FrameMirror.prototype.sourceAndPositionText = function() { |
| 1620 | // Format source and position. |
| 1621 | var result = ''; |
| 1622 | var func = this.func(); |
| 1623 | if (func.resolved()) { |
| 1624 | if (func.script()) { |
| 1625 | if (func.script().name()) { |
| 1626 | result += func.script().name(); |
| 1627 | } else { |
| 1628 | result += '[unnamed]'; |
| 1629 | } |
| 1630 | if (!this.isDebuggerFrame()) { |
| 1631 | var location = this.sourceLocation(); |
| 1632 | result += ' line '; |
| 1633 | result += !IS_UNDEFINED(location) ? (location.line + 1) : '?'; |
| 1634 | result += ' column '; |
| 1635 | result += !IS_UNDEFINED(location) ? (location.column + 1) : '?'; |
| 1636 | if (!IS_UNDEFINED(this.sourcePosition())) { |
| 1637 | result += ' (position ' + (this.sourcePosition() + 1) + ')'; |
| 1638 | } |
| 1639 | } |
| 1640 | } else { |
| 1641 | result += '[no source]'; |
| 1642 | } |
| 1643 | } else { |
| 1644 | result += '[unresolved]'; |
| 1645 | } |
| 1646 | |
| 1647 | return result; |
| 1648 | } |
| 1649 | |
| 1650 | |
| 1651 | FrameMirror.prototype.localsText = function() { |
| 1652 | // Format local variables. |
| 1653 | var result = ''; |
| 1654 | var locals_count = this.localCount() |
| 1655 | if (locals_count > 0) { |
| 1656 | for (var i = 0; i < locals_count; ++i) { |
| 1657 | result += ' var '; |
| 1658 | result += this.localName(i); |
| 1659 | result += ' = '; |
| 1660 | result += this.localValue(i).toText(); |
| 1661 | if (i < locals_count - 1) result += '\n'; |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | return result; |
| 1666 | } |
| 1667 | |
| 1668 | |
| 1669 | FrameMirror.prototype.toText = function(opt_locals) { |
| 1670 | var result = ''; |
| 1671 | result += '#' + (this.index() <= 9 ? '0' : '') + this.index(); |
| 1672 | result += ' '; |
| 1673 | result += this.invocationText(); |
| 1674 | result += ' '; |
| 1675 | result += this.sourceAndPositionText(); |
| 1676 | if (opt_locals) { |
| 1677 | result += '\n'; |
| 1678 | result += this.localsText(); |
| 1679 | } |
| 1680 | return result; |
| 1681 | } |
| 1682 | |
| 1683 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1684 | const kScopeDetailsTypeIndex = 0; |
| 1685 | const kScopeDetailsObjectIndex = 1; |
| 1686 | |
| 1687 | function ScopeDetails(frame, index) { |
| 1688 | this.break_id_ = frame.break_id_; |
| 1689 | this.details_ = %GetScopeDetails(frame.break_id_, |
| 1690 | frame.details_.frameId(), |
| 1691 | index); |
| 1692 | } |
| 1693 | |
| 1694 | |
| 1695 | ScopeDetails.prototype.type = function() { |
| 1696 | %CheckExecutionState(this.break_id_); |
| 1697 | return this.details_[kScopeDetailsTypeIndex]; |
| 1698 | } |
| 1699 | |
| 1700 | |
| 1701 | ScopeDetails.prototype.object = function() { |
| 1702 | %CheckExecutionState(this.break_id_); |
| 1703 | return this.details_[kScopeDetailsObjectIndex]; |
| 1704 | } |
| 1705 | |
| 1706 | |
| 1707 | /** |
| 1708 | * Mirror object for scope. |
| 1709 | * @param {FrameMirror} frame The frame this scope is a part of |
| 1710 | * @param {number} index The scope index in the frame |
| 1711 | * @constructor |
| 1712 | * @extends Mirror |
| 1713 | */ |
| 1714 | function ScopeMirror(frame, index) { |
| 1715 | Mirror.call(this, SCOPE_TYPE); |
| 1716 | this.frame_index_ = frame.index_; |
| 1717 | this.scope_index_ = index; |
| 1718 | this.details_ = new ScopeDetails(frame, index); |
| 1719 | } |
| 1720 | inherits(ScopeMirror, Mirror); |
| 1721 | |
| 1722 | |
| 1723 | ScopeMirror.prototype.frameIndex = function() { |
| 1724 | return this.frame_index_; |
| 1725 | }; |
| 1726 | |
| 1727 | |
| 1728 | ScopeMirror.prototype.scopeIndex = function() { |
| 1729 | return this.scope_index_; |
| 1730 | }; |
| 1731 | |
| 1732 | |
| 1733 | ScopeMirror.prototype.scopeType = function() { |
| 1734 | return this.details_.type(); |
| 1735 | }; |
| 1736 | |
| 1737 | |
| 1738 | ScopeMirror.prototype.scopeObject = function() { |
| 1739 | // For local and closure scopes create a transient mirror as these objects are |
| 1740 | // created on the fly materializing the local or closure scopes and |
| 1741 | // therefore will not preserve identity. |
| 1742 | var transient = this.scopeType() == ScopeType.Local || |
| 1743 | this.scopeType() == ScopeType.Closure; |
| 1744 | return MakeMirror(this.details_.object(), transient); |
| 1745 | }; |
| 1746 | |
| 1747 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1748 | /** |
| 1749 | * Mirror object for script source. |
| 1750 | * @param {Script} script The script object |
| 1751 | * @constructor |
| 1752 | * @extends Mirror |
| 1753 | */ |
| 1754 | function ScriptMirror(script) { |
| 1755 | Mirror.call(this, SCRIPT_TYPE); |
| 1756 | this.script_ = script; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1757 | this.context_ = new ContextMirror(script.context_data); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1758 | this.allocateHandle_(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1759 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1760 | inherits(ScriptMirror, Mirror); |
| 1761 | |
| 1762 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1763 | ScriptMirror.prototype.value = function() { |
| 1764 | return this.script_; |
| 1765 | }; |
| 1766 | |
| 1767 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1768 | ScriptMirror.prototype.name = function() { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1769 | return this.script_.name || this.script_.nameOrSourceURL(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1770 | }; |
| 1771 | |
| 1772 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1773 | ScriptMirror.prototype.id = function() { |
| 1774 | return this.script_.id; |
| 1775 | }; |
| 1776 | |
| 1777 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1778 | ScriptMirror.prototype.source = function() { |
| 1779 | return this.script_.source; |
| 1780 | }; |
| 1781 | |
| 1782 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1783 | ScriptMirror.prototype.lineOffset = function() { |
| 1784 | return this.script_.line_offset; |
| 1785 | }; |
| 1786 | |
| 1787 | |
| 1788 | ScriptMirror.prototype.columnOffset = function() { |
| 1789 | return this.script_.column_offset; |
| 1790 | }; |
| 1791 | |
| 1792 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1793 | ScriptMirror.prototype.data = function() { |
| 1794 | return this.script_.data; |
| 1795 | }; |
| 1796 | |
| 1797 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1798 | ScriptMirror.prototype.scriptType = function() { |
| 1799 | return this.script_.type; |
| 1800 | }; |
| 1801 | |
| 1802 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1803 | ScriptMirror.prototype.compilationType = function() { |
| 1804 | return this.script_.compilation_type; |
| 1805 | }; |
| 1806 | |
| 1807 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1808 | ScriptMirror.prototype.lineCount = function() { |
| 1809 | return this.script_.lineCount(); |
| 1810 | }; |
| 1811 | |
| 1812 | |
ager@chromium.org | 3a6061e | 2009-03-12 14:24:36 +0000 | [diff] [blame] | 1813 | ScriptMirror.prototype.locationFromPosition = function( |
| 1814 | position, include_resource_offset) { |
| 1815 | return this.script_.locationFromPosition(position, include_resource_offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | |
| 1819 | ScriptMirror.prototype.sourceSlice = function (opt_from_line, opt_to_line) { |
| 1820 | return this.script_.sourceSlice(opt_from_line, opt_to_line); |
| 1821 | } |
| 1822 | |
| 1823 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1824 | ScriptMirror.prototype.context = function() { |
| 1825 | return this.context_; |
| 1826 | }; |
| 1827 | |
| 1828 | |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 1829 | ScriptMirror.prototype.evalFromScript = function() { |
| 1830 | return MakeMirror(this.script_.eval_from_script); |
| 1831 | }; |
| 1832 | |
| 1833 | |
| 1834 | ScriptMirror.prototype.evalFromFunctionName = function() { |
| 1835 | return MakeMirror(this.script_.eval_from_function_name); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1836 | }; |
| 1837 | |
| 1838 | |
| 1839 | ScriptMirror.prototype.evalFromLocation = function() { |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 1840 | var eval_from_script = this.evalFromScript(); |
| 1841 | if (!eval_from_script.isUndefined()) { |
| 1842 | var position = this.script_.eval_from_script_position; |
| 1843 | return eval_from_script.locationFromPosition(position, true); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1844 | } |
| 1845 | }; |
| 1846 | |
| 1847 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1848 | ScriptMirror.prototype.toText = function() { |
| 1849 | var result = ''; |
| 1850 | result += this.name(); |
| 1851 | result += ' (lines: '; |
| 1852 | if (this.lineOffset() > 0) { |
| 1853 | result += this.lineOffset(); |
| 1854 | result += '-'; |
| 1855 | result += this.lineOffset() + this.lineCount() - 1; |
| 1856 | } else { |
| 1857 | result += this.lineCount(); |
| 1858 | } |
| 1859 | result += ')'; |
| 1860 | return result; |
| 1861 | } |
| 1862 | |
| 1863 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1864 | /** |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1865 | * Mirror object for context. |
| 1866 | * @param {Object} data The context data |
| 1867 | * @constructor |
| 1868 | * @extends Mirror |
| 1869 | */ |
| 1870 | function ContextMirror(data) { |
| 1871 | Mirror.call(this, CONTEXT_TYPE); |
| 1872 | this.data_ = data; |
| 1873 | this.allocateHandle_(); |
| 1874 | } |
| 1875 | inherits(ContextMirror, Mirror); |
| 1876 | |
| 1877 | |
| 1878 | ContextMirror.prototype.data = function() { |
| 1879 | return this.data_; |
| 1880 | }; |
| 1881 | |
| 1882 | |
| 1883 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1884 | * Returns a mirror serializer |
| 1885 | * |
| 1886 | * @param {boolean} details Set to true to include details |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1887 | * @param {Object} options Options comtrolling the serialization |
| 1888 | * The following options can be set: |
| 1889 | * includeSource: include ths full source of scripts |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1890 | * @returns {MirrorSerializer} mirror serializer |
| 1891 | */ |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1892 | function MakeMirrorSerializer(details, options) { |
| 1893 | return new JSONProtocolSerializer(details, options); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1897 | /** |
| 1898 | * Object for serializing a mirror objects and its direct references. |
| 1899 | * @param {boolean} details Indicates whether to include details for the mirror |
| 1900 | * serialized |
| 1901 | * @constructor |
| 1902 | */ |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1903 | function JSONProtocolSerializer(details, options) { |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1904 | this.details_ = details; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1905 | this.options_ = options; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1906 | this.mirrors_ = [ ]; |
| 1907 | } |
| 1908 | |
| 1909 | |
| 1910 | /** |
| 1911 | * Returns a serialization of an object reference. The referenced object are |
| 1912 | * added to the serialization state. |
| 1913 | * |
| 1914 | * @param {Mirror} mirror The mirror to serialize |
| 1915 | * @returns {String} JSON serialization |
| 1916 | */ |
| 1917 | JSONProtocolSerializer.prototype.serializeReference = function(mirror) { |
| 1918 | return this.serialize_(mirror, true, true); |
| 1919 | } |
| 1920 | |
| 1921 | |
| 1922 | /** |
| 1923 | * Returns a serialization of an object value. The referenced objects are |
| 1924 | * added to the serialization state. |
| 1925 | * |
| 1926 | * @param {Mirror} mirror The mirror to serialize |
| 1927 | * @returns {String} JSON serialization |
| 1928 | */ |
| 1929 | JSONProtocolSerializer.prototype.serializeValue = function(mirror) { |
| 1930 | var json = this.serialize_(mirror, false, true); |
| 1931 | return json; |
| 1932 | } |
| 1933 | |
| 1934 | |
| 1935 | /** |
| 1936 | * Returns a serialization of all the objects referenced. |
| 1937 | * |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1938 | * @param {Mirror} mirror The mirror to serialize. |
| 1939 | * @returns {Array.<Object>} Array of the referenced objects converted to |
| 1940 | * protcol objects. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1941 | */ |
| 1942 | JSONProtocolSerializer.prototype.serializeReferencedObjects = function() { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1943 | // Collect the protocol representation of the referenced objects in an array. |
| 1944 | var content = []; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1945 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1946 | // Get the number of referenced objects. |
| 1947 | var count = this.mirrors_.length; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1948 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1949 | for (var i = 0; i < count; i++) { |
| 1950 | content.push(this.serialize_(this.mirrors_[i], false, false)); |
| 1951 | } |
| 1952 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1953 | return content; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1957 | JSONProtocolSerializer.prototype.includeSource_ = function() { |
| 1958 | return this.options_ && this.options_.includeSource; |
| 1959 | } |
| 1960 | |
| 1961 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1962 | JSONProtocolSerializer.prototype.inlineRefs_ = function() { |
| 1963 | return this.options_ && this.options_.inlineRefs; |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 1967 | JSONProtocolSerializer.prototype.maxStringLength_ = function() { |
| 1968 | if (IS_UNDEFINED(this.options_) || |
| 1969 | IS_UNDEFINED(this.options_.maxStringLength)) { |
| 1970 | return kMaxProtocolStringLength; |
| 1971 | } |
| 1972 | return this.options_.maxStringLength; |
| 1973 | } |
| 1974 | |
| 1975 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1976 | JSONProtocolSerializer.prototype.add_ = function(mirror) { |
| 1977 | // If this mirror is already in the list just return. |
| 1978 | for (var i = 0; i < this.mirrors_.length; i++) { |
| 1979 | if (this.mirrors_[i] === mirror) { |
| 1980 | return; |
| 1981 | } |
| 1982 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1983 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1984 | // Add the mirror to the list of mirrors to be serialized. |
| 1985 | this.mirrors_.push(mirror); |
| 1986 | } |
| 1987 | |
| 1988 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1989 | /** |
| 1990 | * Formats mirror object to protocol reference object with some data that can |
| 1991 | * be used to display the value in debugger. |
| 1992 | * @param {Mirror} mirror Mirror to serialize. |
| 1993 | * @return {Object} Protocol reference object. |
| 1994 | */ |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 1995 | JSONProtocolSerializer.prototype.serializeReferenceWithDisplayData_ = |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 1996 | function(mirror) { |
| 1997 | var o = {}; |
| 1998 | o.ref = mirror.handle(); |
| 1999 | o.type = mirror.type(); |
| 2000 | switch (mirror.type()) { |
| 2001 | case UNDEFINED_TYPE: |
| 2002 | case NULL_TYPE: |
| 2003 | case BOOLEAN_TYPE: |
| 2004 | case NUMBER_TYPE: |
| 2005 | o.value = mirror.value(); |
| 2006 | break; |
| 2007 | case STRING_TYPE: |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 2008 | o.value = mirror.getTruncatedValue(this.maxStringLength_()); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2009 | break; |
| 2010 | case FUNCTION_TYPE: |
| 2011 | o.name = mirror.name(); |
| 2012 | o.inferredName = mirror.inferredName(); |
| 2013 | if (mirror.script()) { |
| 2014 | o.scriptId = mirror.script().id(); |
| 2015 | } |
| 2016 | break; |
| 2017 | case ERROR_TYPE: |
| 2018 | case REGEXP_TYPE: |
| 2019 | o.value = mirror.toText(); |
| 2020 | break; |
| 2021 | case OBJECT_TYPE: |
| 2022 | o.className = mirror.className(); |
| 2023 | break; |
| 2024 | } |
| 2025 | return o; |
| 2026 | }; |
| 2027 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2028 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2029 | JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, |
| 2030 | details) { |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 2031 | // If serializing a reference to a mirror just return the reference and add |
| 2032 | // the mirror to the referenced mirrors. |
| 2033 | if (reference && |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2034 | (mirror.isValue() || mirror.isScript() || mirror.isContext())) { |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2035 | if (this.inlineRefs_() && mirror.isValue()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2036 | return this.serializeReferenceWithDisplayData_(mirror); |
| 2037 | } else { |
| 2038 | this.add_(mirror); |
| 2039 | return {'ref' : mirror.handle()}; |
| 2040 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2041 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2042 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2043 | // Collect the JSON property/value pairs. |
| 2044 | var content = {}; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2045 | |
kasperl@chromium.org | 2d18d10 | 2009-04-15 13:27:32 +0000 | [diff] [blame] | 2046 | // Add the mirror handle. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2047 | if (mirror.isValue() || mirror.isScript() || mirror.isContext()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2048 | content.handle = mirror.handle(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | // Always add the type. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2052 | content.type = mirror.type(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2053 | |
| 2054 | switch (mirror.type()) { |
| 2055 | case UNDEFINED_TYPE: |
| 2056 | case NULL_TYPE: |
| 2057 | // Undefined and null are represented just by their type. |
| 2058 | break; |
| 2059 | |
| 2060 | case BOOLEAN_TYPE: |
| 2061 | // Boolean values are simply represented by their value. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2062 | content.value = mirror.value(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2063 | break; |
| 2064 | |
| 2065 | case NUMBER_TYPE: |
| 2066 | // Number values are simply represented by their value. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2067 | content.value = NumberToJSON_(mirror.value()); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2068 | break; |
| 2069 | |
| 2070 | case STRING_TYPE: |
| 2071 | // String values might have their value cropped to keep down size. |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 2072 | if (this.maxStringLength_() != -1 && |
| 2073 | mirror.length() > this.maxStringLength_()) { |
| 2074 | var str = mirror.getTruncatedValue(this.maxStringLength_()); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2075 | content.value = str; |
| 2076 | content.fromIndex = 0; |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 2077 | content.toIndex = this.maxStringLength_(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2078 | } else { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2079 | content.value = mirror.value(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2080 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2081 | content.length = mirror.length(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2082 | break; |
| 2083 | |
| 2084 | case OBJECT_TYPE: |
| 2085 | case FUNCTION_TYPE: |
| 2086 | case ERROR_TYPE: |
| 2087 | case REGEXP_TYPE: |
| 2088 | // Add object representation. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2089 | this.serializeObject_(mirror, content, details); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2090 | break; |
| 2091 | |
| 2092 | case PROPERTY_TYPE: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2093 | throw new Error('PropertyMirror cannot be serialized independeltly') |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2094 | break; |
| 2095 | |
| 2096 | case FRAME_TYPE: |
| 2097 | // Add object representation. |
| 2098 | this.serializeFrame_(mirror, content); |
| 2099 | break; |
| 2100 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2101 | case SCOPE_TYPE: |
| 2102 | // Add object representation. |
| 2103 | this.serializeScope_(mirror, content); |
| 2104 | break; |
| 2105 | |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2106 | case SCRIPT_TYPE: |
kasperl@chromium.org | 2d18d10 | 2009-04-15 13:27:32 +0000 | [diff] [blame] | 2107 | // Script is represented by id, name and source attributes. |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2108 | if (mirror.name()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2109 | content.name = mirror.name(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2110 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2111 | content.id = mirror.id(); |
| 2112 | content.lineOffset = mirror.lineOffset(); |
| 2113 | content.columnOffset = mirror.columnOffset(); |
| 2114 | content.lineCount = mirror.lineCount(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2115 | if (mirror.data()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2116 | content.data = mirror.data(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2117 | } |
| 2118 | if (this.includeSource_()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2119 | content.source = mirror.source(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2120 | } else { |
| 2121 | var sourceStart = mirror.source().substring(0, 80); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2122 | content.sourceStart = sourceStart; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2123 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2124 | content.sourceLength = mirror.source().length; |
| 2125 | content.scriptType = mirror.scriptType(); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2126 | content.compilationType = mirror.compilationType(); |
sgjesse@chromium.org | 636edf4 | 2009-06-18 14:43:07 +0000 | [diff] [blame] | 2127 | // For compilation type eval emit information on the script from which |
| 2128 | // eval was called if a script is present. |
| 2129 | if (mirror.compilationType() == 1 && |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 2130 | mirror.evalFromScript()) { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2131 | content.evalFromScript = |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 2132 | this.serializeReference(mirror.evalFromScript()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2133 | var evalFromLocation = mirror.evalFromLocation() |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2134 | if (evalFromLocation) { |
| 2135 | content.evalFromLocation = { line: evalFromLocation.line, |
| 2136 | column: evalFromLocation.column }; |
| 2137 | } |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 2138 | if (mirror.evalFromFunctionName()) { |
| 2139 | content.evalFromFunctionName = mirror.evalFromFunctionName(); |
| 2140 | } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2141 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2142 | if (mirror.context()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2143 | content.context = this.serializeReference(mirror.context()); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2144 | } |
| 2145 | break; |
| 2146 | |
| 2147 | case CONTEXT_TYPE: |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2148 | content.data = mirror.data(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2149 | break; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | // Always add the text representation. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2153 | content.text = mirror.toText(); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2154 | |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2155 | // Create and return the JSON string. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2156 | return content; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2160 | /** |
| 2161 | * Serialize object information to the following JSON format. |
| 2162 | * |
| 2163 | * {"className":"<class name>", |
| 2164 | * "constructorFunction":{"ref":<number>}, |
| 2165 | * "protoObject":{"ref":<number>}, |
| 2166 | * "prototypeObject":{"ref":<number>}, |
| 2167 | * "namedInterceptor":<boolean>, |
| 2168 | * "indexedInterceptor":<boolean>, |
| 2169 | * "properties":[<properties>]} |
| 2170 | */ |
| 2171 | JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, |
| 2172 | details) { |
| 2173 | // Add general object properties. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2174 | content.className = mirror.className(); |
| 2175 | content.constructorFunction = |
| 2176 | this.serializeReference(mirror.constructorFunction()); |
| 2177 | content.protoObject = this.serializeReference(mirror.protoObject()); |
| 2178 | content.prototypeObject = this.serializeReference(mirror.prototypeObject()); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2179 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2180 | // Add flags to indicate whether there are interceptors. |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2181 | if (mirror.hasNamedInterceptor()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2182 | content.namedInterceptor = true; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2183 | } |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2184 | if (mirror.hasIndexedInterceptor()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2185 | content.indexedInterceptor = true; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2186 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2187 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2188 | // Add function specific properties. |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2189 | if (mirror.isFunction()) { |
| 2190 | // Add function specific properties. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2191 | content.name = mirror.name(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2192 | if (!IS_UNDEFINED(mirror.inferredName())) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2193 | content.inferredName = mirror.inferredName(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 2194 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2195 | content.resolved = mirror.resolved(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2196 | if (mirror.resolved()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2197 | content.source = mirror.source(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2198 | } |
| 2199 | if (mirror.script()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2200 | content.script = this.serializeReference(mirror.script()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2201 | content.scriptId = mirror.script().id(); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2202 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2203 | serializeLocationFields(mirror.sourceLocation(), content); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2204 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | // Add date specific properties. |
| 2208 | if (mirror.isDate()) { |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2209 | // Add date specific properties. |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2210 | content.value = mirror.value(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2211 | } |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2212 | |
| 2213 | // Add actual properties - named properties followed by indexed properties. |
| 2214 | var propertyNames = mirror.propertyNames(PropertyKind.Named); |
| 2215 | var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); |
| 2216 | var p = new Array(propertyNames.length + propertyIndexes.length); |
| 2217 | for (var i = 0; i < propertyNames.length; i++) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2218 | var propertyMirror = mirror.property(propertyNames[i]); |
| 2219 | p[i] = this.serializeProperty_(propertyMirror); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2220 | if (details) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2221 | this.add_(propertyMirror.value()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | for (var i = 0; i < propertyIndexes.length; i++) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2225 | var propertyMirror = mirror.property(propertyIndexes[i]); |
| 2226 | p[propertyNames.length + i] = this.serializeProperty_(propertyMirror); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2227 | if (details) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2228 | this.add_(propertyMirror.value()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2229 | } |
| 2230 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2231 | content.properties = p; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | |
| 2235 | /** |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2236 | * Serialize location information to the following JSON format: |
| 2237 | * |
| 2238 | * "position":"<position>", |
| 2239 | * "line":"<line>", |
| 2240 | * "column":"<column>", |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2241 | * |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2242 | * @param {SourceLocation} location The location to serialize, may be undefined. |
| 2243 | */ |
| 2244 | function serializeLocationFields (location, content) { |
| 2245 | if (!location) { |
| 2246 | return; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2247 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2248 | content.position = location.position; |
| 2249 | var line = location.line; |
| 2250 | if (!IS_UNDEFINED(line)) { |
| 2251 | content.line = line; |
| 2252 | } |
| 2253 | var column = location.column; |
| 2254 | if (!IS_UNDEFINED(column)) { |
| 2255 | content.column = column; |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | |
| 2260 | /** |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2261 | * Serialize property information to the following JSON format for building the |
| 2262 | * array of properties. |
| 2263 | * |
| 2264 | * {"name":"<property name>", |
| 2265 | * "attributes":<number>, |
| 2266 | * "propertyType":<number>, |
| 2267 | * "ref":<number>} |
| 2268 | * |
| 2269 | * If the attribute for the property is PropertyAttribute.None it is not added. |
| 2270 | * If the propertyType for the property is PropertyType.Normal it is not added. |
| 2271 | * Here are a couple of examples. |
| 2272 | * |
| 2273 | * {"name":"hello","ref":1} |
| 2274 | * {"name":"length","attributes":7,"propertyType":3,"ref":2} |
| 2275 | * |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2276 | * @param {PropertyMirror} propertyMirror The property to serialize. |
| 2277 | * @returns {Object} Protocol object representing the property. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2278 | */ |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2279 | JSONProtocolSerializer.prototype.serializeProperty_ = function(propertyMirror) { |
| 2280 | var result = {}; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2281 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2282 | result.name = propertyMirror.name(); |
| 2283 | var propertyValue = propertyMirror.value(); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2284 | if (this.inlineRefs_() && propertyValue.isValue()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2285 | result.value = this.serializeReferenceWithDisplayData_(propertyValue); |
| 2286 | } else { |
| 2287 | if (propertyMirror.attributes() != PropertyAttribute.None) { |
| 2288 | result.attributes = propertyMirror.attributes(); |
| 2289 | } |
| 2290 | if (propertyMirror.propertyType() != PropertyType.Normal) { |
| 2291 | result.propertyType = propertyMirror.propertyType(); |
| 2292 | } |
| 2293 | result.ref = propertyValue.handle(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2294 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2295 | return result; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | |
| 2299 | JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2300 | content.index = mirror.index(); |
| 2301 | content.receiver = this.serializeReference(mirror.receiver()); |
kasperl@chromium.org | 2d18d10 | 2009-04-15 13:27:32 +0000 | [diff] [blame] | 2302 | var func = mirror.func(); |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2303 | content.func = this.serializeReference(func); |
kasperl@chromium.org | 2d18d10 | 2009-04-15 13:27:32 +0000 | [diff] [blame] | 2304 | if (func.script()) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2305 | content.script = this.serializeReference(func.script()); |
kasperl@chromium.org | 2d18d10 | 2009-04-15 13:27:32 +0000 | [diff] [blame] | 2306 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2307 | content.constructCall = mirror.isConstructCall(); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 2308 | content.atReturn = mirror.isAtReturn(); |
| 2309 | if (mirror.isAtReturn()) { |
| 2310 | content.returnValue = this.serializeReference(mirror.returnValue()); |
| 2311 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2312 | content.debuggerFrame = mirror.isDebuggerFrame(); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2313 | var x = new Array(mirror.argumentCount()); |
| 2314 | for (var i = 0; i < mirror.argumentCount(); i++) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2315 | var arg = {}; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2316 | var argument_name = mirror.argumentName(i) |
| 2317 | if (argument_name) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2318 | arg.name = argument_name; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2319 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2320 | arg.value = this.serializeReference(mirror.argumentValue(i)); |
| 2321 | x[i] = arg; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2322 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2323 | content.arguments = x; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2324 | var x = new Array(mirror.localCount()); |
| 2325 | for (var i = 0; i < mirror.localCount(); i++) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2326 | var local = {}; |
| 2327 | local.name = mirror.localName(i); |
| 2328 | local.value = this.serializeReference(mirror.localValue(i)); |
| 2329 | x[i] = local; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2330 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2331 | content.locals = x; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2332 | serializeLocationFields(mirror.sourceLocation(), content); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2333 | var source_line_text = mirror.sourceLineText(); |
| 2334 | if (!IS_UNDEFINED(source_line_text)) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2335 | content.sourceLineText = source_line_text; |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2336 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2337 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2338 | content.scopes = []; |
| 2339 | for (var i = 0; i < mirror.scopeCount(); i++) { |
| 2340 | var scope = mirror.scope(i); |
| 2341 | content.scopes.push({ |
| 2342 | type: scope.scopeType(), |
| 2343 | index: i |
| 2344 | }); |
| 2345 | } |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2349 | JSONProtocolSerializer.prototype.serializeScope_ = function(mirror, content) { |
| 2350 | content.index = mirror.scopeIndex(); |
| 2351 | content.frameIndex = mirror.frameIndex(); |
| 2352 | content.type = mirror.scopeType(); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2353 | content.object = this.inlineRefs_() ? |
| 2354 | this.serializeValue(mirror.scopeObject()) : |
| 2355 | this.serializeReference(mirror.scopeObject()); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | |
sgjesse@chromium.org | 715915b | 2009-01-19 16:08:47 +0000 | [diff] [blame] | 2359 | /** |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2360 | * Convert a number to a protocol value. For all finite numbers the number |
| 2361 | * itself is returned. For non finite numbers NaN, Infinite and |
sgjesse@chromium.org | 715915b | 2009-01-19 16:08:47 +0000 | [diff] [blame] | 2362 | * -Infinite the string representation "NaN", "Infinite" or "-Infinite" |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2363 | * (not including the quotes) is returned. |
sgjesse@chromium.org | 715915b | 2009-01-19 16:08:47 +0000 | [diff] [blame] | 2364 | * |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2365 | * @param {number} value The number value to convert to a protocol value. |
| 2366 | * @returns {number|string} Protocol value. |
sgjesse@chromium.org | 715915b | 2009-01-19 16:08:47 +0000 | [diff] [blame] | 2367 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2368 | function NumberToJSON_(value) { |
sgjesse@chromium.org | 715915b | 2009-01-19 16:08:47 +0000 | [diff] [blame] | 2369 | if (isNaN(value)) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2370 | return 'NaN'; |
sgjesse@chromium.org | 715915b | 2009-01-19 16:08:47 +0000 | [diff] [blame] | 2371 | } |
| 2372 | if (!isFinite(value)) { |
| 2373 | if (value > 0) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2374 | return 'Infinity'; |
sgjesse@chromium.org | 715915b | 2009-01-19 16:08:47 +0000 | [diff] [blame] | 2375 | } else { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 2376 | return '-Infinity'; |
sgjesse@chromium.org | 715915b | 2009-01-19 16:08:47 +0000 | [diff] [blame] | 2377 | } |
| 2378 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 2379 | return value; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2380 | } |