OLD | NEW |
1 // Copyright 2006-2012 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Handle id counters. | 5 // Handle id counters. |
6 var next_handle_ = 0; | 6 var next_handle_ = 0; |
7 var next_transient_handle_ = -1; | 7 var next_transient_handle_ = -1; |
8 | 8 |
9 // Mirror cache. | 9 // Mirror cache. |
10 var mirror_cache_ = []; | 10 var mirror_cache_ = []; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } else if (IS_ERROR(value)) { | 80 } else if (IS_ERROR(value)) { |
81 mirror = new ErrorMirror(value); | 81 mirror = new ErrorMirror(value); |
82 } else if (IS_SCRIPT(value)) { | 82 } else if (IS_SCRIPT(value)) { |
83 mirror = new ScriptMirror(value); | 83 mirror = new ScriptMirror(value); |
84 } else if (IS_MAP(value) || IS_WEAKMAP(value)) { | 84 } else if (IS_MAP(value) || IS_WEAKMAP(value)) { |
85 mirror = new MapMirror(value); | 85 mirror = new MapMirror(value); |
86 } else if (IS_SET(value) || IS_WEAKSET(value)) { | 86 } else if (IS_SET(value) || IS_WEAKSET(value)) { |
87 mirror = new SetMirror(value); | 87 mirror = new SetMirror(value); |
88 } else if (ObjectIsPromise(value)) { | 88 } else if (ObjectIsPromise(value)) { |
89 mirror = new PromiseMirror(value); | 89 mirror = new PromiseMirror(value); |
| 90 } else if (IS_GENERATOR(value)) { |
| 91 mirror = new GeneratorMirror(value); |
90 } else { | 92 } else { |
91 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); | 93 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); |
92 } | 94 } |
93 | 95 |
94 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror; | 96 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror; |
95 return mirror; | 97 return mirror; |
96 } | 98 } |
97 | 99 |
98 | 100 |
99 /** | 101 /** |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 var ERROR_TYPE = 'error'; | 156 var ERROR_TYPE = 'error'; |
155 var PROPERTY_TYPE = 'property'; | 157 var PROPERTY_TYPE = 'property'; |
156 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; | 158 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; |
157 var FRAME_TYPE = 'frame'; | 159 var FRAME_TYPE = 'frame'; |
158 var SCRIPT_TYPE = 'script'; | 160 var SCRIPT_TYPE = 'script'; |
159 var CONTEXT_TYPE = 'context'; | 161 var CONTEXT_TYPE = 'context'; |
160 var SCOPE_TYPE = 'scope'; | 162 var SCOPE_TYPE = 'scope'; |
161 var PROMISE_TYPE = 'promise'; | 163 var PROMISE_TYPE = 'promise'; |
162 var MAP_TYPE = 'map'; | 164 var MAP_TYPE = 'map'; |
163 var SET_TYPE = 'set'; | 165 var SET_TYPE = 'set'; |
| 166 var GENERATOR_TYPE = 'generator'; |
164 | 167 |
165 // Maximum length when sending strings through the JSON protocol. | 168 // Maximum length when sending strings through the JSON protocol. |
166 var kMaxProtocolStringLength = 80; | 169 var kMaxProtocolStringLength = 80; |
167 | 170 |
168 // Different kind of properties. | 171 // Different kind of properties. |
169 var PropertyKind = {}; | 172 var PropertyKind = {}; |
170 PropertyKind.Named = 1; | 173 PropertyKind.Named = 1; |
171 PropertyKind.Indexed = 2; | 174 PropertyKind.Indexed = 2; |
172 | 175 |
173 | 176 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // - ObjectMirror | 210 // - ObjectMirror |
208 // - FunctionMirror | 211 // - FunctionMirror |
209 // - UnresolvedFunctionMirror | 212 // - UnresolvedFunctionMirror |
210 // - ArrayMirror | 213 // - ArrayMirror |
211 // - DateMirror | 214 // - DateMirror |
212 // - RegExpMirror | 215 // - RegExpMirror |
213 // - ErrorMirror | 216 // - ErrorMirror |
214 // - PromiseMirror | 217 // - PromiseMirror |
215 // - MapMirror | 218 // - MapMirror |
216 // - SetMirror | 219 // - SetMirror |
| 220 // - GeneratorMirror |
217 // - PropertyMirror | 221 // - PropertyMirror |
218 // - InternalPropertyMirror | 222 // - InternalPropertyMirror |
219 // - FrameMirror | 223 // - FrameMirror |
220 // - ScriptMirror | 224 // - ScriptMirror |
221 | 225 |
222 | 226 |
223 /** | 227 /** |
224 * Base class for all mirror objects. | 228 * Base class for all mirror objects. |
225 * @param {string} type The type of the mirror | 229 * @param {string} type The type of the mirror |
226 * @constructor | 230 * @constructor |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 /** | 368 /** |
365 * Check whether the mirror reflects a promise. | 369 * Check whether the mirror reflects a promise. |
366 * @returns {boolean} True if the mirror reflects a promise | 370 * @returns {boolean} True if the mirror reflects a promise |
367 */ | 371 */ |
368 Mirror.prototype.isPromise = function() { | 372 Mirror.prototype.isPromise = function() { |
369 return this instanceof PromiseMirror; | 373 return this instanceof PromiseMirror; |
370 }; | 374 }; |
371 | 375 |
372 | 376 |
373 /** | 377 /** |
| 378 * Check whether the mirror reflects a generator object. |
| 379 * @returns {boolean} True if the mirror reflects a generator object |
| 380 */ |
| 381 Mirror.prototype.isGenerator = function() { |
| 382 return this instanceof GeneratorMirror; |
| 383 }; |
| 384 |
| 385 |
| 386 /** |
374 * Check whether the mirror reflects a property. | 387 * Check whether the mirror reflects a property. |
375 * @returns {boolean} True if the mirror reflects a property | 388 * @returns {boolean} True if the mirror reflects a property |
376 */ | 389 */ |
377 Mirror.prototype.isProperty = function() { | 390 Mirror.prototype.isProperty = function() { |
378 return this instanceof PropertyMirror; | 391 return this instanceof PropertyMirror; |
379 }; | 392 }; |
380 | 393 |
381 | 394 |
382 /** | 395 /** |
383 * Check whether the mirror reflects an internal property. | 396 * Check whether the mirror reflects an internal property. |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 } | 992 } |
980 }; | 993 }; |
981 | 994 |
982 | 995 |
983 /** | 996 /** |
984 * Returns the script source position for the function. Only makes sense | 997 * Returns the script source position for the function. Only makes sense |
985 * for functions which has a script defined. | 998 * for functions which has a script defined. |
986 * @return {Number or undefined} in-script position for the function | 999 * @return {Number or undefined} in-script position for the function |
987 */ | 1000 */ |
988 FunctionMirror.prototype.sourcePosition_ = function() { | 1001 FunctionMirror.prototype.sourcePosition_ = function() { |
989 // Return script if function is resolved. Otherwise just fall through | 1002 // Return position if function is resolved. Otherwise just fall |
990 // to return undefined. | 1003 // through to return undefined. |
991 if (this.resolved()) { | 1004 if (this.resolved()) { |
992 return %FunctionGetScriptSourcePosition(this.value_); | 1005 return %FunctionGetScriptSourcePosition(this.value_); |
993 } | 1006 } |
994 }; | 1007 }; |
995 | 1008 |
996 | 1009 |
997 /** | 1010 /** |
998 * Returns the script source location object for the function. Only makes sense | 1011 * Returns the script source location object for the function. Only makes sense |
999 * for functions which has a script defined. | 1012 * for functions which has a script defined. |
1000 * @return {Location or undefined} in-script location for the function begin | 1013 * @return {Location or undefined} in-script location for the function begin |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 var iter = %_CallFunction(this.value_, builtins.SetValues); | 1358 var iter = %_CallFunction(this.value_, builtins.SetValues); |
1346 var next; | 1359 var next; |
1347 while (!(next = iter.next()).done) { | 1360 while (!(next = iter.next()).done) { |
1348 result.push(next.value); | 1361 result.push(next.value); |
1349 } | 1362 } |
1350 return result; | 1363 return result; |
1351 }; | 1364 }; |
1352 | 1365 |
1353 | 1366 |
1354 /** | 1367 /** |
| 1368 * Mirror object for a Generator object. |
| 1369 * @param {Object} data The Generator object |
| 1370 * @constructor |
| 1371 * @extends Mirror |
| 1372 */ |
| 1373 function GeneratorMirror(value) { |
| 1374 %_CallFunction(this, value, GENERATOR_TYPE, ObjectMirror); |
| 1375 } |
| 1376 inherits(GeneratorMirror, ObjectMirror); |
| 1377 |
| 1378 |
| 1379 GeneratorMirror.prototype.status = function() { |
| 1380 var continuation = %GeneratorGetContinuation(this.value_); |
| 1381 if (continuation < 0) return "running"; |
| 1382 if (continuation == 0) return "closed"; |
| 1383 return "suspended"; |
| 1384 }; |
| 1385 |
| 1386 |
| 1387 GeneratorMirror.prototype.sourcePosition_ = function() { |
| 1388 return %GeneratorGetSourcePosition(this.value_); |
| 1389 }; |
| 1390 |
| 1391 |
| 1392 GeneratorMirror.prototype.sourceLocation = function() { |
| 1393 var pos = this.sourcePosition_(); |
| 1394 if (!IS_UNDEFINED(pos)) { |
| 1395 var script = this.func().script(); |
| 1396 if (script) { |
| 1397 return script.locationFromPosition(pos, true); |
| 1398 } |
| 1399 } |
| 1400 }; |
| 1401 |
| 1402 |
| 1403 GeneratorMirror.prototype.func = function() { |
| 1404 if (!this.func_) { |
| 1405 this.func_ = MakeMirror(%GeneratorGetFunction(this.value_)); |
| 1406 } |
| 1407 return this.func_; |
| 1408 }; |
| 1409 |
| 1410 |
| 1411 GeneratorMirror.prototype.context = function() { |
| 1412 if (!this.context_) { |
| 1413 this.context_ = new ContextMirror(%GeneratorGetContext(this.value_)); |
| 1414 } |
| 1415 return this.context_; |
| 1416 }; |
| 1417 |
| 1418 |
| 1419 GeneratorMirror.prototype.receiver = function() { |
| 1420 if (!this.receiver_) { |
| 1421 this.receiver_ = MakeMirror(%GeneratorGetReceiver(this.value_)); |
| 1422 } |
| 1423 return this.receiver_; |
| 1424 }; |
| 1425 |
| 1426 |
| 1427 /** |
1355 * Base mirror object for properties. | 1428 * Base mirror object for properties. |
1356 * @param {ObjectMirror} mirror The mirror object having this property | 1429 * @param {ObjectMirror} mirror The mirror object having this property |
1357 * @param {string} name The name of the property | 1430 * @param {string} name The name of the property |
1358 * @param {Array} details Details about the property | 1431 * @param {Array} details Details about the property |
1359 * @constructor | 1432 * @constructor |
1360 * @extends Mirror | 1433 * @extends Mirror |
1361 */ | 1434 */ |
1362 function PropertyMirror(mirror, name, details) { | 1435 function PropertyMirror(mirror, name, details) { |
1363 %_CallFunction(this, PROPERTY_TYPE, Mirror); | 1436 %_CallFunction(this, PROPERTY_TYPE, Mirror); |
1364 this.mirror_ = mirror; | 1437 this.mirror_ = mirror; |
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2532 | 2605 |
2533 case SYMBOL_TYPE: | 2606 case SYMBOL_TYPE: |
2534 content.description = mirror.description(); | 2607 content.description = mirror.description(); |
2535 break; | 2608 break; |
2536 | 2609 |
2537 case OBJECT_TYPE: | 2610 case OBJECT_TYPE: |
2538 case FUNCTION_TYPE: | 2611 case FUNCTION_TYPE: |
2539 case ERROR_TYPE: | 2612 case ERROR_TYPE: |
2540 case REGEXP_TYPE: | 2613 case REGEXP_TYPE: |
2541 case PROMISE_TYPE: | 2614 case PROMISE_TYPE: |
| 2615 case GENERATOR_TYPE: |
2542 // Add object representation. | 2616 // Add object representation. |
2543 this.serializeObject_(mirror, content, details); | 2617 this.serializeObject_(mirror, content, details); |
2544 break; | 2618 break; |
2545 | 2619 |
2546 case PROPERTY_TYPE: | 2620 case PROPERTY_TYPE: |
2547 case INTERNAL_PROPERTY_TYPE: | 2621 case INTERNAL_PROPERTY_TYPE: |
2548 throw new Error('PropertyMirror cannot be serialized independently'); | 2622 throw new Error('PropertyMirror cannot be serialized independently'); |
2549 break; | 2623 break; |
2550 | 2624 |
2551 case FRAME_TYPE: | 2625 case FRAME_TYPE: |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2661 content.scopes = []; | 2735 content.scopes = []; |
2662 for (var i = 0; i < mirror.scopeCount(); i++) { | 2736 for (var i = 0; i < mirror.scopeCount(); i++) { |
2663 var scope = mirror.scope(i); | 2737 var scope = mirror.scope(i); |
2664 content.scopes.push({ | 2738 content.scopes.push({ |
2665 type: scope.scopeType(), | 2739 type: scope.scopeType(), |
2666 index: i | 2740 index: i |
2667 }); | 2741 }); |
2668 } | 2742 } |
2669 } | 2743 } |
2670 | 2744 |
| 2745 if (mirror.isGenerator()) { |
| 2746 // Add generator specific properties. |
| 2747 |
| 2748 // Either 'running', 'closed', or 'suspended'. |
| 2749 content.status = mirror.status(); |
| 2750 |
| 2751 content.func = this.serializeReference(mirror.func()) |
| 2752 content.receiver = this.serializeReference(mirror.receiver()) |
| 2753 |
| 2754 // If the generator is suspended, the content add line/column properties. |
| 2755 serializeLocationFields(mirror.sourceLocation(), content); |
| 2756 |
| 2757 // TODO(wingo): Also serialize a reference to the context (scope chain). |
| 2758 } |
| 2759 |
2671 if (mirror.isDate()) { | 2760 if (mirror.isDate()) { |
2672 // Add date specific properties. | 2761 // Add date specific properties. |
2673 content.value = mirror.value(); | 2762 content.value = mirror.value(); |
2674 } | 2763 } |
2675 | 2764 |
2676 if (mirror.isPromise()) { | 2765 if (mirror.isPromise()) { |
2677 // Add promise specific properties. | 2766 // Add promise specific properties. |
2678 content.status = mirror.status(); | 2767 content.status = mirror.status(); |
2679 content.promiseValue = this.serializeReference(mirror.promiseValue()); | 2768 content.promiseValue = this.serializeReference(mirror.promiseValue()); |
2680 } | 2769 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2877 } | 2966 } |
2878 if (!NUMBER_IS_FINITE(value)) { | 2967 if (!NUMBER_IS_FINITE(value)) { |
2879 if (value > 0) { | 2968 if (value > 0) { |
2880 return 'Infinity'; | 2969 return 'Infinity'; |
2881 } else { | 2970 } else { |
2882 return '-Infinity'; | 2971 return '-Infinity'; |
2883 } | 2972 } |
2884 } | 2973 } |
2885 return value; | 2974 return value; |
2886 } | 2975 } |
OLD | NEW |