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

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

Issue 1917993004: [es8] Initial set of changes to support syntactic tail calls. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressing comments Created 4 years, 8 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
« no previous file with comments | « test/mjsunit/es7/syntactic-tail-call.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 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-tailcalls --stack-size=100 5 // Flags: --allow-natives-syntax --harmony-explicit-tailcalls --stack-size=100
6 6
7 // 7 //
8 // Tail calls work only in strict mode. 8 // Tail call normal functions.
9 // 9 //
10 (function() { 10 (function() {
11 function f(n) { 11 function f(n) {
12 if (n <= 0) { 12 if (n <= 0) {
13 return "foo"; 13 return "foo";
14 } 14 }
15 return f(n - 1); 15 return continue f(n - 1);
16 }
17 assertThrows(()=>{ f(1e5) });
18 %OptimizeFunctionOnNextCall(f);
19 assertThrows(()=>{ f(1e5) });
20 })();
21
22
23 //
24 // Tail call normal functions.
25 //
26 (function() {
27 "use strict";
28 function f(n) {
29 if (n <= 0) {
30 return "foo";
31 }
32 return f(n - 1);
33 } 16 }
34 assertEquals("foo", f(1e5)); 17 assertEquals("foo", f(1e5));
35 %OptimizeFunctionOnNextCall(f); 18 %OptimizeFunctionOnNextCall(f);
36 assertEquals("foo", f(1e5)); 19 assertEquals("foo", f(1e5));
37 })(); 20 })();
38 21
39 22
40 (function() { 23 (function() {
41 "use strict";
42 function f(n) { 24 function f(n) {
43 if (n <= 0) { 25 if (n <= 0) {
44 return "foo"; 26 return "foo";
45 } 27 }
46 return f(n - 1, 42); // Call with arguments adaptor. 28 return continue f(n - 1, 42); // Call with arguments adaptor.
47 } 29 }
48 assertEquals("foo", f(1e5)); 30 assertEquals("foo", f(1e5));
49 %OptimizeFunctionOnNextCall(f); 31 %OptimizeFunctionOnNextCall(f);
50 assertEquals("foo", f(1e5)); 32 assertEquals("foo", f(1e5));
51 })(); 33 })();
52 34
53 35
54 (function() { 36 (function() {
55 "use strict";
56 function f(n){ 37 function f(n){
57 if (n <= 0) { 38 if (n <= 0) {
58 return "foo"; 39 return "foo";
59 } 40 }
60 return g(n - 1); 41 return continue g(n - 1);
61 } 42 }
62 function g(n){ 43 function g(n){
63 if (n <= 0) { 44 if (n <= 0) {
64 return "bar"; 45 return "bar";
65 } 46 }
66 return f(n - 1); 47 return continue f(n - 1);
67 } 48 }
68 assertEquals("foo", f(1e5)); 49 assertEquals("foo", f(1e5));
69 assertEquals("bar", f(1e5 + 1)); 50 assertEquals("bar", f(1e5 + 1));
70 %OptimizeFunctionOnNextCall(f); 51 %OptimizeFunctionOnNextCall(f);
71 assertEquals("foo", f(1e5)); 52 assertEquals("foo", f(1e5));
72 assertEquals("bar", f(1e5 + 1)); 53 assertEquals("bar", f(1e5 + 1));
73 })(); 54 })();
74 55
75 56
76 (function() { 57 (function() {
77 "use strict";
78 function f(n){ 58 function f(n){
79 if (n <= 0) { 59 if (n <= 0) {
80 return "foo"; 60 return "foo";
81 } 61 }
82 return g(n - 1, 42); // Call with arguments adaptor. 62 return continue g(n - 1, 42); // Call with arguments adaptor.
83 } 63 }
84 function g(n){ 64 function g(n){
85 if (n <= 0) { 65 if (n <= 0) {
86 return "bar"; 66 return "bar";
87 } 67 }
88 return f(n - 1, 42); // Call with arguments adaptor. 68 return continue f(n - 1, 42); // Call with arguments adaptor.
89 } 69 }
90 assertEquals("foo", f(1e5)); 70 assertEquals("foo", f(1e5));
91 assertEquals("bar", f(1e5 + 1)); 71 assertEquals("bar", f(1e5 + 1));
92 %OptimizeFunctionOnNextCall(f); 72 %OptimizeFunctionOnNextCall(f);
93 assertEquals("foo", f(1e5)); 73 assertEquals("foo", f(1e5));
94 assertEquals("bar", f(1e5 + 1)); 74 assertEquals("bar", f(1e5 + 1));
95 })(); 75 })();
96 76
97 77
98 // 78 //
99 // Tail call bound functions. 79 // Tail call bound functions.
100 // 80 //
101 (function() { 81 (function() {
102 "use strict";
103 function f0(n) { 82 function f0(n) {
104 if (n <= 0) { 83 if (n <= 0) {
105 return "foo"; 84 return "foo";
106 } 85 }
107 return f_bound(n - 1); 86 return continue f_bound(n - 1);
108 } 87 }
109 var f_bound = f0.bind({}); 88 var f_bound = f0.bind({});
110 function f(n) { 89 function f(n) {
111 return f_bound(n); 90 return continue f_bound(n);
112 } 91 }
113 assertEquals("foo", f(1e5)); 92 assertEquals("foo", f(1e5));
114 %OptimizeFunctionOnNextCall(f); 93 %OptimizeFunctionOnNextCall(f);
115 assertEquals("foo", f(1e5)); 94 assertEquals("foo", f(1e5));
116 })(); 95 })();
117 96
118 97
119 (function() { 98 (function() {
120 "use strict";
121 function f0(n){ 99 function f0(n){
122 if (n <= 0) { 100 if (n <= 0) {
123 return "foo"; 101 return "foo";
124 } 102 }
125 return g_bound(n - 1); 103 return continue g_bound(n - 1);
126 } 104 }
127 function g0(n){ 105 function g0(n){
128 if (n <= 0) { 106 if (n <= 0) {
129 return "bar"; 107 return "bar";
130 } 108 }
131 return f_bound(n - 1); 109 return continue f_bound(n - 1);
132 } 110 }
133 var f_bound = f0.bind({}); 111 var f_bound = f0.bind({});
134 var g_bound = g0.bind({}); 112 var g_bound = g0.bind({});
135 function f(n) { 113 function f(n) {
136 return f_bound(n); 114 return continue f_bound(n);
137 } 115 }
138 assertEquals("foo", f(1e5)); 116 assertEquals("foo", f(1e5));
139 assertEquals("bar", f(1e5 + 1)); 117 assertEquals("bar", f(1e5 + 1));
140 %OptimizeFunctionOnNextCall(f); 118 %OptimizeFunctionOnNextCall(f);
141 assertEquals("foo", f(1e5)); 119 assertEquals("foo", f(1e5));
142 assertEquals("bar", f(1e5 + 1)); 120 assertEquals("bar", f(1e5 + 1));
143 })(); 121 })();
OLDNEW
« no previous file with comments | « test/mjsunit/es7/syntactic-tail-call.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698