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 // 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 24 matching lines...) Expand all Loading... |
35 | 35 |
36 /** | 36 /** |
37 * Clear the mirror handle cache. | 37 * Clear the mirror handle cache. |
38 */ | 38 */ |
39 function ClearMirrorCache() { | 39 function ClearMirrorCache() { |
40 next_handle_ = 0; | 40 next_handle_ = 0; |
41 mirror_cache_ = []; | 41 mirror_cache_ = []; |
42 } | 42 } |
43 | 43 |
44 | 44 |
| 45 // Wrapper to check whether an object is a Promise. The call may not work |
| 46 // if promises are not enabled. |
| 47 // TODO(yangguo): remove this wrapper once promises are enabled by default. |
| 48 function ObjectIsPromise(value) { |
| 49 try { |
| 50 return %IsPromise(value); |
| 51 } catch (e) { |
| 52 return false; |
| 53 } |
| 54 } |
| 55 |
| 56 |
45 /** | 57 /** |
46 * Returns the mirror for a specified value or object. | 58 * Returns the mirror for a specified value or object. |
47 * | 59 * |
48 * @param {value or Object} value the value or object to retreive the mirror for | 60 * @param {value or Object} value the value or object to retreive the mirror for |
49 * @param {boolean} transient indicate whether this object is transient and | 61 * @param {boolean} transient indicate whether this object is transient and |
50 * should not be added to the mirror cache. The default is not transient. | 62 * should not be added to the mirror cache. The default is not transient. |
51 * @returns {Mirror} the mirror reflects the passed value or object | 63 * @returns {Mirror} the mirror reflects the passed value or object |
52 */ | 64 */ |
53 function MakeMirror(value, opt_transient) { | 65 function MakeMirror(value, opt_transient) { |
54 var mirror; | 66 var mirror; |
(...skipping 28 matching lines...) Expand all Loading... |
83 } else if (IS_DATE(value)) { | 95 } else if (IS_DATE(value)) { |
84 mirror = new DateMirror(value); | 96 mirror = new DateMirror(value); |
85 } else if (IS_FUNCTION(value)) { | 97 } else if (IS_FUNCTION(value)) { |
86 mirror = new FunctionMirror(value); | 98 mirror = new FunctionMirror(value); |
87 } else if (IS_REGEXP(value)) { | 99 } else if (IS_REGEXP(value)) { |
88 mirror = new RegExpMirror(value); | 100 mirror = new RegExpMirror(value); |
89 } else if (IS_ERROR(value)) { | 101 } else if (IS_ERROR(value)) { |
90 mirror = new ErrorMirror(value); | 102 mirror = new ErrorMirror(value); |
91 } else if (IS_SCRIPT(value)) { | 103 } else if (IS_SCRIPT(value)) { |
92 mirror = new ScriptMirror(value); | 104 mirror = new ScriptMirror(value); |
| 105 } else if (ObjectIsPromise(value)) { |
| 106 mirror = new PromiseMirror(value); |
93 } else { | 107 } else { |
94 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); | 108 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); |
95 } | 109 } |
96 | 110 |
97 mirror_cache_[mirror.handle()] = mirror; | 111 mirror_cache_[mirror.handle()] = mirror; |
98 return mirror; | 112 return mirror; |
99 } | 113 } |
100 | 114 |
101 | 115 |
102 /** | 116 /** |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 var OBJECT_TYPE = 'object'; | 166 var OBJECT_TYPE = 'object'; |
153 var FUNCTION_TYPE = 'function'; | 167 var FUNCTION_TYPE = 'function'; |
154 var REGEXP_TYPE = 'regexp'; | 168 var REGEXP_TYPE = 'regexp'; |
155 var ERROR_TYPE = 'error'; | 169 var ERROR_TYPE = 'error'; |
156 var PROPERTY_TYPE = 'property'; | 170 var PROPERTY_TYPE = 'property'; |
157 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; | 171 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; |
158 var FRAME_TYPE = 'frame'; | 172 var FRAME_TYPE = 'frame'; |
159 var SCRIPT_TYPE = 'script'; | 173 var SCRIPT_TYPE = 'script'; |
160 var CONTEXT_TYPE = 'context'; | 174 var CONTEXT_TYPE = 'context'; |
161 var SCOPE_TYPE = 'scope'; | 175 var SCOPE_TYPE = 'scope'; |
| 176 var PROMISE_TYPE = 'promise'; |
162 | 177 |
163 // Maximum length when sending strings through the JSON protocol. | 178 // Maximum length when sending strings through the JSON protocol. |
164 var kMaxProtocolStringLength = 80; | 179 var kMaxProtocolStringLength = 80; |
165 | 180 |
166 // Different kind of properties. | 181 // Different kind of properties. |
167 var PropertyKind = {}; | 182 var PropertyKind = {}; |
168 PropertyKind.Named = 1; | 183 PropertyKind.Named = 1; |
169 PropertyKind.Indexed = 2; | 184 PropertyKind.Indexed = 2; |
170 | 185 |
171 | 186 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // - NullMirror | 220 // - NullMirror |
206 // - NumberMirror | 221 // - NumberMirror |
207 // - StringMirror | 222 // - StringMirror |
208 // - ObjectMirror | 223 // - ObjectMirror |
209 // - FunctionMirror | 224 // - FunctionMirror |
210 // - UnresolvedFunctionMirror | 225 // - UnresolvedFunctionMirror |
211 // - ArrayMirror | 226 // - ArrayMirror |
212 // - DateMirror | 227 // - DateMirror |
213 // - RegExpMirror | 228 // - RegExpMirror |
214 // - ErrorMirror | 229 // - ErrorMirror |
| 230 // - PromiseMirror |
215 // - PropertyMirror | 231 // - PropertyMirror |
216 // - InternalPropertyMirror | 232 // - InternalPropertyMirror |
217 // - FrameMirror | 233 // - FrameMirror |
218 // - ScriptMirror | 234 // - ScriptMirror |
219 | 235 |
220 | 236 |
221 /** | 237 /** |
222 * Base class for all mirror objects. | 238 * Base class for all mirror objects. |
223 * @param {string} type The type of the mirror | 239 * @param {string} type The type of the mirror |
224 * @constructor | 240 * @constructor |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 /** | 360 /** |
345 * Check whether the mirror reflects an error. | 361 * Check whether the mirror reflects an error. |
346 * @returns {boolean} True if the mirror reflects an error | 362 * @returns {boolean} True if the mirror reflects an error |
347 */ | 363 */ |
348 Mirror.prototype.isError = function() { | 364 Mirror.prototype.isError = function() { |
349 return this instanceof ErrorMirror; | 365 return this instanceof ErrorMirror; |
350 }; | 366 }; |
351 | 367 |
352 | 368 |
353 /** | 369 /** |
| 370 * Check whether the mirror reflects a promise. |
| 371 * @returns {boolean} True if the mirror reflects a promise |
| 372 */ |
| 373 Mirror.prototype.isPromise = function() { |
| 374 return this instanceof PromiseMirror; |
| 375 }; |
| 376 |
| 377 |
| 378 /** |
354 * Check whether the mirror reflects a property. | 379 * Check whether the mirror reflects a property. |
355 * @returns {boolean} True if the mirror reflects a property | 380 * @returns {boolean} True if the mirror reflects a property |
356 */ | 381 */ |
357 Mirror.prototype.isProperty = function() { | 382 Mirror.prototype.isProperty = function() { |
358 return this instanceof PropertyMirror; | 383 return this instanceof PropertyMirror; |
359 }; | 384 }; |
360 | 385 |
361 | 386 |
362 /** | 387 /** |
363 * Check whether the mirror reflects an internal property. | 388 * Check whether the mirror reflects an internal property. |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 ObjectMirror.prototype.propertyNames = function(kind, limit) { | 655 ObjectMirror.prototype.propertyNames = function(kind, limit) { |
631 // Find kind and limit and allocate array for the result | 656 // Find kind and limit and allocate array for the result |
632 kind = kind || PropertyKind.Named | PropertyKind.Indexed; | 657 kind = kind || PropertyKind.Named | PropertyKind.Indexed; |
633 | 658 |
634 var propertyNames; | 659 var propertyNames; |
635 var elementNames; | 660 var elementNames; |
636 var total = 0; | 661 var total = 0; |
637 | 662 |
638 // Find all the named properties. | 663 // Find all the named properties. |
639 if (kind & PropertyKind.Named) { | 664 if (kind & PropertyKind.Named) { |
640 // Get all the local property names. | 665 // Get all the local property names except for private symbols. |
641 propertyNames = | 666 propertyNames = |
642 %GetLocalPropertyNames(this.value_, PROPERTY_ATTRIBUTES_NONE); | 667 %GetLocalPropertyNames(this.value_, PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL); |
643 total += propertyNames.length; | 668 total += propertyNames.length; |
644 | 669 |
645 // Get names for named interceptor properties if any. | 670 // Get names for named interceptor properties if any. |
646 if (this.hasNamedInterceptor() && (kind & PropertyKind.Named)) { | 671 if (this.hasNamedInterceptor() && (kind & PropertyKind.Named)) { |
647 var namedInterceptorNames = | 672 var namedInterceptorNames = |
648 %GetNamedInterceptorPropertyNames(this.value_); | 673 %GetNamedInterceptorPropertyNames(this.value_); |
649 if (namedInterceptorNames) { | 674 if (namedInterceptorNames) { |
650 propertyNames = propertyNames.concat(namedInterceptorNames); | 675 propertyNames = propertyNames.concat(namedInterceptorNames); |
651 total += namedInterceptorNames.length; | 676 total += namedInterceptorNames.length; |
652 } | 677 } |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 try { | 1190 try { |
1166 str = %_CallFunction(this.value_, builtins.ErrorToString); | 1191 str = %_CallFunction(this.value_, builtins.ErrorToString); |
1167 } catch (e) { | 1192 } catch (e) { |
1168 str = '#<Error>'; | 1193 str = '#<Error>'; |
1169 } | 1194 } |
1170 return str; | 1195 return str; |
1171 }; | 1196 }; |
1172 | 1197 |
1173 | 1198 |
1174 /** | 1199 /** |
| 1200 * Mirror object for a Promise object. |
| 1201 * @param {Object} data The Promise object |
| 1202 * @constructor |
| 1203 * @extends Mirror |
| 1204 */ |
| 1205 function PromiseMirror(value) { |
| 1206 %_CallFunction(this, value, PROMISE_TYPE, ObjectMirror); |
| 1207 } |
| 1208 inherits(PromiseMirror, ObjectMirror); |
| 1209 |
| 1210 |
| 1211 PromiseMirror.prototype.status = function() { |
| 1212 var status = %GetPromiseStatus(this.value_); |
| 1213 if (status == 0) return "pending"; |
| 1214 if (status == 1) return "resolved"; |
| 1215 return "rejected"; |
| 1216 }; |
| 1217 |
| 1218 |
| 1219 /** |
1175 * Base mirror object for properties. | 1220 * Base mirror object for properties. |
1176 * @param {ObjectMirror} mirror The mirror object having this property | 1221 * @param {ObjectMirror} mirror The mirror object having this property |
1177 * @param {string} name The name of the property | 1222 * @param {string} name The name of the property |
1178 * @param {Array} details Details about the property | 1223 * @param {Array} details Details about the property |
1179 * @constructor | 1224 * @constructor |
1180 * @extends Mirror | 1225 * @extends Mirror |
1181 */ | 1226 */ |
1182 function PropertyMirror(mirror, name, details) { | 1227 function PropertyMirror(mirror, name, details) { |
1183 %_CallFunction(this, PROPERTY_TYPE, Mirror); | 1228 %_CallFunction(this, PROPERTY_TYPE, Mirror); |
1184 this.mirror_ = mirror; | 1229 this.mirror_ = mirror; |
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2343 } else { | 2388 } else { |
2344 content.value = mirror.value(); | 2389 content.value = mirror.value(); |
2345 } | 2390 } |
2346 content.length = mirror.length(); | 2391 content.length = mirror.length(); |
2347 break; | 2392 break; |
2348 | 2393 |
2349 case OBJECT_TYPE: | 2394 case OBJECT_TYPE: |
2350 case FUNCTION_TYPE: | 2395 case FUNCTION_TYPE: |
2351 case ERROR_TYPE: | 2396 case ERROR_TYPE: |
2352 case REGEXP_TYPE: | 2397 case REGEXP_TYPE: |
| 2398 case PROMISE_TYPE: |
2353 // Add object representation. | 2399 // Add object representation. |
2354 this.serializeObject_(mirror, content, details); | 2400 this.serializeObject_(mirror, content, details); |
2355 break; | 2401 break; |
2356 | 2402 |
2357 case PROPERTY_TYPE: | 2403 case PROPERTY_TYPE: |
2358 case INTERNAL_PROPERTY_TYPE: | 2404 case INTERNAL_PROPERTY_TYPE: |
2359 throw new Error('PropertyMirror cannot be serialized independently'); | 2405 throw new Error('PropertyMirror cannot be serialized independently'); |
2360 break; | 2406 break; |
2361 | 2407 |
2362 case FRAME_TYPE: | 2408 case FRAME_TYPE: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2445 content.prototypeObject = this.serializeReference(mirror.prototypeObject()); | 2491 content.prototypeObject = this.serializeReference(mirror.prototypeObject()); |
2446 | 2492 |
2447 // Add flags to indicate whether there are interceptors. | 2493 // Add flags to indicate whether there are interceptors. |
2448 if (mirror.hasNamedInterceptor()) { | 2494 if (mirror.hasNamedInterceptor()) { |
2449 content.namedInterceptor = true; | 2495 content.namedInterceptor = true; |
2450 } | 2496 } |
2451 if (mirror.hasIndexedInterceptor()) { | 2497 if (mirror.hasIndexedInterceptor()) { |
2452 content.indexedInterceptor = true; | 2498 content.indexedInterceptor = true; |
2453 } | 2499 } |
2454 | 2500 |
2455 // Add function specific properties. | |
2456 if (mirror.isFunction()) { | 2501 if (mirror.isFunction()) { |
2457 // Add function specific properties. | 2502 // Add function specific properties. |
2458 content.name = mirror.name(); | 2503 content.name = mirror.name(); |
2459 if (!IS_UNDEFINED(mirror.inferredName())) { | 2504 if (!IS_UNDEFINED(mirror.inferredName())) { |
2460 content.inferredName = mirror.inferredName(); | 2505 content.inferredName = mirror.inferredName(); |
2461 } | 2506 } |
2462 content.resolved = mirror.resolved(); | 2507 content.resolved = mirror.resolved(); |
2463 if (mirror.resolved()) { | 2508 if (mirror.resolved()) { |
2464 content.source = mirror.source(); | 2509 content.source = mirror.source(); |
2465 } | 2510 } |
2466 if (mirror.script()) { | 2511 if (mirror.script()) { |
2467 content.script = this.serializeReference(mirror.script()); | 2512 content.script = this.serializeReference(mirror.script()); |
2468 content.scriptId = mirror.script().id(); | 2513 content.scriptId = mirror.script().id(); |
2469 | 2514 |
2470 serializeLocationFields(mirror.sourceLocation(), content); | 2515 serializeLocationFields(mirror.sourceLocation(), content); |
2471 } | 2516 } |
2472 | 2517 |
2473 content.scopes = []; | 2518 content.scopes = []; |
2474 for (var i = 0; i < mirror.scopeCount(); i++) { | 2519 for (var i = 0; i < mirror.scopeCount(); i++) { |
2475 var scope = mirror.scope(i); | 2520 var scope = mirror.scope(i); |
2476 content.scopes.push({ | 2521 content.scopes.push({ |
2477 type: scope.scopeType(), | 2522 type: scope.scopeType(), |
2478 index: i | 2523 index: i |
2479 }); | 2524 }); |
2480 } | 2525 } |
2481 } | 2526 } |
2482 | 2527 |
2483 // Add date specific properties. | |
2484 if (mirror.isDate()) { | 2528 if (mirror.isDate()) { |
2485 // Add date specific properties. | 2529 // Add date specific properties. |
2486 content.value = mirror.value(); | 2530 content.value = mirror.value(); |
2487 } | 2531 } |
2488 | 2532 |
| 2533 if (mirror.isPromise()) { |
| 2534 // Add promise specific properties. |
| 2535 content.status = mirror.status(); |
| 2536 } |
| 2537 |
2489 // Add actual properties - named properties followed by indexed properties. | 2538 // Add actual properties - named properties followed by indexed properties. |
2490 var propertyNames = mirror.propertyNames(PropertyKind.Named); | 2539 var propertyNames = mirror.propertyNames(PropertyKind.Named); |
2491 var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); | 2540 var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); |
2492 var p = new Array(propertyNames.length + propertyIndexes.length); | 2541 var p = new Array(propertyNames.length + propertyIndexes.length); |
2493 for (var i = 0; i < propertyNames.length; i++) { | 2542 for (var i = 0; i < propertyNames.length; i++) { |
2494 var propertyMirror = mirror.property(propertyNames[i]); | 2543 var propertyMirror = mirror.property(propertyNames[i]); |
2495 p[i] = this.serializeProperty_(propertyMirror); | 2544 p[i] = this.serializeProperty_(propertyMirror); |
2496 if (details) { | 2545 if (details) { |
2497 this.add_(propertyMirror.value()); | 2546 this.add_(propertyMirror.value()); |
2498 } | 2547 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2684 } | 2733 } |
2685 if (!NUMBER_IS_FINITE(value)) { | 2734 if (!NUMBER_IS_FINITE(value)) { |
2686 if (value > 0) { | 2735 if (value > 0) { |
2687 return 'Infinity'; | 2736 return 'Infinity'; |
2688 } else { | 2737 } else { |
2689 return '-Infinity'; | 2738 return '-Infinity'; |
2690 } | 2739 } |
2691 } | 2740 } |
2692 return value; | 2741 return value; |
2693 } | 2742 } |
OLD | NEW |