Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: test/mjsunit/stack-traces-gc.js

Issue 11377158: Fire 'stack' getter of error objects after GC. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: use hidden properties to mark oneshot getter Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/messages.js ('K') | « test/mjsunit/stack-traces.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --expose-gc 28 // Flags: --expose-gc --allow-natives-syntax
29 29
30 // Handy abbreviation. 30 var fired = [];
31 var dp = Object.defineProperty; 31 for (var i = 0; i < 100; i++) fired[i] = false;
32 32
33 function getter() { return 111; } 33 function getter_function(i) {
34 function setter(x) { print(222); } 34 return %MarkOneShotGetter( function() { fired[i] = true; } );
35 function anotherGetter() { return 333; } 35 }
36 function anotherSetter(x) { print(444); }
37 var obj1, obj2;
38 36
39 // obj1 and obj2 share the getter accessor. 37 // Error objects that die young.
40 obj1 = {}; 38 for (var i = 0; i < 100; i++) {
41 dp(obj1, "alpha", { get: getter, set: setter }); 39 var error = new Error();
42 obj2 = {} 40 // Replace the getter to observe whether it has been fired,
43 dp(obj2, "alpha", { get: getter }); 41 // and disguise it as original getter.
44 obj1 = {}; 42 var getter = getter_function(i);
45 assertEquals(111, obj2.alpha); 43 error.__defineGetter__("stack", getter);
44
45 error = undefined;
46 }
47
46 gc(); 48 gc();
47 assertEquals(111, obj2.alpha); 49 for (var i = 0; i < 100; i++) {
50 assertFalse(fired[i]);
51 }
48 52
49 // obj1, obj2, and obj3 share the getter accessor. 53 // Error objects that are kept alive.
50 obj1 = {}; 54 var array = [];
51 dp(obj1, "alpha", { get: getter, set: setter }); 55 for (var i = 0; i < 100; i++) {
52 obj2 = {} 56 var error = new Error();
53 dp(obj2, "alpha", { get: getter }); 57 var getter = getter_function(i);
54 obj1 = {}; 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
55 gc(); 66 gc();
56 obj3 = {} 67 // We don't expect all stack traces to be formatted after only one GC.
57 dp(obj3, "alpha", { get: getter }); 68 assertTrue(fired[0]);
58 69
70 for (var i = 0; i < 10; i++) gc();
71 for (var i = 0; i < 100; i++) assertTrue(fired[i]);
59 72
60 // obj1 and obj2 share the getter and setter accessor. 73 // Error objects with custom stack getter.
61 obj1 = {}; 74 var custom_error = new Error();
62 dp(obj1, "alpha", { get: getter, set: setter }); 75 var custom_getter_fired = false;
63 obj1.beta = 10; 76 custom_error.__defineGetter__("stack",
64 obj2 = {} 77 function() { custom_getter_fired = true; });
65 dp(obj2, "alpha", { get: getter, set: setter });
66 obj1 = {};
67 assertEquals(111, obj2.alpha);
68 gc(); 78 gc();
69 obj2.alpha = 100 79 assertFalse(custom_getter_fired);
70 assertEquals(111, obj2.alpha);
OLDNEW
« src/messages.js ('K') | « test/mjsunit/stack-traces.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698