| 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_ = []; |
| 11 | 11 |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Clear the mirror handle cache. | 14 * Clear the mirror handle cache. |
| 15 */ | 15 */ |
| 16 function ClearMirrorCache() { | 16 function ClearMirrorCache() { |
| 17 next_handle_ = 0; | 17 next_handle_ = 0; |
| 18 mirror_cache_ = []; | 18 mirror_cache_ = []; |
| 19 } | 19 } |
| 20 | 20 |
| 21 | 21 |
| 22 // Wrapper to check whether an object is a Promise. The call may not work | 22 // Wrapper to check whether an object is a Promise. The call may not work |
| 23 // if promises are not enabled. | 23 // if promises are not enabled. |
| 24 // TODO(yangguo): remove this wrapper once promises are enabled by default. | 24 // TODO(yangguo): remove try-catch once promises are enabled by default. |
| 25 function ObjectIsPromise(value) { | 25 function ObjectIsPromise(value) { |
| 26 try { | 26 try { |
| 27 return %IsPromise(value); | 27 return IS_SPEC_OBJECT(value) && |
| 28 !IS_UNDEFINED(%DebugGetProperty(value, builtins.promiseStatus)); |
| 28 } catch (e) { | 29 } catch (e) { |
| 29 return false; | 30 return false; |
| 30 } | 31 } |
| 31 } | 32 } |
| 32 | 33 |
| 33 | 34 |
| 34 /** | 35 /** |
| 35 * Returns the mirror for a specified value or object. | 36 * Returns the mirror for a specified value or object. |
| 36 * | 37 * |
| 37 * @param {value or Object} value the value or object to retreive the mirror for | 38 * @param {value or Object} value the value or object to retreive the mirror for |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 bindings[0])); | 818 bindings[0])); |
| 818 result.push(new InternalPropertyMirror("[[BoundThis]]", bindings[1])); | 819 result.push(new InternalPropertyMirror("[[BoundThis]]", bindings[1])); |
| 819 var boundArgs = []; | 820 var boundArgs = []; |
| 820 for (var i = 2; i < bindings.length; i++) { | 821 for (var i = 2; i < bindings.length; i++) { |
| 821 boundArgs.push(bindings[i]); | 822 boundArgs.push(bindings[i]); |
| 822 } | 823 } |
| 823 result.push(new InternalPropertyMirror("[[BoundArgs]]", boundArgs)); | 824 result.push(new InternalPropertyMirror("[[BoundArgs]]", boundArgs)); |
| 824 } | 825 } |
| 825 return result; | 826 return result; |
| 826 } else if (ObjectIsPromise(value)) { | 827 } else if (ObjectIsPromise(value)) { |
| 827 var mirror = new PromiseMirror(value); | 828 var result = []; |
| 828 var result = []; | 829 result.push(new InternalPropertyMirror("[[PromiseStatus]]", |
| 829 result.push(new InternalPropertyMirror("[[PromiseStatus]]", | 830 PromiseGetStatus_(value))); |
| 830 mirror.status())); | 831 result.push(new InternalPropertyMirror("[[PromiseValue]]", |
| 831 result.push(new InternalPropertyMirror("[[PromiseValue]]", | 832 PromiseGetValue_(value))); |
| 832 mirror.promiseValue())); | 833 return result; |
| 833 return result; | |
| 834 } | 834 } |
| 835 return []; | 835 return []; |
| 836 } | 836 } |
| 837 | 837 |
| 838 | 838 |
| 839 /** | 839 /** |
| 840 * Mirror object for functions. | 840 * Mirror object for functions. |
| 841 * @param {function} value The function object reflected by this mirror. | 841 * @param {function} value The function object reflected by this mirror. |
| 842 * @constructor | 842 * @constructor |
| 843 * @extends ObjectMirror | 843 * @extends ObjectMirror |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 * @param {Object} data The Promise object | 1187 * @param {Object} data The Promise object |
| 1188 * @constructor | 1188 * @constructor |
| 1189 * @extends Mirror | 1189 * @extends Mirror |
| 1190 */ | 1190 */ |
| 1191 function PromiseMirror(value) { | 1191 function PromiseMirror(value) { |
| 1192 %_CallFunction(this, value, PROMISE_TYPE, ObjectMirror); | 1192 %_CallFunction(this, value, PROMISE_TYPE, ObjectMirror); |
| 1193 } | 1193 } |
| 1194 inherits(PromiseMirror, ObjectMirror); | 1194 inherits(PromiseMirror, ObjectMirror); |
| 1195 | 1195 |
| 1196 | 1196 |
| 1197 PromiseMirror.prototype.status = function() { | 1197 function PromiseGetStatus_(value) { |
| 1198 var status = builtins.GetPromiseStatus(this.value_); | 1198 var status = %DebugGetProperty(value, builtins.promiseStatus); |
| 1199 if (status == 0) return "pending"; | 1199 if (status == 0) return "pending"; |
| 1200 if (status == 1) return "resolved"; | 1200 if (status == 1) return "resolved"; |
| 1201 return "rejected"; | 1201 return "rejected"; |
| 1202 } |
| 1203 |
| 1204 |
| 1205 function PromiseGetValue_(value) { |
| 1206 return %DebugGetProperty(value, builtins.promiseValue); |
| 1207 } |
| 1208 |
| 1209 |
| 1210 PromiseMirror.prototype.status = function() { |
| 1211 return PromiseGetStatus_(this.value_); |
| 1202 }; | 1212 }; |
| 1203 | 1213 |
| 1204 | 1214 |
| 1205 PromiseMirror.prototype.promiseValue = function() { | 1215 PromiseMirror.prototype.promiseValue = function() { |
| 1206 return builtins.GetPromiseValue(this.value_); | 1216 return MakeMirror(PromiseGetValue_(this.value_)); |
| 1207 }; | 1217 }; |
| 1208 | 1218 |
| 1209 | 1219 |
| 1210 /** | 1220 /** |
| 1211 * Base mirror object for properties. | 1221 * Base mirror object for properties. |
| 1212 * @param {ObjectMirror} mirror The mirror object having this property | 1222 * @param {ObjectMirror} mirror The mirror object having this property |
| 1213 * @param {string} name The name of the property | 1223 * @param {string} name The name of the property |
| 1214 * @param {Array} details Details about the property | 1224 * @param {Array} details Details about the property |
| 1215 * @constructor | 1225 * @constructor |
| 1216 * @extends Mirror | 1226 * @extends Mirror |
| (...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2517 } | 2527 } |
| 2518 | 2528 |
| 2519 if (mirror.isDate()) { | 2529 if (mirror.isDate()) { |
| 2520 // Add date specific properties. | 2530 // Add date specific properties. |
| 2521 content.value = mirror.value(); | 2531 content.value = mirror.value(); |
| 2522 } | 2532 } |
| 2523 | 2533 |
| 2524 if (mirror.isPromise()) { | 2534 if (mirror.isPromise()) { |
| 2525 // Add promise specific properties. | 2535 // Add promise specific properties. |
| 2526 content.status = mirror.status(); | 2536 content.status = mirror.status(); |
| 2527 content.promiseValue = mirror.promiseValue(); | 2537 content.promiseValue = this.serializeReference(mirror.promiseValue()); |
| 2528 } | 2538 } |
| 2529 | 2539 |
| 2530 // Add actual properties - named properties followed by indexed properties. | 2540 // Add actual properties - named properties followed by indexed properties. |
| 2531 var propertyNames = mirror.propertyNames(PropertyKind.Named); | 2541 var propertyNames = mirror.propertyNames(PropertyKind.Named); |
| 2532 var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); | 2542 var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); |
| 2533 var p = new Array(propertyNames.length + propertyIndexes.length); | 2543 var p = new Array(propertyNames.length + propertyIndexes.length); |
| 2534 for (var i = 0; i < propertyNames.length; i++) { | 2544 for (var i = 0; i < propertyNames.length; i++) { |
| 2535 var propertyMirror = mirror.property(propertyNames[i]); | 2545 var propertyMirror = mirror.property(propertyNames[i]); |
| 2536 p[i] = this.serializeProperty_(propertyMirror); | 2546 p[i] = this.serializeProperty_(propertyMirror); |
| 2537 if (details) { | 2547 if (details) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2725 } | 2735 } |
| 2726 if (!NUMBER_IS_FINITE(value)) { | 2736 if (!NUMBER_IS_FINITE(value)) { |
| 2727 if (value > 0) { | 2737 if (value > 0) { |
| 2728 return 'Infinity'; | 2738 return 'Infinity'; |
| 2729 } else { | 2739 } else { |
| 2730 return '-Infinity'; | 2740 return '-Infinity'; |
| 2731 } | 2741 } |
| 2732 } | 2742 } |
| 2733 return value; | 2743 return value; |
| 2734 } | 2744 } |
| OLD | NEW |