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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } else if (IS_DATE(value)) { | 74 } else if (IS_DATE(value)) { |
75 mirror = new DateMirror(value); | 75 mirror = new DateMirror(value); |
76 } else if (IS_FUNCTION(value)) { | 76 } else if (IS_FUNCTION(value)) { |
77 mirror = new FunctionMirror(value); | 77 mirror = new FunctionMirror(value); |
78 } else if (IS_REGEXP(value)) { | 78 } else if (IS_REGEXP(value)) { |
79 mirror = new RegExpMirror(value); | 79 mirror = new RegExpMirror(value); |
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)) { | |
85 mirror = new MapMirror(value); | |
86 } else if (ObjectIsPromise(value)) { | 84 } else if (ObjectIsPromise(value)) { |
87 mirror = new PromiseMirror(value); | 85 mirror = new PromiseMirror(value); |
88 } else { | 86 } else { |
89 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); | 87 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); |
90 } | 88 } |
91 | 89 |
92 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror; | 90 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror; |
93 return mirror; | 91 return mirror; |
94 } | 92 } |
95 | 93 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 var FUNCTION_TYPE = 'function'; | 148 var FUNCTION_TYPE = 'function'; |
151 var REGEXP_TYPE = 'regexp'; | 149 var REGEXP_TYPE = 'regexp'; |
152 var ERROR_TYPE = 'error'; | 150 var ERROR_TYPE = 'error'; |
153 var PROPERTY_TYPE = 'property'; | 151 var PROPERTY_TYPE = 'property'; |
154 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; | 152 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; |
155 var FRAME_TYPE = 'frame'; | 153 var FRAME_TYPE = 'frame'; |
156 var SCRIPT_TYPE = 'script'; | 154 var SCRIPT_TYPE = 'script'; |
157 var CONTEXT_TYPE = 'context'; | 155 var CONTEXT_TYPE = 'context'; |
158 var SCOPE_TYPE = 'scope'; | 156 var SCOPE_TYPE = 'scope'; |
159 var PROMISE_TYPE = 'promise'; | 157 var PROMISE_TYPE = 'promise'; |
160 var MAP_TYPE = 'map'; | |
161 | 158 |
162 // Maximum length when sending strings through the JSON protocol. | 159 // Maximum length when sending strings through the JSON protocol. |
163 var kMaxProtocolStringLength = 80; | 160 var kMaxProtocolStringLength = 80; |
164 | 161 |
165 // Different kind of properties. | 162 // Different kind of properties. |
166 var PropertyKind = {}; | 163 var PropertyKind = {}; |
167 PropertyKind.Named = 1; | 164 PropertyKind.Named = 1; |
168 PropertyKind.Indexed = 2; | 165 PropertyKind.Indexed = 2; |
169 | 166 |
170 | 167 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // - StringMirror | 203 // - StringMirror |
207 // - SymbolMirror | 204 // - SymbolMirror |
208 // - ObjectMirror | 205 // - ObjectMirror |
209 // - FunctionMirror | 206 // - FunctionMirror |
210 // - UnresolvedFunctionMirror | 207 // - UnresolvedFunctionMirror |
211 // - ArrayMirror | 208 // - ArrayMirror |
212 // - DateMirror | 209 // - DateMirror |
213 // - RegExpMirror | 210 // - RegExpMirror |
214 // - ErrorMirror | 211 // - ErrorMirror |
215 // - PromiseMirror | 212 // - PromiseMirror |
216 // - MapMirror | |
217 // - PropertyMirror | 213 // - PropertyMirror |
218 // - InternalPropertyMirror | 214 // - InternalPropertyMirror |
219 // - FrameMirror | 215 // - FrameMirror |
220 // - ScriptMirror | 216 // - ScriptMirror |
221 | 217 |
222 | 218 |
223 /** | 219 /** |
224 * Base class for all mirror objects. | 220 * Base class for all mirror objects. |
225 * @param {string} type The type of the mirror | 221 * @param {string} type The type of the mirror |
226 * @constructor | 222 * @constructor |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 /** | 414 /** |
419 * Check whether the mirror reflects a scope. | 415 * Check whether the mirror reflects a scope. |
420 * @returns {boolean} True if the mirror reflects a scope | 416 * @returns {boolean} True if the mirror reflects a scope |
421 */ | 417 */ |
422 Mirror.prototype.isScope = function() { | 418 Mirror.prototype.isScope = function() { |
423 return this instanceof ScopeMirror; | 419 return this instanceof ScopeMirror; |
424 }; | 420 }; |
425 | 421 |
426 | 422 |
427 /** | 423 /** |
428 * Check whether the mirror reflects a map. | |
429 * @returns {boolean} True if the mirror reflects a map | |
430 */ | |
431 Mirror.prototype.isMap = function() { | |
432 return this instanceof MapMirror; | |
433 }; | |
434 | |
435 | |
436 /** | |
437 * Allocate a handle id for this object. | 424 * Allocate a handle id for this object. |
438 */ | 425 */ |
439 Mirror.prototype.allocateHandle_ = function() { | 426 Mirror.prototype.allocateHandle_ = function() { |
440 if (mirror_cache_enabled_) this.handle_ = next_handle_++; | 427 if (mirror_cache_enabled_) this.handle_ = next_handle_++; |
441 }; | 428 }; |
442 | 429 |
443 | 430 |
444 /** | 431 /** |
445 * Allocate a transient handle id for this object. Transient handles are | 432 * Allocate a transient handle id for this object. Transient handles are |
446 * negative. | 433 * negative. |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 PromiseMirror.prototype.status = function() { | 1246 PromiseMirror.prototype.status = function() { |
1260 return PromiseGetStatus_(this.value_); | 1247 return PromiseGetStatus_(this.value_); |
1261 }; | 1248 }; |
1262 | 1249 |
1263 | 1250 |
1264 PromiseMirror.prototype.promiseValue = function() { | 1251 PromiseMirror.prototype.promiseValue = function() { |
1265 return MakeMirror(PromiseGetValue_(this.value_)); | 1252 return MakeMirror(PromiseGetValue_(this.value_)); |
1266 }; | 1253 }; |
1267 | 1254 |
1268 | 1255 |
1269 function MapMirror(value) { | |
1270 %_CallFunction(this, value, MAP_TYPE, ObjectMirror); | |
1271 } | |
1272 inherits(MapMirror, ObjectMirror); | |
1273 | |
1274 | |
1275 /** | |
1276 * Returns an array of key/value pairs of a map. | |
1277 * This will keep keys alive for WeakMaps. | |
1278 * | |
1279 * @returns {Array.<Object>} Array of key/value pairs of a map. | |
1280 */ | |
1281 MapMirror.prototype.entries = function() { | |
1282 var result = []; | |
1283 | |
1284 if (IS_WEAKMAP(this.value_)) { | |
1285 var entries = %GetWeakMapEntries(this.value_); | |
1286 for (var i = 0; i < entries.length; i += 2) { | |
1287 result.push({ | |
1288 key: entries[i], | |
1289 value: entries[i + 1] | |
1290 }); | |
1291 } | |
1292 return result; | |
1293 } | |
1294 | |
1295 var iter = %_CallFunction(this.value_, builtins.MapEntries); | |
1296 var next; | |
1297 while (!(next = iter.next()).done) { | |
1298 result.push({ | |
1299 key: next.value[0], | |
1300 value: next.value[1] | |
1301 }); | |
1302 } | |
1303 return result; | |
1304 }; | |
1305 | |
1306 | |
1307 /** | 1256 /** |
1308 * Base mirror object for properties. | 1257 * Base mirror object for properties. |
1309 * @param {ObjectMirror} mirror The mirror object having this property | 1258 * @param {ObjectMirror} mirror The mirror object having this property |
1310 * @param {string} name The name of the property | 1259 * @param {string} name The name of the property |
1311 * @param {Array} details Details about the property | 1260 * @param {Array} details Details about the property |
1312 * @constructor | 1261 * @constructor |
1313 * @extends Mirror | 1262 * @extends Mirror |
1314 */ | 1263 */ |
1315 function PropertyMirror(mirror, name, details) { | 1264 function PropertyMirror(mirror, name, details) { |
1316 %_CallFunction(this, PROPERTY_TYPE, Mirror); | 1265 %_CallFunction(this, PROPERTY_TYPE, Mirror); |
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2829 } | 2778 } |
2830 if (!NUMBER_IS_FINITE(value)) { | 2779 if (!NUMBER_IS_FINITE(value)) { |
2831 if (value > 0) { | 2780 if (value > 0) { |
2832 return 'Infinity'; | 2781 return 'Infinity'; |
2833 } else { | 2782 } else { |
2834 return '-Infinity'; | 2783 return '-Infinity'; |
2835 } | 2784 } |
2836 } | 2785 } |
2837 return value; | 2786 return value; |
2838 } | 2787 } |
OLD | NEW |