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

Side by Side Diff: test/mjsunit/es8/syntactic-tail-call.js

Issue 1928203002: [es8] More spec compliant syntactic tail calls implementation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Moar tests Created 4 years, 7 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 // Flags: --allow-natives-syntax --harmony-explicit-tailcalls 5 // Flags: --allow-natives-syntax --harmony-explicit-tailcalls
6 // Flags: --harmony-do-expressions
6 7
7 Error.prepareStackTrace = (error,stack) => { 8 Error.prepareStackTrace = (error,stack) => {
8 error.strace = stack; 9 error.strace = stack;
9 return error.message + "\n at " + stack.join("\n at "); 10 return error.message + "\n at " + stack.join("\n at ");
10 } 11 }
11 12
12 13
13 function CheckStackTrace(expected) { 14 function CheckStackTrace(expected) {
14 var e = new Error(); 15 var e = new Error();
15 e.stack; // prepare stack trace 16 e.stack; // prepare stack trace
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 assertEquals(19, g3()); 214 assertEquals(19, g3());
214 assertEquals(12, g4()); 215 assertEquals(12, g4());
215 } 216 }
216 test(); 217 test();
217 test(); 218 test();
218 %OptimizeFunctionOnNextCall(test); 219 %OptimizeFunctionOnNextCall(test);
219 test(); 220 test();
220 })(); 221 })();
221 222
222 223
223 // Tail calling via various expressions. 224 // Tail calling via various expressions.
rossberg 2016/05/04 10:45:30 Can you add tests where these cases nest? E.g. a
Igor Sheludko 2016/05/04 11:50:14 Done.
224 (function() { 225 (function() {
225 function g1(a) { 226 function g1(a) {
226 return continue f([f, g1, test], false) || f([f, test], true); 227 return f([f, g1, test], false) || continue f([f, test], true);
227 } 228 }
228 229
229 function g2(a) { 230 function g2(a) {
230 return continue f([f, g2, test], true) && f([f, test], true); 231 return f([f, g2, test], true) && continue f([f, test], true);
231 } 232 }
232 233
233 function g3(a) { 234 function g3(a) {
234 return continue f([f, g3, test], 13), f([f, test], 153); 235 return f([f, g3, test], 13), continue f([f, test], 153);
235 } 236 }
236 237
237 function test() { 238 function test() {
238 assertEquals(true, g1()); 239 assertEquals(true, g1());
239 assertEquals(true, g2()); 240 assertEquals(true, g2());
240 assertEquals(153, g3()); 241 assertEquals(153, g3());
241 } 242 }
242 test(); 243 test();
243 test(); 244 test();
244 %OptimizeFunctionOnNextCall(test); 245 %OptimizeFunctionOnNextCall(test);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 (function () { 398 (function () {
398 function g1(a) { 399 function g1(a) {
399 return continue (() => { return continue f_153([f_153, test]); })(); 400 return continue (() => { return continue f_153([f_153, test]); })();
400 } 401 }
401 402
402 function g2(a) { 403 function g2(a) {
403 return continue (() => continue f_153([f_153, test]))(); 404 return continue (() => continue f_153([f_153, test]))();
404 } 405 }
405 406
406 function g3(a) { 407 function g3(a) {
407 var closure = () => continue f([f, closure, test], true) 408 var closure = () => f([f, closure, test], true)
408 ? f_153([f_153, test]) 409 ? continue f_153([f_153, test])
409 : f_153([f_153, test]); 410 : continue f_153([f_153, test]);
410
411 return continue closure(); 411 return continue closure();
412 } 412 }
413 413
414 function test() { 414 function test() {
415 assertEquals(153, g1()); 415 assertEquals(153, g1());
416 assertEquals(153, g2()); 416 assertEquals(153, g2());
417 assertEquals(153, g3()); 417 assertEquals(153, g3());
418 } 418 }
419 test(); 419 test();
420 test(); 420 test();
421 %OptimizeFunctionOnNextCall(test); 421 %OptimizeFunctionOnNextCall(test);
422 test(); 422 test();
423 })(); 423 })();
424
425
426 // Test tail calls from do expressions.
427 (function () {
428 function g1(a) {
429 var a = do { return continue f_153([f_153, test]); 42; };
430 return a;
431 }
432
433 function test() {
434 assertEquals(153, g1());
435 }
436 test();
437 test();
438 %OptimizeFunctionOnNextCall(test);
439 test();
440 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698