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