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

Side by Side Diff: test/mjsunit/getters-on-elements.js

Issue 35413006: Correct handling of arrays with callbacks in the prototype chain. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Bugfix: check on dictionary elements was incorrect. Added test. Re-enabled test. Created 7 years, 1 month 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
« no previous file with comments | « test/mjsunit/allocation-site-info.js ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 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: --allow-natives-syntax --max-opt-count=100 --noalways-opt
29
30 // We specify max-opt-count because we opt/deopt the same function many
31 // times.
32
33 // It's nice to run this in other browsers too.
34 var standalone = false;
35 if (standalone) {
36 assertTrue = function(val) {
37 if (val != true) {
38 print("FAILURE");
39 }
40 }
41
42 assertFalse = function(val) {
43 if (val != false) {
44 print("FAILURE");
45 }
46 }
47
48 assertEquals = function(expected, val) {
49 if (expected !== val) {
50 print("FAILURE");
51 }
52 }
53
54 empty_func = function(name) { }
55 assertUnoptimized = empty_func;
56 assertOptimized = empty_func;
57
58 optimize = empty_func;
59 clearFunctionTypeFeedback = empty_func;
60 deoptimizeFunction = empty_func;
61 } else {
62 optimize = function(name) {
63 %OptimizeFunctionOnNextCall(name);
64 }
65 clearFunctionTypeFeedback = function(name) {
66 %ClearFunctionTypeFeedback(name);
67 }
68 deoptimizeFunction = function(name) {
69 %DeoptimizeFunction(name);
70 }
71 }
72
73 function base_getter_test(create_func) {
74 var calls = 0;
75
76 // Testcase: setter in prototype chain
77 foo = function(a) { var x = a[0]; return x + 3; }
78 var a = create_func();
79 var ap = [];
80 ap.__defineGetter__(0, function() { calls++; return 0; });
81
82 foo(a);
83 foo(a);
84 foo(a);
85 delete a[0];
86
87 assertEquals(0, calls);
88 a.__proto__ = ap;
89 foo(a);
90 assertEquals(1, calls);
91 optimize(foo);
92 foo(a);
93 assertEquals(2, calls);
94 assertOptimized(foo);
95
96 // Testcase: getter "deep" in prototype chain.
97 clearFunctionTypeFeedback(foo);
98 deoptimizeFunction(foo);
99 clearFunctionTypeFeedback(foo);
100 calls = 0;
101
102 a = create_func();
103 var ap2 = [];
104 a.__proto__ = ap2;
105 foo(a);
106 foo(a);
107 foo(a);
108 delete a[0];
109
110 assertEquals(0, calls);
111
112 ap2.__proto__ = ap; // "sneak" in a callback.
113 // The sneak case should be caught by unoptimized code too.
114 assertUnoptimized(foo);
115 foo(a);
116 foo(a);
117 foo(a);
118 assertEquals(3, calls);
119
120 // Testcase: getter added after optimization (feedback is monomorphic)
121 clearFunctionTypeFeedback(foo);
122 deoptimizeFunction(foo);
123 clearFunctionTypeFeedback(foo);
124 calls = 0;
125
126 a = create_func();
127 ap2 = [];
128 a.__proto__ = ap2;
129 foo(a);
130 foo(a);
131 foo(a);
132 optimize(foo);
133 foo(a);
134 assertOptimized(foo);
135 delete a[0];
136 ap2.__proto__ = ap;
137 foo(a);
138 assertOptimized(foo); // getters don't require deopt on shape change.
139 assertEquals(1, calls);
140
141 // Testcase: adding additional getters to a prototype chain that already has
142 // one shouldn't deopt anything.
143 clearFunctionTypeFeedback(foo);
144 calls = 0;
145
146 a = create_func();
147 a.__proto__ = ap2;
148 bar = function(a) { return a[3] + 600; }
149 bar(a);
150 bar(a);
151 bar(a);
152 optimize(bar);
153 bar(a);
154 assertOptimized(bar);
155 assertEquals(0, calls);
156 delete a[3];
157 ap2.__defineGetter__(3, function() { calls++; return 0; });
158 bar(a);
159 assertOptimized(bar);
160 assertEquals(1, calls);
161 }
162
163 // Verify that map transitions don't confuse us.
164 create_func_smi = function() { return [,,,,,,5]; }
165 create_func_double = function() { return [,,,,,,5.5]; }
166 create_func_fast = function() { return [,,,,,,true]; }
167
168 var cf = [create_func_smi,
169 create_func_double,
170 create_func_fast];
171
172 for(var c = 0; c < 3; c++) {
173 base_getter_test(cf[c]);
174 }
175
176 // A special test for LoadKeyedHoleMode. Ensure that optimized is generated
177 // which sets ALLOW_RETURN_HOLE, then add a setter on the prototype that should
178 // cause the function to deoptimize.
179
180 var a = [3.5,,,3.5];
181 fun = function(a) { return a[0] + 5.5; }
182 fun(a);
183 fun(a);
184 fun(a); // should have a monomorphic KeyedLoadIC.
185 optimize(fun);
186 fun(a);
187 assertOptimized(fun);
188
189 // returning undefined shouldn't phase us.
190 delete a[0];
191 fun(a);
192 assertOptimized(fun);
193
194 // but messing up the prototype chain will.
195 a.__proto__ = [];
196 fun(a);
197 assertUnoptimized(fun);
198
199 // Construct a non-trivial prototype chain.
200 var a = [3.5,,,,3.5];
201 var ap = [,,3.5];
202 ap.__proto__ = a.__proto__;
203 a.__proto__ = ap;
204 fun(a);
205 optimize(fun);
206 fun(a);
207 assertOptimized(fun);
208
209 var calls = 0;
210 delete a[0];
211 ap.__defineGetter__(0, function() { calls++; return 0; });
212 fun(a);
213 assertEquals(1, calls);
214 assertUnoptimized(fun);
OLDNEW
« no previous file with comments | « test/mjsunit/allocation-site-info.js ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698