| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 // Flags: --expose-gc --allow-natives-syntax | |
| 29 | |
| 30 var fired = []; | |
| 31 for (var i = 0; i < 100; i++) fired[i] = false; | |
| 32 | |
| 33 function getter_function(i) { | |
| 34 return %MarkOneShotGetter( function() { fired[i] = true; } ); | |
| 35 } | |
| 36 | |
| 37 // Error objects that die young. | |
| 38 for (var i = 0; i < 100; i++) { | |
| 39 var error = new Error(); | |
| 40 // Replace the getter to observe whether it has been fired, | |
| 41 // and disguise it as original getter. | |
| 42 var getter = getter_function(i); | |
| 43 error.__defineGetter__("stack", getter); | |
| 44 | |
| 45 error = undefined; | |
| 46 } | |
| 47 | |
| 48 gc(); | |
| 49 for (var i = 0; i < 100; i++) { | |
| 50 assertFalse(fired[i]); | |
| 51 } | |
| 52 | |
| 53 // Error objects that are kept alive. | |
| 54 var array = []; | |
| 55 for (var i = 0; i < 100; i++) { | |
| 56 var error = new Error(); | |
| 57 var getter = getter_function(i); | |
| 58 // Replace the getter to observe whether it has been fired, | |
| 59 // and disguise it as original getter. | |
| 60 error.__defineGetter__("stack", getter); | |
| 61 | |
| 62 array.push(error); | |
| 63 error = undefined; | |
| 64 } | |
| 65 | |
| 66 gc(); | |
| 67 // We don't expect all stack traces to be formatted after only one GC. | |
| 68 assertTrue(fired[0]); | |
| 69 | |
| 70 for (var i = 0; i < 10; i++) gc(); | |
| 71 for (var i = 0; i < 100; i++) assertTrue(fired[i]); | |
| 72 | |
| 73 // Error objects with custom stack getter. | |
| 74 var custom_error = new Error(); | |
| 75 var custom_getter_fired = false; | |
| 76 custom_error.__defineGetter__("stack", | |
| 77 function() { custom_getter_fired = true; }); | |
| 78 gc(); | |
| 79 assertFalse(custom_getter_fired); | |
| 80 | |
| 81 // Check that formatting caused by GC is not somehow observable. | |
| 82 var error; | |
| 83 | |
| 84 var obj = { foo: function foo() { throw new Error(); } }; | |
| 85 | |
| 86 try { | |
| 87 obj.foo(); | |
| 88 } catch (e) { | |
| 89 delete obj.foo; | |
| 90 Object.defineProperty(obj, 'foo', { | |
| 91 get: function() { assertUnreachable(); } | |
| 92 }); | |
| 93 error = e; | |
| 94 } | |
| 95 | |
| 96 gc(); | |
| 97 | |
| 98 Object.defineProperty(Array.prototype, '0', { | |
| 99 get: function() { assertUnreachable(); } | |
| 100 }); | |
| 101 | |
| 102 try { | |
| 103 throw new Error(); | |
| 104 } catch (e) { | |
| 105 error = e; | |
| 106 } | |
| 107 | |
| 108 gc(); | |
| 109 | |
| 110 String.prototype.indexOf = function() { assertUnreachable(); }; | |
| 111 String.prototype.lastIndexOf = function() { assertUnreachable(); }; | |
| 112 var obj = { method: function() { throw Error(); } }; | |
| 113 try { | |
| 114 obj.method(); | |
| 115 } catch (e) { | |
| 116 error = e; | |
| 117 } | |
| 118 | |
| 119 gc(); | |
| OLD | NEW |