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); |
84 } else if (ObjectIsPromise(value)) { | 86 } else if (ObjectIsPromise(value)) { |
85 mirror = new PromiseMirror(value); | 87 mirror = new PromiseMirror(value); |
86 } else { | 88 } else { |
87 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); | 89 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); |
88 } | 90 } |
89 | 91 |
90 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror; | 92 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror; |
91 return mirror; | 93 return mirror; |
92 } | 94 } |
93 | 95 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 var FUNCTION_TYPE = 'function'; | 150 var FUNCTION_TYPE = 'function'; |
149 var REGEXP_TYPE = 'regexp'; | 151 var REGEXP_TYPE = 'regexp'; |
150 var ERROR_TYPE = 'error'; | 152 var ERROR_TYPE = 'error'; |
151 var PROPERTY_TYPE = 'property'; | 153 var PROPERTY_TYPE = 'property'; |
152 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; | 154 var INTERNAL_PROPERTY_TYPE = 'internalProperty'; |
153 var FRAME_TYPE = 'frame'; | 155 var FRAME_TYPE = 'frame'; |
154 var SCRIPT_TYPE = 'script'; | 156 var SCRIPT_TYPE = 'script'; |
155 var CONTEXT_TYPE = 'context'; | 157 var CONTEXT_TYPE = 'context'; |
156 var SCOPE_TYPE = 'scope'; | 158 var SCOPE_TYPE = 'scope'; |
157 var PROMISE_TYPE = 'promise'; | 159 var PROMISE_TYPE = 'promise'; |
| 160 var MAP_TYPE = 'map'; |
158 | 161 |
159 // Maximum length when sending strings through the JSON protocol. | 162 // Maximum length when sending strings through the JSON protocol. |
160 var kMaxProtocolStringLength = 80; | 163 var kMaxProtocolStringLength = 80; |
161 | 164 |
162 // Different kind of properties. | 165 // Different kind of properties. |
163 var PropertyKind = {}; | 166 var PropertyKind = {}; |
164 PropertyKind.Named = 1; | 167 PropertyKind.Named = 1; |
165 PropertyKind.Indexed = 2; | 168 PropertyKind.Indexed = 2; |
166 | 169 |
167 | 170 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // - StringMirror | 206 // - StringMirror |
204 // - SymbolMirror | 207 // - SymbolMirror |
205 // - ObjectMirror | 208 // - ObjectMirror |
206 // - FunctionMirror | 209 // - FunctionMirror |
207 // - UnresolvedFunctionMirror | 210 // - UnresolvedFunctionMirror |
208 // - ArrayMirror | 211 // - ArrayMirror |
209 // - DateMirror | 212 // - DateMirror |
210 // - RegExpMirror | 213 // - RegExpMirror |
211 // - ErrorMirror | 214 // - ErrorMirror |
212 // - PromiseMirror | 215 // - PromiseMirror |
| 216 // - MapMirror |
213 // - PropertyMirror | 217 // - PropertyMirror |
214 // - InternalPropertyMirror | 218 // - InternalPropertyMirror |
215 // - FrameMirror | 219 // - FrameMirror |
216 // - ScriptMirror | 220 // - ScriptMirror |
217 | 221 |
218 | 222 |
219 /** | 223 /** |
220 * Base class for all mirror objects. | 224 * Base class for all mirror objects. |
221 * @param {string} type The type of the mirror | 225 * @param {string} type The type of the mirror |
222 * @constructor | 226 * @constructor |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 /** | 418 /** |
415 * Check whether the mirror reflects a scope. | 419 * Check whether the mirror reflects a scope. |
416 * @returns {boolean} True if the mirror reflects a scope | 420 * @returns {boolean} True if the mirror reflects a scope |
417 */ | 421 */ |
418 Mirror.prototype.isScope = function() { | 422 Mirror.prototype.isScope = function() { |
419 return this instanceof ScopeMirror; | 423 return this instanceof ScopeMirror; |
420 }; | 424 }; |
421 | 425 |
422 | 426 |
423 /** | 427 /** |
| 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 /** |
424 * Allocate a handle id for this object. | 437 * Allocate a handle id for this object. |
425 */ | 438 */ |
426 Mirror.prototype.allocateHandle_ = function() { | 439 Mirror.prototype.allocateHandle_ = function() { |
427 if (mirror_cache_enabled_) this.handle_ = next_handle_++; | 440 if (mirror_cache_enabled_) this.handle_ = next_handle_++; |
428 }; | 441 }; |
429 | 442 |
430 | 443 |
431 /** | 444 /** |
432 * Allocate a transient handle id for this object. Transient handles are | 445 * Allocate a transient handle id for this object. Transient handles are |
433 * negative. | 446 * negative. |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 PromiseMirror.prototype.status = function() { | 1259 PromiseMirror.prototype.status = function() { |
1247 return PromiseGetStatus_(this.value_); | 1260 return PromiseGetStatus_(this.value_); |
1248 }; | 1261 }; |
1249 | 1262 |
1250 | 1263 |
1251 PromiseMirror.prototype.promiseValue = function() { | 1264 PromiseMirror.prototype.promiseValue = function() { |
1252 return MakeMirror(PromiseGetValue_(this.value_)); | 1265 return MakeMirror(PromiseGetValue_(this.value_)); |
1253 }; | 1266 }; |
1254 | 1267 |
1255 | 1268 |
| 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 |
1256 /** | 1307 /** |
1257 * Base mirror object for properties. | 1308 * Base mirror object for properties. |
1258 * @param {ObjectMirror} mirror The mirror object having this property | 1309 * @param {ObjectMirror} mirror The mirror object having this property |
1259 * @param {string} name The name of the property | 1310 * @param {string} name The name of the property |
1260 * @param {Array} details Details about the property | 1311 * @param {Array} details Details about the property |
1261 * @constructor | 1312 * @constructor |
1262 * @extends Mirror | 1313 * @extends Mirror |
1263 */ | 1314 */ |
1264 function PropertyMirror(mirror, name, details) { | 1315 function PropertyMirror(mirror, name, details) { |
1265 %_CallFunction(this, PROPERTY_TYPE, Mirror); | 1316 %_CallFunction(this, PROPERTY_TYPE, Mirror); |
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2778 } | 2829 } |
2779 if (!NUMBER_IS_FINITE(value)) { | 2830 if (!NUMBER_IS_FINITE(value)) { |
2780 if (value > 0) { | 2831 if (value > 0) { |
2781 return 'Infinity'; | 2832 return 'Infinity'; |
2782 } else { | 2833 } else { |
2783 return '-Infinity'; | 2834 return '-Infinity'; |
2784 } | 2835 } |
2785 } | 2836 } |
2786 return value; | 2837 return value; |
2787 } | 2838 } |
OLD | NEW |