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

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

Issue 1670133002: [es6] Further fixing of tail Calls. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tail call tracing added Created 4 years, 10 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 | « src/runtime/runtime-test.cc ('k') | test/mjsunit/function-caller.js » ('j') | 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-tailcalls --stack-size=100
6 6
7 // 7 //
8 // Tail calls work only in strict mode. 8 // Tail calls work only in strict mode.
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 f(n - 1);
16 } 16 }
17 assertThrows(()=>{ f(1e6) }); 17 assertThrows(()=>{ f(1e6) });
18 %OptimizeFunctionOnNextCall(f);
19 assertThrows(()=>{ f(1e6) });
18 })(); 20 })();
19 21
20 22
21 // 23 //
22 // Tail call normal functions. 24 // Tail call normal functions.
23 // 25 //
24 (function() { 26 (function() {
25 "use strict"; 27 "use strict";
26 function f(n) { 28 function f(n) {
27 if (n <= 0) { 29 if (n <= 0) {
28 return "foo"; 30 return "foo";
29 } 31 }
30 return f(n - 1); 32 return f(n - 1);
31 } 33 }
32 assertEquals("foo", f(1e6)); 34 assertEquals("foo", f(1e6));
35 %OptimizeFunctionOnNextCall(f);
36 assertEquals("foo", f(1e6));
33 })(); 37 })();
34 38
35 39
36 (function() { 40 (function() {
37 "use strict"; 41 "use strict";
38 function f(n){ 42 function f(n){
39 if (n <= 0) { 43 if (n <= 0) {
40 return "foo"; 44 return "foo";
41 } 45 }
42 return g(n - 1); 46 return g(n - 1);
43 } 47 }
44 function g(n){ 48 function g(n){
45 if (n <= 0) { 49 if (n <= 0) {
46 return "bar"; 50 return "bar";
47 } 51 }
48 return f(n - 1); 52 return f(n - 1);
49 } 53 }
50 assertEquals("foo", f(1e6)); 54 assertEquals("foo", f(1e6));
51 assertEquals("bar", f(1e6 + 1)); 55 assertEquals("bar", f(1e6 + 1));
56 %OptimizeFunctionOnNextCall(f);
57 assertEquals("foo", f(1e6));
58 assertEquals("bar", f(1e6 + 1));
52 })(); 59 })();
53 60
54 61
55 // 62 //
56 // Tail call bound functions. 63 // Tail call bound functions.
57 // 64 //
58 (function() { 65 (function() {
59 "use strict"; 66 "use strict";
60 function f0(n) { 67 function f0(n) {
61 if (n <= 0) { 68 if (n <= 0) {
62 return "foo"; 69 return "foo";
63 } 70 }
64 return f(n - 1); 71 return f_bound(n - 1);
65 } 72 }
66 var f = f0.bind({}); 73 var f_bound = f0.bind({});
74 function f(n) {
75 return f_bound(n);
76 }
77 assertEquals("foo", f(1e6));
78 %OptimizeFunctionOnNextCall(f);
67 assertEquals("foo", f(1e6)); 79 assertEquals("foo", f(1e6));
68 })(); 80 })();
69 81
70 82
71 (function() { 83 (function() {
72 "use strict"; 84 "use strict";
73 function f0(n){ 85 function f0(n){
74 if (n <= 0) { 86 if (n <= 0) {
75 return "foo"; 87 return "foo";
76 } 88 }
77 return g(n - 1); 89 return g_bound(n - 1);
78 } 90 }
79 function g0(n){ 91 function g0(n){
80 if (n <= 0) { 92 if (n <= 0) {
81 return "bar"; 93 return "bar";
82 } 94 }
83 return f(n - 1); 95 return f_bound(n - 1);
84 } 96 }
85 var f = f0.bind({}); 97 var f_bound = f0.bind({});
86 var g = g0.bind({}); 98 var g_bound = g0.bind({});
87 99 function f(n) {
100 return f_bound(n);
101 }
102 assertEquals("foo", f(1e6));
103 assertEquals("bar", f(1e6 + 1));
104 %OptimizeFunctionOnNextCall(f);
88 assertEquals("foo", f(1e6)); 105 assertEquals("foo", f(1e6));
89 assertEquals("bar", f(1e6 + 1)); 106 assertEquals("bar", f(1e6 + 1));
90 })(); 107 })();
OLDNEW
« no previous file with comments | « src/runtime/runtime-test.cc ('k') | test/mjsunit/function-caller.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698