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

Side by Side Diff: test/mjsunit/es7/syntactic-tail-call-simple.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
(Empty)
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
3 // found in the LICENSE file.
4
5 // Flags: --allow-natives-syntax --harmony-explicit-tailcalls --stack-size=100
6
7 //
8 // Tail call normal functions.
9 //
10 (function() {
11 function f(n) {
12 if (n <= 0) {
13 return "foo";
14 }
15 return continue f(n - 1);
16 }
17 assertEquals("foo", f(1e5));
18 %OptimizeFunctionOnNextCall(f);
19 assertEquals("foo", f(1e5));
20 })();
21
22
23 (function() {
24 function f(n) {
25 if (n <= 0) {
26 return "foo";
27 }
28 return continue f(n - 1, 42); // Call with arguments adaptor.
29 }
30 assertEquals("foo", f(1e5));
31 %OptimizeFunctionOnNextCall(f);
32 assertEquals("foo", f(1e5));
33 })();
34
35
36 (function() {
37 function f(n){
38 if (n <= 0) {
39 return "foo";
40 }
41 return continue g(n - 1);
42 }
43 function g(n){
44 if (n <= 0) {
45 return "bar";
46 }
47 return continue f(n - 1);
48 }
49 assertEquals("foo", f(1e5));
50 assertEquals("bar", f(1e5 + 1));
51 %OptimizeFunctionOnNextCall(f);
52 assertEquals("foo", f(1e5));
53 assertEquals("bar", f(1e5 + 1));
54 })();
55
56
57 (function() {
58 function f(n){
59 if (n <= 0) {
60 return "foo";
61 }
62 return continue g(n - 1, 42); // Call with arguments adaptor.
63 }
64 function g(n){
65 if (n <= 0) {
66 return "bar";
67 }
68 return continue f(n - 1, 42); // Call with arguments adaptor.
69 }
70 assertEquals("foo", f(1e5));
71 assertEquals("bar", f(1e5 + 1));
72 %OptimizeFunctionOnNextCall(f);
73 assertEquals("foo", f(1e5));
74 assertEquals("bar", f(1e5 + 1));
75 })();
76
77
78 //
79 // Tail call bound functions.
80 //
81 (function() {
82 function f0(n) {
83 if (n <= 0) {
84 return "foo";
85 }
86 return continue f_bound(n - 1);
87 }
88 var f_bound = f0.bind({});
89 function f(n) {
90 return continue f_bound(n);
91 }
92 assertEquals("foo", f(1e5));
93 %OptimizeFunctionOnNextCall(f);
94 assertEquals("foo", f(1e5));
95 })();
96
97
98 (function() {
99 function f0(n){
100 if (n <= 0) {
101 return "foo";
102 }
103 return continue g_bound(n - 1);
104 }
105 function g0(n){
106 if (n <= 0) {
107 return "bar";
108 }
109 return continue f_bound(n - 1);
110 }
111 var f_bound = f0.bind({});
112 var g_bound = g0.bind({});
113 function f(n) {
114 return continue f_bound(n);
115 }
116 assertEquals("foo", f(1e5));
117 assertEquals("bar", f(1e5 + 1));
118 %OptimizeFunctionOnNextCall(f);
119 assertEquals("foo", f(1e5));
120 assertEquals("bar", f(1e5 + 1));
121 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698