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