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

Side by Side Diff: test/mjsunit/harmony/block-let-crankshaft.js

Issue 307593002: Preliminary support for block contexts in hydrogen. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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
(...skipping 14 matching lines...) Expand all
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: --harmony-scoping --allow-natives-syntax 28 // Flags: --harmony-scoping --allow-natives-syntax
29 29
30 // TODO(ES6): properly activate extended mode 30 // TODO(ES6): properly activate extended mode
31 "use strict"; 31 "use strict";
32 32
33 // Check that the following functions are optimizable. 33 // Check that the following functions are optimizable.
34 var functions = [ f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, 34 var functions = [ f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14,
35 f15, f16, f17, f18, f19, f20, f21, f22, f23 ]; 35 f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26,
36 f27, f28, f29, f30, f31, f32, f33 ];
rossberg 2014/06/04 12:54:53 Perhaps add a test for throwing out of a crankshaf
ulan 2014/06/04 14:02:05 Done.
36 37
37 for (var i = 0; i < functions.length; ++i) { 38 for (var i = 0; i < functions.length; ++i) {
38 var func = functions[i]; 39 var func = functions[i];
39 print("Testing:"); 40 print("Testing:");
40 print(func); 41 print(func);
41 for (var j = 0; j < 10; ++j) { 42 for (var j = 0; j < 10; ++j) {
42 func(12); 43 func(12);
43 } 44 }
44 %OptimizeFunctionOnNextCall(func); 45 %OptimizeFunctionOnNextCall(func);
45 func(12); 46 func(12);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 x = 1; 150 x = 1;
150 (function() { x; }); 151 (function() { x; });
151 } 152 }
152 153
153 function f23() { 154 function f23() {
154 function x() { } 155 function x() { }
155 x = 1; 156 x = 1;
156 (function() { x; }); 157 (function() { x; });
157 } 158 }
158 159
160 function f24() {
161 let x = 1;
162 {
163 let x = 2;
164 {
165 let x = 3;
166 assertEquals(3, x);
167 }
168 assertEquals(2, x);
169 }
170 assertEquals(1, x);
171 }
172
173 function f25() {
174 {
175 let x = 2;
176 L: {
177 let x = 3;
178 assertEquals(3, x);
179 break L;
180 assertTrue(false);
181 }
182 assertEquals(2, x);
183 }
184 assertTrue(true);
185 }
186
187 function f26() {
188 {
189 let x = 1;
190 L: {
191 let x = 2;
192 {
193 let x = 3;
194 assertEquals(3, x);
195 break L;
196 assertTrue(false);
197 }
198 assertTrue(false);
199 }
200 assertEquals(1, x);
201 }
202 }
203
204
205 function f27() {
206 do {
207 let x = 4;
208 assertEquals(4,x);
209 {
210 let x = 5;
211 assertEquals(5, x);
212 continue;
213 assertTrue(false);
214 }
215 } while (false);
216 }
217
218 function f28() {
219 label: for (var i = 0; i < 10; ++i) {
220 let x = 'middle' + i;
221 for (var j = 0; j < 10; ++j) {
222 let x = 'inner' + j;
223 continue label;
224 }
225 }
226 }
227
228 function f29() {
229 // Verify that the context is correctly set in the stack frame after exiting
230 // from with.
231
232 let x = 'outer';
233 label: {
234 let x = 'inner';
235 break label;
236 }
237 f(); // The context could be restored from the stack after the call.
238 assertEquals('outer', x);
239
240 function f() {
241 assertEquals('outer', x);
242 };
243 }
244
245 function f30() {
246 let x = 'outer';
247 for (var i = 0; i < 10; ++i) {
248 let x = 'inner';
249 continue;
250 }
251 f();
252 assertEquals('outer', x);
253
254 function f() {
255 assertEquals('outer', x);
256 };
257 }
258
259 function f31() {
260 {
261 let x = 'outer';
262 label: for (var i = 0; assertEquals('outer', x), i < 10; ++i) {
263 let x = 'middle' + i;
264 {
265 let x = 'inner' + j;
266 continue label;
267 }
268 }
269 assertEquals('outer', x);
270 }
271 }
272
273 var c = true;
274
275 function f32() {
276 {
277 let x = 'outer';
278 L: {
279 {
280 let x = 'inner';
281 if (c) {
282 break L;
283 }
284 }
285 foo();
286 }
287 }
288
289 function foo() {
290 return 'bar';
291 }
292 }
293
294 function f33() {
295 {
296 let x = 'outer';
297 L: {
298 {
299 let x = 'inner';
300 if (c) {
301 break L;
302 }
303 foo();
304 }
305 }
306 }
307
308 function foo() {
309 return 'bar';
310 }
311 }
159 312
160 // Test that temporal dead zone semantics for function and block scoped 313 // Test that temporal dead zone semantics for function and block scoped
161 // let bindings are handled by the optimizing compiler. 314 // let bindings are handled by the optimizing compiler.
162 315
163 function TestFunctionLocal(s) { 316 function TestFunctionLocal(s) {
164 'use strict'; 317 'use strict';
165 var func = eval("(function baz(){" + s + "; })"); 318 var func = eval("(function baz(){" + s + "; })");
166 print("Testing:"); 319 print("Testing:");
167 print(func); 320 print(func);
168 for (var i = 0; i < 5; ++i) { 321 for (var i = 0; i < 5; ++i) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 try { 354 try {
202 print("call"); 355 print("call");
203 func(); 356 func();
204 assertUnreachable(); 357 assertUnreachable();
205 } catch (e) { 358 } catch (e) {
206 print("catch"); 359 print("catch");
207 assertInstanceof(e, ReferenceError); 360 assertInstanceof(e, ReferenceError);
208 } 361 }
209 } 362 }
210 363
364 function TestBlockLocal(s) {
365 'use strict';
366 var func = eval("(function baz(){ { " + s + "; } })");
367 print("Testing:");
368 print(func);
369 for (var i = 0; i < 5; ++i) {
370 try {
371 func();
372 assertUnreachable();
373 } catch (e) {
374 assertInstanceof(e, ReferenceError);
375 }
376 }
377 %OptimizeFunctionOnNextCall(func);
378 try {
379 func();
380 assertUnreachable();
381 } catch (e) {
382 assertInstanceof(e, ReferenceError);
383 }
384 }
385
386 function TestBlockContext(s) {
387 'use strict';
388 var func = eval("(function baz(){ { " + s + "; (function() { x; }); } })");
389 print("Testing:");
390 print(func);
391 for (var i = 0; i < 5; ++i) {
392 print(i);
393 try {
394 func();
395 assertUnreachable();
396 } catch (e) {
397 assertInstanceof(e, ReferenceError);
398 }
399 }
400 print("optimize");
401 %OptimizeFunctionOnNextCall(func);
402 try {
403 print("call");
404 func();
405 assertUnreachable();
406 } catch (e) {
407 print("catch");
408 assertInstanceof(e, ReferenceError);
409 }
410 }
411
211 function TestAll(s) { 412 function TestAll(s) {
212 TestFunctionLocal(s); 413 TestFunctionLocal(s);
213 TestFunctionContext(s); 414 TestFunctionContext(s);
415 TestBlockLocal(s);
416 TestBlockContext(s);
214 } 417 }
215 418
216 // Use before initialization in declaration statement. 419 // Use before initialization in declaration statement.
217 TestAll('let x = x + 1'); 420 TestAll('let x = x + 1');
218 TestAll('let x = x += 1'); 421 TestAll('let x = x += 1');
219 TestAll('let x = x++'); 422 TestAll('let x = x++');
220 TestAll('let x = ++x'); 423 TestAll('let x = ++x');
221 TestAll('const x = x + 1'); 424 TestAll('const x = x + 1');
222 425
223 // Use before initialization in prior statement. 426 // Use before initialization in prior statement.
224 TestAll('x + 1; let x;'); 427 TestAll('x + 1; let x;');
225 TestAll('x = 1; let x;'); 428 TestAll('x = 1; let x;');
226 TestAll('x += 1; let x;'); 429 TestAll('x += 1; let x;');
227 TestAll('++x; let x;'); 430 TestAll('++x; let x;');
228 TestAll('x++; let x;'); 431 TestAll('x++; let x;');
229 TestAll('let y = x; const x = 1;'); 432 TestAll('let y = x; const x = 1;');
230 433
231 434
232 function f(x, b) { 435 function f(x) {
233 let y = (b ? y : x) + 42; 436 let y = x + 42;
234 return y; 437 return y;
235 } 438 }
236 439
237 function g(x, b) { 440 function g(x) {
238 { 441 {
239 let y = (b ? y : x) + 42; 442 let y = x + 42;
240 return y; 443 return y;
241 } 444 }
242 } 445 }
243 446
244 for (var i=0; i<10; i++) { 447 for (var i=0; i<10; i++) {
245 f(i, false); 448 f(i);
246 g(i, false); 449 g(i);
247 } 450 }
248 451
249 %OptimizeFunctionOnNextCall(f); 452 %OptimizeFunctionOnNextCall(f);
250 %OptimizeFunctionOnNextCall(g); 453 %OptimizeFunctionOnNextCall(g);
251 454
252 try { 455 f(12);
253 f(42, true); 456 g(12);
254 } catch (e) {
255 assertInstanceof(e, ReferenceError);
256 }
257 457
258 try { 458 assertTrue(%GetOptimizationStatus(f) != 2);
259 g(42, true); 459 assertTrue(%GetOptimizationStatus(g) != 2);
260 } catch (e) {
261 assertInstanceof(e, ReferenceError);
262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698