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 var mirror_cache_enabled_ = true; | |
12 | |
13 | |
14 function ToggleMirrorCache(value) { | |
15 mirror_cache_enabled_ = value; | |
16 next_handle_ = 0; | |
17 mirror_cache_ = []; | |
18 } | |
11 | 19 |
12 | 20 |
13 /** | 21 /** |
14 * Clear the mirror handle cache. | 22 * Clear the mirror handle cache. |
15 */ | 23 */ |
16 function ClearMirrorCache() { | 24 function ClearMirrorCache() { |
17 next_handle_ = 0; | 25 next_handle_ = 0; |
18 mirror_cache_ = []; | 26 mirror_cache_ = []; |
19 } | 27 } |
20 | 28 |
(...skipping 16 matching lines...) Expand all Loading... | |
37 * | 45 * |
38 * @param {value or Object} value the value or object to retreive the mirror for | 46 * @param {value or Object} value the value or object to retreive the mirror for |
39 * @param {boolean} transient indicate whether this object is transient and | 47 * @param {boolean} transient indicate whether this object is transient and |
40 * should not be added to the mirror cache. The default is not transient. | 48 * should not be added to the mirror cache. The default is not transient. |
41 * @returns {Mirror} the mirror reflects the passed value or object | 49 * @returns {Mirror} the mirror reflects the passed value or object |
42 */ | 50 */ |
43 function MakeMirror(value, opt_transient) { | 51 function MakeMirror(value, opt_transient) { |
44 var mirror; | 52 var mirror; |
45 | 53 |
46 // Look for non transient mirrors in the mirror cache. | 54 // Look for non transient mirrors in the mirror cache. |
47 if (!opt_transient) { | 55 if (!opt_transient && mirror_cache_enabled_) { |
48 for (id in mirror_cache_) { | 56 for (id in mirror_cache_) { |
49 mirror = mirror_cache_[id]; | 57 mirror = mirror_cache_[id]; |
50 if (mirror.value() === value) { | 58 if (mirror.value() === value) { |
51 return mirror; | 59 return mirror; |
52 } | 60 } |
53 // Special check for NaN as NaN == NaN is false. | 61 // Special check for NaN as NaN == NaN is false. |
54 if (mirror.isNumber() && isNaN(mirror.value()) && | 62 if (mirror.isNumber() && isNaN(mirror.value()) && |
55 typeof value == 'number' && isNaN(value)) { | 63 typeof value == 'number' && isNaN(value)) { |
56 return mirror; | 64 return mirror; |
57 } | 65 } |
(...skipping 23 matching lines...) Expand all Loading... | |
81 } else if (IS_ERROR(value)) { | 89 } else if (IS_ERROR(value)) { |
82 mirror = new ErrorMirror(value); | 90 mirror = new ErrorMirror(value); |
83 } else if (IS_SCRIPT(value)) { | 91 } else if (IS_SCRIPT(value)) { |
84 mirror = new ScriptMirror(value); | 92 mirror = new ScriptMirror(value); |
85 } else if (ObjectIsPromise(value)) { | 93 } else if (ObjectIsPromise(value)) { |
86 mirror = new PromiseMirror(value); | 94 mirror = new PromiseMirror(value); |
87 } else { | 95 } else { |
88 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); | 96 mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); |
89 } | 97 } |
90 | 98 |
91 mirror_cache_[mirror.handle()] = mirror; | 99 if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror; |
92 return mirror; | 100 return mirror; |
93 } | 101 } |
94 | 102 |
95 | 103 |
96 /** | 104 /** |
97 * Returns the mirror for a specified mirror handle. | 105 * Returns the mirror for a specified mirror handle. |
98 * | 106 * |
99 * @param {number} handle the handle to find the mirror for | 107 * @param {number} handle the handle to find the mirror for |
100 * @returns {Mirror or undefiend} the mirror with the requested handle or | 108 * @returns {Mirror or undefiend} the mirror with the requested handle or |
101 * undefined if no mirror with the requested handle was found | 109 * undefined if no mirror with the requested handle was found |
102 */ | 110 */ |
103 function LookupMirror(handle) { | 111 function LookupMirror(handle) { |
104 return mirror_cache_[handle]; | 112 return mirror_cache_enabled_ ? mirror_cache_[handle] : UNDEFINED; |
yurys
2014/06/03 13:27:18
I'd rather we threw an exception if mirror cache i
Yang
2014/06/03 14:22:05
Done.
| |
105 } | 113 } |
106 | 114 |
107 | 115 |
108 /** | 116 /** |
109 * Returns the mirror for the undefined value. | 117 * Returns the mirror for the undefined value. |
110 * | 118 * |
111 * @returns {Mirror} the mirror reflects the undefined value | 119 * @returns {Mirror} the mirror reflects the undefined value |
112 */ | 120 */ |
113 function GetUndefinedMirror() { | 121 function GetUndefinedMirror() { |
114 return MakeMirror(UNDEFINED); | 122 return MakeMirror(UNDEFINED); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 */ | 425 */ |
418 Mirror.prototype.isScope = function() { | 426 Mirror.prototype.isScope = function() { |
419 return this instanceof ScopeMirror; | 427 return this instanceof ScopeMirror; |
420 }; | 428 }; |
421 | 429 |
422 | 430 |
423 /** | 431 /** |
424 * Allocate a handle id for this object. | 432 * Allocate a handle id for this object. |
425 */ | 433 */ |
426 Mirror.prototype.allocateHandle_ = function() { | 434 Mirror.prototype.allocateHandle_ = function() { |
427 this.handle_ = next_handle_++; | 435 if (mirror_cache_enabled_) this.handle_ = next_handle_++; |
428 }; | 436 }; |
429 | 437 |
430 | 438 |
431 /** | 439 /** |
432 * Allocate a transient handle id for this object. Transient handles are | 440 * Allocate a transient handle id for this object. Transient handles are |
433 * negative. | 441 * negative. |
434 */ | 442 */ |
435 Mirror.prototype.allocateTransientHandle_ = function() { | 443 Mirror.prototype.allocateTransientHandle_ = function() { |
436 this.handle_ = next_transient_handle_--; | 444 this.handle_ = next_transient_handle_--; |
437 }; | 445 }; |
(...skipping 2340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2778 } | 2786 } |
2779 if (!NUMBER_IS_FINITE(value)) { | 2787 if (!NUMBER_IS_FINITE(value)) { |
2780 if (value > 0) { | 2788 if (value > 0) { |
2781 return 'Infinity'; | 2789 return 'Infinity'; |
2782 } else { | 2790 } else { |
2783 return '-Infinity'; | 2791 return '-Infinity'; |
2784 } | 2792 } |
2785 } | 2793 } |
2786 return value; | 2794 return value; |
2787 } | 2795 } |
OLD | NEW |