| 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) { |
| 112 if (!mirror_cache_enabled_) throw new Error("Mirror cache is disabled"); |
| 104 return mirror_cache_[handle]; | 113 return mirror_cache_[handle]; |
| 105 } | 114 } |
| 106 | 115 |
| 107 | 116 |
| 108 /** | 117 /** |
| 109 * Returns the mirror for the undefined value. | 118 * Returns the mirror for the undefined value. |
| 110 * | 119 * |
| 111 * @returns {Mirror} the mirror reflects the undefined value | 120 * @returns {Mirror} the mirror reflects the undefined value |
| 112 */ | 121 */ |
| 113 function GetUndefinedMirror() { | 122 function GetUndefinedMirror() { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 */ | 426 */ |
| 418 Mirror.prototype.isScope = function() { | 427 Mirror.prototype.isScope = function() { |
| 419 return this instanceof ScopeMirror; | 428 return this instanceof ScopeMirror; |
| 420 }; | 429 }; |
| 421 | 430 |
| 422 | 431 |
| 423 /** | 432 /** |
| 424 * Allocate a handle id for this object. | 433 * Allocate a handle id for this object. |
| 425 */ | 434 */ |
| 426 Mirror.prototype.allocateHandle_ = function() { | 435 Mirror.prototype.allocateHandle_ = function() { |
| 427 this.handle_ = next_handle_++; | 436 if (mirror_cache_enabled_) this.handle_ = next_handle_++; |
| 428 }; | 437 }; |
| 429 | 438 |
| 430 | 439 |
| 431 /** | 440 /** |
| 432 * Allocate a transient handle id for this object. Transient handles are | 441 * Allocate a transient handle id for this object. Transient handles are |
| 433 * negative. | 442 * negative. |
| 434 */ | 443 */ |
| 435 Mirror.prototype.allocateTransientHandle_ = function() { | 444 Mirror.prototype.allocateTransientHandle_ = function() { |
| 436 this.handle_ = next_transient_handle_--; | 445 this.handle_ = next_transient_handle_--; |
| 437 }; | 446 }; |
| (...skipping 2340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2778 } | 2787 } |
| 2779 if (!NUMBER_IS_FINITE(value)) { | 2788 if (!NUMBER_IS_FINITE(value)) { |
| 2780 if (value > 0) { | 2789 if (value > 0) { |
| 2781 return 'Infinity'; | 2790 return 'Infinity'; |
| 2782 } else { | 2791 } else { |
| 2783 return '-Infinity'; | 2792 return '-Infinity'; |
| 2784 } | 2793 } |
| 2785 } | 2794 } |
| 2786 return value; | 2795 return value; |
| 2787 } | 2796 } |
| OLD | NEW |