OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // jsminify this file, js2c: jsmin | 28 // jsminify this file, js2c: jsmin |
29 | 29 |
30 // Touch the RegExp and Date functions to make sure that date-delay.js and | 30 // Touch the RegExp and Date functions to make sure that date-delay.js and |
31 // regexp-delay.js has been loaded. This is required as the mirrors use | 31 // regexp-delay.js has been loaded. This is required as the mirrors use |
32 // functions within these files through the builtins object. | 32 // functions within these files through the builtins object. |
33 RegExp; | 33 RegExp; |
34 Date; | 34 Date; |
35 | 35 |
36 | 36 |
| 37 // Handle id counters. |
37 var next_handle_ = 0; | 38 var next_handle_ = 0; |
| 39 var next_transient_handle_ = -1; |
| 40 |
| 41 // Mirror cache. |
38 var mirror_cache_ = []; | 42 var mirror_cache_ = []; |
39 | 43 |
| 44 |
40 /** | 45 /** |
41 * Clear the mirror handle cache. | 46 * Clear the mirror handle cache. |
42 */ | 47 */ |
43 function ClearMirrorCache() { | 48 function ClearMirrorCache() { |
44 next_handle_ = 0; | 49 next_handle_ = 0; |
45 mirror_cache_ = []; | 50 mirror_cache_ = []; |
46 } | 51 } |
47 | 52 |
48 | 53 |
49 /** | 54 /** |
50 * Returns the mirror for a specified value or object. | 55 * Returns the mirror for a specified value or object. |
51 * | 56 * |
52 * @param {value or Object} value the value or object to retreive the mirror for | 57 * @param {value or Object} value the value or object to retreive the mirror for |
| 58 * @param {boolean} transient indicate whether this object is transient and |
| 59 * should not be added to the mirror cache. The default is not transient. |
53 * @returns {Mirror} the mirror reflects the passed value or object | 60 * @returns {Mirror} the mirror reflects the passed value or object |
54 */ | 61 */ |
55 function MakeMirror(value) { | 62 function MakeMirror(value, opt_transient) { |
56 var mirror; | 63 var mirror; |
57 for (id in mirror_cache_) { | 64 |
58 mirror = mirror_cache_[id]; | 65 // Look for non transient mirrors in the mirror cache. |
59 if (mirror.value() === value) { | 66 if (!opt_transient) { |
60 return mirror; | 67 for (id in mirror_cache_) { |
61 } | 68 mirror = mirror_cache_[id]; |
62 // Special check for NaN as NaN == NaN is false. | 69 if (mirror.value() === value) { |
63 if (mirror.isNumber() && isNaN(mirror.value()) && | 70 return mirror; |
64 typeof value == 'number' && isNaN(value)) { | 71 } |
65 return mirror; | 72 // Special check for NaN as NaN == NaN is false. |
| 73 if (mirror.isNumber() && isNaN(mirror.value()) && |
| 74 typeof value == 'number' && isNaN(value)) { |
| 75 return mirror; |
| 76 } |
66 } | 77 } |
67 } | 78 } |
68 | 79 |
69 if (IS_UNDEFINED(value)) { | 80 if (IS_UNDEFINED(value)) { |
70 mirror = new UndefinedMirror(); | 81 mirror = new UndefinedMirror(); |
71 } else if (IS_NULL(value)) { | 82 } else if (IS_NULL(value)) { |
72 mirror = new NullMirror(); | 83 mirror = new NullMirror(); |
73 } else if (IS_BOOLEAN(value)) { | 84 } else if (IS_BOOLEAN(value)) { |
74 mirror = new BooleanMirror(value); | 85 mirror = new BooleanMirror(value); |
75 } else if (IS_NUMBER(value)) { | 86 } else if (IS_NUMBER(value)) { |
76 mirror = new NumberMirror(value); | 87 mirror = new NumberMirror(value); |
77 } else if (IS_STRING(value)) { | 88 } else if (IS_STRING(value)) { |
78 mirror = new StringMirror(value); | 89 mirror = new StringMirror(value); |
79 } else if (IS_ARRAY(value)) { | 90 } else if (IS_ARRAY(value)) { |
80 mirror = new ArrayMirror(value); | 91 mirror = new ArrayMirror(value); |
81 } else if (IS_DATE(value)) { | 92 } else if (IS_DATE(value)) { |
82 mirror = new DateMirror(value); | 93 mirror = new DateMirror(value); |
83 } else if (IS_FUNCTION(value)) { | 94 } else if (IS_FUNCTION(value)) { |
84 mirror = new FunctionMirror(value); | 95 mirror = new FunctionMirror(value); |
85 } else if (IS_REGEXP(value)) { | 96 } else if (IS_REGEXP(value)) { |
86 mirror = new RegExpMirror(value); | 97 mirror = new RegExpMirror(value); |
87 } else if (IS_ERROR(value)) { | 98 } else if (IS_ERROR(value)) { |
88 mirror = new ErrorMirror(value); | 99 mirror = new ErrorMirror(value); |
89 } else if (IS_SCRIPT(value)) { | 100 } else if (IS_SCRIPT(value)) { |
90 mirror = new ScriptMirror(value); | 101 mirror = new ScriptMirror(value); |
91 } else { | 102 } else { |
92 mirror = new ObjectMirror(value); | 103 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); |
93 } | 104 } |
94 | 105 |
95 mirror_cache_[mirror.handle()] = mirror; | 106 mirror_cache_[mirror.handle()] = mirror; |
96 return mirror; | 107 return mirror; |
97 } | 108 } |
98 | 109 |
99 | 110 |
100 /** | 111 /** |
101 * Returns the mirror for a specified mirror handle. | 112 * Returns the mirror for a specified mirror handle. |
102 * | 113 * |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 const NUMBER_TYPE = 'number'; | 159 const NUMBER_TYPE = 'number'; |
149 const STRING_TYPE = 'string'; | 160 const STRING_TYPE = 'string'; |
150 const OBJECT_TYPE = 'object'; | 161 const OBJECT_TYPE = 'object'; |
151 const FUNCTION_TYPE = 'function'; | 162 const FUNCTION_TYPE = 'function'; |
152 const REGEXP_TYPE = 'regexp'; | 163 const REGEXP_TYPE = 'regexp'; |
153 const ERROR_TYPE = 'error'; | 164 const ERROR_TYPE = 'error'; |
154 const PROPERTY_TYPE = 'property'; | 165 const PROPERTY_TYPE = 'property'; |
155 const FRAME_TYPE = 'frame'; | 166 const FRAME_TYPE = 'frame'; |
156 const SCRIPT_TYPE = 'script'; | 167 const SCRIPT_TYPE = 'script'; |
157 const CONTEXT_TYPE = 'context'; | 168 const CONTEXT_TYPE = 'context'; |
| 169 const SCOPE_TYPE = 'scope'; |
158 | 170 |
159 // Maximum length when sending strings through the JSON protocol. | 171 // Maximum length when sending strings through the JSON protocol. |
160 const kMaxProtocolStringLength = 80; | 172 const kMaxProtocolStringLength = 80; |
161 | 173 |
162 // Different kind of properties. | 174 // Different kind of properties. |
163 PropertyKind = {}; | 175 PropertyKind = {}; |
164 PropertyKind.Named = 1; | 176 PropertyKind.Named = 1; |
165 PropertyKind.Indexed = 2; | 177 PropertyKind.Indexed = 2; |
166 | 178 |
167 | 179 |
(...skipping 10 matching lines...) Expand all Loading... |
178 | 190 |
179 | 191 |
180 // Different attributes for a property. | 192 // Different attributes for a property. |
181 PropertyAttribute = {}; | 193 PropertyAttribute = {}; |
182 PropertyAttribute.None = NONE; | 194 PropertyAttribute.None = NONE; |
183 PropertyAttribute.ReadOnly = READ_ONLY; | 195 PropertyAttribute.ReadOnly = READ_ONLY; |
184 PropertyAttribute.DontEnum = DONT_ENUM; | 196 PropertyAttribute.DontEnum = DONT_ENUM; |
185 PropertyAttribute.DontDelete = DONT_DELETE; | 197 PropertyAttribute.DontDelete = DONT_DELETE; |
186 | 198 |
187 | 199 |
| 200 // A copy of the scope types from runtime.cc. |
| 201 ScopeType = { Global: 0, |
| 202 Local: 1, |
| 203 With: 2, |
| 204 Closure: 3 }; |
| 205 |
| 206 |
188 // Mirror hierarchy: | 207 // Mirror hierarchy: |
189 // - Mirror | 208 // - Mirror |
190 // - ValueMirror | 209 // - ValueMirror |
191 // - UndefinedMirror | 210 // - UndefinedMirror |
192 // - NullMirror | 211 // - NullMirror |
193 // - NumberMirror | 212 // - NumberMirror |
194 // - StringMirror | 213 // - StringMirror |
195 // - ObjectMirror | 214 // - ObjectMirror |
196 // - FunctionMirror | 215 // - FunctionMirror |
197 // - UnresolvedFunctionMirror | 216 // - UnresolvedFunctionMirror |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 /** | 385 /** |
367 * Check whether the mirror reflects a context. | 386 * Check whether the mirror reflects a context. |
368 * @returns {boolean} True if the mirror reflects a context | 387 * @returns {boolean} True if the mirror reflects a context |
369 */ | 388 */ |
370 Mirror.prototype.isContext = function() { | 389 Mirror.prototype.isContext = function() { |
371 return this instanceof ContextMirror; | 390 return this instanceof ContextMirror; |
372 } | 391 } |
373 | 392 |
374 | 393 |
375 /** | 394 /** |
| 395 * Check whether the mirror reflects a scope. |
| 396 * @returns {boolean} True if the mirror reflects a scope |
| 397 */ |
| 398 Mirror.prototype.isScope = function() { |
| 399 return this instanceof ScopeMirror; |
| 400 } |
| 401 |
| 402 |
| 403 /** |
376 * Allocate a handle id for this object. | 404 * Allocate a handle id for this object. |
377 */ | 405 */ |
378 Mirror.prototype.allocateHandle_ = function() { | 406 Mirror.prototype.allocateHandle_ = function() { |
379 this.handle_ = next_handle_++; | 407 this.handle_ = next_handle_++; |
380 } | 408 } |
381 | 409 |
382 | 410 |
| 411 /** |
| 412 * Allocate a transient handle id for this object. Transient handles are |
| 413 * negative. |
| 414 */ |
| 415 Mirror.prototype.allocateTransientHandle_ = function() { |
| 416 this.handle_ = next_transient_handle_--; |
| 417 } |
| 418 |
| 419 |
383 Mirror.prototype.toText = function() { | 420 Mirror.prototype.toText = function() { |
384 // Simpel to text which is used when on specialization in subclass. | 421 // Simpel to text which is used when on specialization in subclass. |
385 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; | 422 return "#<" + builtins.GetInstanceName(this.constructor.name) + ">"; |
386 } | 423 } |
387 | 424 |
388 | 425 |
389 /** | 426 /** |
390 * Base class for all value mirror objects. | 427 * Base class for all value mirror objects. |
391 * @param {string} type The type of the mirror | 428 * @param {string} type The type of the mirror |
392 * @param {value} value The value reflected by this mirror | 429 * @param {value} value The value reflected by this mirror |
| 430 * @param {boolean} transient indicate whether this object is transient with a |
| 431 * transient handle |
393 * @constructor | 432 * @constructor |
394 * @extends Mirror | 433 * @extends Mirror |
395 */ | 434 */ |
396 function ValueMirror(type, value) { | 435 function ValueMirror(type, value, transient) { |
397 Mirror.call(this, type); | 436 Mirror.call(this, type); |
398 this.value_ = value; | 437 this.value_ = value; |
399 this.allocateHandle_(); | 438 if (!transient) { |
| 439 this.allocateHandle_(); |
| 440 } else { |
| 441 this.allocateTransientHandle_(); |
| 442 } |
400 } | 443 } |
401 inherits(ValueMirror, Mirror); | 444 inherits(ValueMirror, Mirror); |
402 | 445 |
403 | 446 |
404 Mirror.prototype.handle = function() { | 447 Mirror.prototype.handle = function() { |
405 return this.handle_; | 448 return this.handle_; |
406 }; | 449 }; |
407 | 450 |
408 | 451 |
409 /** | 452 /** |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 '... (length: ' + this.length() + ')'; | 561 '... (length: ' + this.length() + ')'; |
519 } else { | 562 } else { |
520 return this.value_; | 563 return this.value_; |
521 } | 564 } |
522 } | 565 } |
523 | 566 |
524 | 567 |
525 /** | 568 /** |
526 * Mirror object for objects. | 569 * Mirror object for objects. |
527 * @param {object} value The object reflected by this mirror | 570 * @param {object} value The object reflected by this mirror |
| 571 * @param {boolean} transient indicate whether this object is transient with a |
| 572 * transient handle |
528 * @constructor | 573 * @constructor |
529 * @extends ValueMirror | 574 * @extends ValueMirror |
530 */ | 575 */ |
531 function ObjectMirror(value, type) { | 576 function ObjectMirror(value, type, transient) { |
532 ValueMirror.call(this, type || OBJECT_TYPE, value); | 577 ValueMirror.call(this, type || OBJECT_TYPE, value, transient); |
533 } | 578 } |
534 inherits(ObjectMirror, ValueMirror); | 579 inherits(ObjectMirror, ValueMirror); |
535 | 580 |
536 | 581 |
537 ObjectMirror.prototype.className = function() { | 582 ObjectMirror.prototype.className = function() { |
538 return %ClassOf(this.value_); | 583 return %ClassOf(this.value_); |
539 }; | 584 }; |
540 | 585 |
541 | 586 |
542 ObjectMirror.prototype.constructorFunction = function() { | 587 ObjectMirror.prototype.constructorFunction = function() { |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 for (var i = 0; i < this.name_.length; i++) { | 1118 for (var i = 0; i < this.name_.length; i++) { |
1074 if (this.name_[i] < '0' || '9' < this.name_[i]) { | 1119 if (this.name_[i] < '0' || '9' < this.name_[i]) { |
1075 return false; | 1120 return false; |
1076 } | 1121 } |
1077 } | 1122 } |
1078 return true; | 1123 return true; |
1079 } | 1124 } |
1080 | 1125 |
1081 | 1126 |
1082 PropertyMirror.prototype.value = function() { | 1127 PropertyMirror.prototype.value = function() { |
1083 return MakeMirror(this.value_); | 1128 return MakeMirror(this.value_, false); |
1084 } | 1129 } |
1085 | 1130 |
1086 | 1131 |
1087 /** | 1132 /** |
1088 * Returns whether this property value is an exception. | 1133 * Returns whether this property value is an exception. |
1089 * @return {booolean} True if this property value is an exception | 1134 * @return {booolean} True if this property value is an exception |
1090 */ | 1135 */ |
1091 PropertyMirror.prototype.isException = function() { | 1136 PropertyMirror.prototype.isException = function() { |
1092 return this.exception_ ? true : false; | 1137 return this.exception_ ? true : false; |
1093 } | 1138 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 | 1173 |
1129 /** | 1174 /** |
1130 * Returns the getter for this property defined through __defineGetter__. | 1175 * Returns the getter for this property defined through __defineGetter__. |
1131 * @return {Mirror} FunctionMirror reflecting the getter function or | 1176 * @return {Mirror} FunctionMirror reflecting the getter function or |
1132 * UndefinedMirror if there is no getter for this property | 1177 * UndefinedMirror if there is no getter for this property |
1133 */ | 1178 */ |
1134 PropertyMirror.prototype.getter = function() { | 1179 PropertyMirror.prototype.getter = function() { |
1135 if (this.hasGetter()) { | 1180 if (this.hasGetter()) { |
1136 return MakeMirror(this.getter_); | 1181 return MakeMirror(this.getter_); |
1137 } else { | 1182 } else { |
1138 return new UndefinedMirror(); | 1183 return GetUndefinedMirror(); |
1139 } | 1184 } |
1140 } | 1185 } |
1141 | 1186 |
1142 | 1187 |
1143 /** | 1188 /** |
1144 * Returns the setter for this property defined through __defineSetter__. | 1189 * Returns the setter for this property defined through __defineSetter__. |
1145 * @return {Mirror} FunctionMirror reflecting the setter function or | 1190 * @return {Mirror} FunctionMirror reflecting the setter function or |
1146 * UndefinedMirror if there is no setter for this property | 1191 * UndefinedMirror if there is no setter for this property |
1147 */ | 1192 */ |
1148 PropertyMirror.prototype.setter = function() { | 1193 PropertyMirror.prototype.setter = function() { |
1149 if (this.hasSetter()) { | 1194 if (this.hasSetter()) { |
1150 return MakeMirror(this.setter_); | 1195 return MakeMirror(this.setter_); |
1151 } else { | 1196 } else { |
1152 return new UndefinedMirror(); | 1197 return GetUndefinedMirror(); |
1153 } | 1198 } |
1154 } | 1199 } |
1155 | 1200 |
1156 | 1201 |
1157 /** | 1202 /** |
1158 * Returns whether this property is natively implemented by the host or a set | 1203 * Returns whether this property is natively implemented by the host or a set |
1159 * through JavaScript code. | 1204 * through JavaScript code. |
1160 * @return {boolean} True if the property is | 1205 * @return {boolean} True if the property is |
1161 * UndefinedMirror if there is no setter for this property | 1206 * UndefinedMirror if there is no setter for this property |
1162 */ | 1207 */ |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 %CheckExecutionState(this.break_id_); | 1332 %CheckExecutionState(this.break_id_); |
1288 if (index >= 0 && index < this.localCount()) { | 1333 if (index >= 0 && index < this.localCount()) { |
1289 var locals_offset = kFrameDetailsFirstDynamicIndex + this.argumentCount() *
kFrameDetailsNameValueSize | 1334 var locals_offset = kFrameDetailsFirstDynamicIndex + this.argumentCount() *
kFrameDetailsNameValueSize |
1290 return this.details_[locals_offset + | 1335 return this.details_[locals_offset + |
1291 index * kFrameDetailsNameValueSize + | 1336 index * kFrameDetailsNameValueSize + |
1292 kFrameDetailsValueIndex] | 1337 kFrameDetailsValueIndex] |
1293 } | 1338 } |
1294 } | 1339 } |
1295 | 1340 |
1296 | 1341 |
| 1342 FrameDetails.prototype.scopeCount = function() { |
| 1343 return %GetScopeCount(this.break_id_, this.frameId()); |
| 1344 } |
| 1345 |
| 1346 |
1297 /** | 1347 /** |
1298 * Mirror object for stack frames. | 1348 * Mirror object for stack frames. |
1299 * @param {number} break_id The break id in the VM for which this frame is | 1349 * @param {number} break_id The break id in the VM for which this frame is |
1300 valid | 1350 valid |
1301 * @param {number} index The frame index (top frame is index 0) | 1351 * @param {number} index The frame index (top frame is index 0) |
1302 * @constructor | 1352 * @constructor |
1303 * @extends Mirror | 1353 * @extends Mirror |
1304 */ | 1354 */ |
1305 function FrameMirror(break_id, index) { | 1355 function FrameMirror(break_id, index) { |
1306 Mirror.call(this, FRAME_TYPE); | 1356 Mirror.call(this, FRAME_TYPE); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 FrameMirror.prototype.sourceLineText = function() { | 1462 FrameMirror.prototype.sourceLineText = function() { |
1413 if (this.func().resolved()) { | 1463 if (this.func().resolved()) { |
1414 var location = this.sourceLocation(); | 1464 var location = this.sourceLocation(); |
1415 if (location) { | 1465 if (location) { |
1416 return location.sourceText(); | 1466 return location.sourceText(); |
1417 } | 1467 } |
1418 } | 1468 } |
1419 }; | 1469 }; |
1420 | 1470 |
1421 | 1471 |
| 1472 FrameMirror.prototype.scopeCount = function() { |
| 1473 return this.details_.scopeCount(); |
| 1474 }; |
| 1475 |
| 1476 |
| 1477 FrameMirror.prototype.scope = function(index) { |
| 1478 return new ScopeMirror(this, index); |
| 1479 }; |
| 1480 |
| 1481 |
1422 FrameMirror.prototype.evaluate = function(source, disable_break) { | 1482 FrameMirror.prototype.evaluate = function(source, disable_break) { |
1423 var result = %DebugEvaluate(this.break_id_, this.details_.frameId(), | 1483 var result = %DebugEvaluate(this.break_id_, this.details_.frameId(), |
1424 source, Boolean(disable_break)); | 1484 source, Boolean(disable_break)); |
1425 return MakeMirror(result); | 1485 return MakeMirror(result); |
1426 }; | 1486 }; |
1427 | 1487 |
1428 | 1488 |
1429 FrameMirror.prototype.invocationText = function() { | 1489 FrameMirror.prototype.invocationText = function() { |
1430 // Format frame invoaction (receiver, function and arguments). | 1490 // Format frame invoaction (receiver, function and arguments). |
1431 var result = ''; | 1491 var result = ''; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 result += ' '; | 1615 result += ' '; |
1556 result += this.sourceAndPositionText(); | 1616 result += this.sourceAndPositionText(); |
1557 if (opt_locals) { | 1617 if (opt_locals) { |
1558 result += '\n'; | 1618 result += '\n'; |
1559 result += this.localsText(); | 1619 result += this.localsText(); |
1560 } | 1620 } |
1561 return result; | 1621 return result; |
1562 } | 1622 } |
1563 | 1623 |
1564 | 1624 |
| 1625 const kScopeDetailsTypeIndex = 0; |
| 1626 const kScopeDetailsObjectIndex = 1; |
| 1627 |
| 1628 function ScopeDetails(frame, index) { |
| 1629 this.break_id_ = frame.break_id_; |
| 1630 this.details_ = %GetScopeDetails(frame.break_id_, |
| 1631 frame.details_.frameId(), |
| 1632 index); |
| 1633 } |
| 1634 |
| 1635 |
| 1636 ScopeDetails.prototype.type = function() { |
| 1637 %CheckExecutionState(this.break_id_); |
| 1638 return this.details_[kScopeDetailsTypeIndex]; |
| 1639 } |
| 1640 |
| 1641 |
| 1642 ScopeDetails.prototype.object = function() { |
| 1643 %CheckExecutionState(this.break_id_); |
| 1644 return this.details_[kScopeDetailsObjectIndex]; |
| 1645 } |
| 1646 |
| 1647 |
| 1648 /** |
| 1649 * Mirror object for scope. |
| 1650 * @param {FrameMirror} frame The frame this scope is a part of |
| 1651 * @param {number} index The scope index in the frame |
| 1652 * @constructor |
| 1653 * @extends Mirror |
| 1654 */ |
| 1655 function ScopeMirror(frame, index) { |
| 1656 Mirror.call(this, SCOPE_TYPE); |
| 1657 this.frame_index_ = frame.index_; |
| 1658 this.scope_index_ = index; |
| 1659 this.details_ = new ScopeDetails(frame, index); |
| 1660 } |
| 1661 inherits(ScopeMirror, Mirror); |
| 1662 |
| 1663 |
| 1664 ScopeMirror.prototype.frameIndex = function() { |
| 1665 return this.frame_index_; |
| 1666 }; |
| 1667 |
| 1668 |
| 1669 ScopeMirror.prototype.scopeIndex = function() { |
| 1670 return this.scope_index_; |
| 1671 }; |
| 1672 |
| 1673 |
| 1674 ScopeMirror.prototype.scopeType = function() { |
| 1675 return this.details_.type(); |
| 1676 }; |
| 1677 |
| 1678 |
| 1679 ScopeMirror.prototype.scopeObject = function() { |
| 1680 // For local and closure scopes create a transient mirror as these objects are |
| 1681 // created on the fly materializing the local or closure scopes and |
| 1682 // therefore will not preserve identity. |
| 1683 var transient = this.scopeType() == ScopeType.Local || |
| 1684 this.scopeType() == ScopeType.Closure; |
| 1685 return MakeMirror(this.details_.object(), transient); |
| 1686 }; |
| 1687 |
| 1688 |
1565 /** | 1689 /** |
1566 * Mirror object for script source. | 1690 * Mirror object for script source. |
1567 * @param {Script} script The script object | 1691 * @param {Script} script The script object |
1568 * @constructor | 1692 * @constructor |
1569 * @extends Mirror | 1693 * @extends Mirror |
1570 */ | 1694 */ |
1571 function ScriptMirror(script) { | 1695 function ScriptMirror(script) { |
1572 Mirror.call(this, SCRIPT_TYPE); | 1696 Mirror.call(this, SCRIPT_TYPE); |
1573 this.script_ = script; | 1697 this.script_ = script; |
1574 this.context_ = new ContextMirror(script.context_data); | 1698 this.context_ = new ContextMirror(script.context_data); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1822 case REGEXP_TYPE: | 1946 case REGEXP_TYPE: |
1823 o.value = mirror.toText(); | 1947 o.value = mirror.toText(); |
1824 break; | 1948 break; |
1825 case OBJECT_TYPE: | 1949 case OBJECT_TYPE: |
1826 o.className = mirror.className(); | 1950 o.className = mirror.className(); |
1827 break; | 1951 break; |
1828 } | 1952 } |
1829 return o; | 1953 return o; |
1830 }; | 1954 }; |
1831 | 1955 |
| 1956 |
1832 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, | 1957 JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, |
1833 details) { | 1958 details) { |
1834 // If serializing a reference to a mirror just return the reference and add | 1959 // If serializing a reference to a mirror just return the reference and add |
1835 // the mirror to the referenced mirrors. | 1960 // the mirror to the referenced mirrors. |
1836 if (reference && | 1961 if (reference && |
1837 (mirror.isValue() || mirror.isScript() || mirror.isContext())) { | 1962 (mirror.isValue() || mirror.isScript() || mirror.isContext())) { |
1838 if (this.compactFormat_() && mirror.isValue()) { | 1963 if (this.compactFormat_() && mirror.isValue()) { |
1839 return this.serializeReferenceWithDisplayData_(mirror); | 1964 return this.serializeReferenceWithDisplayData_(mirror); |
1840 } else { | 1965 } else { |
1841 this.add_(mirror); | 1966 this.add_(mirror); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1893 | 2018 |
1894 case PROPERTY_TYPE: | 2019 case PROPERTY_TYPE: |
1895 throw new Error('PropertyMirror cannot be serialized independeltly') | 2020 throw new Error('PropertyMirror cannot be serialized independeltly') |
1896 break; | 2021 break; |
1897 | 2022 |
1898 case FRAME_TYPE: | 2023 case FRAME_TYPE: |
1899 // Add object representation. | 2024 // Add object representation. |
1900 this.serializeFrame_(mirror, content); | 2025 this.serializeFrame_(mirror, content); |
1901 break; | 2026 break; |
1902 | 2027 |
| 2028 case SCOPE_TYPE: |
| 2029 // Add object representation. |
| 2030 this.serializeScope_(mirror, content); |
| 2031 break; |
| 2032 |
1903 case SCRIPT_TYPE: | 2033 case SCRIPT_TYPE: |
1904 // Script is represented by id, name and source attributes. | 2034 // Script is represented by id, name and source attributes. |
1905 if (mirror.name()) { | 2035 if (mirror.name()) { |
1906 content.name = mirror.name(); | 2036 content.name = mirror.name(); |
1907 } | 2037 } |
1908 content.id = mirror.id(); | 2038 content.id = mirror.id(); |
1909 content.lineOffset = mirror.lineOffset(); | 2039 content.lineOffset = mirror.lineOffset(); |
1910 content.columnOffset = mirror.columnOffset(); | 2040 content.columnOffset = mirror.columnOffset(); |
1911 content.lineCount = mirror.lineCount(); | 2041 content.lineCount = mirror.lineCount(); |
1912 if (mirror.data()) { | 2042 if (mirror.data()) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 if (!IS_UNDEFINED(column)) { | 2225 if (!IS_UNDEFINED(column)) { |
2096 content.column = column; | 2226 content.column = column; |
2097 } | 2227 } |
2098 var source_line_text = mirror.sourceLineText(); | 2228 var source_line_text = mirror.sourceLineText(); |
2099 if (!IS_UNDEFINED(source_line_text)) { | 2229 if (!IS_UNDEFINED(source_line_text)) { |
2100 content.sourceLineText = source_line_text; | 2230 content.sourceLineText = source_line_text; |
2101 } | 2231 } |
2102 } | 2232 } |
2103 | 2233 |
2104 | 2234 |
| 2235 JSONProtocolSerializer.prototype.serializeScope_ = function(mirror, content) { |
| 2236 content.index = mirror.scopeIndex(); |
| 2237 content.frameIndex = mirror.frameIndex(); |
| 2238 content.type = mirror.scopeType(); |
| 2239 content.object = this.serializeReference(mirror.scopeObject()); |
| 2240 } |
| 2241 |
| 2242 |
2105 /** | 2243 /** |
2106 * Convert a number to a protocol value. For all finite numbers the number | 2244 * Convert a number to a protocol value. For all finite numbers the number |
2107 * itself is returned. For non finite numbers NaN, Infinite and | 2245 * itself is returned. For non finite numbers NaN, Infinite and |
2108 * -Infinite the string representation "NaN", "Infinite" or "-Infinite" | 2246 * -Infinite the string representation "NaN", "Infinite" or "-Infinite" |
2109 * (not including the quotes) is returned. | 2247 * (not including the quotes) is returned. |
2110 * | 2248 * |
2111 * @param {number} value The number value to convert to a protocol value. | 2249 * @param {number} value The number value to convert to a protocol value. |
2112 * @returns {number|string} Protocol value. | 2250 * @returns {number|string} Protocol value. |
2113 */ | 2251 */ |
2114 function NumberToJSON_(value) { | 2252 function NumberToJSON_(value) { |
2115 if (isNaN(value)) { | 2253 if (isNaN(value)) { |
2116 return 'NaN'; | 2254 return 'NaN'; |
2117 } | 2255 } |
2118 if (!isFinite(value)) { | 2256 if (!isFinite(value)) { |
2119 if (value > 0) { | 2257 if (value > 0) { |
2120 return 'Infinity'; | 2258 return 'Infinity'; |
2121 } else { | 2259 } else { |
2122 return '-Infinity'; | 2260 return '-Infinity'; |
2123 } | 2261 } |
2124 } | 2262 } |
2125 return value; | 2263 return value; |
2126 } | 2264 } |
OLD | NEW |