OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 --nostress-opt --turbo | 5 // Flags: --allow-natives-syntax --nostress-opt --turbo |
6 // Flags: --nonative-context-specialization | 6 // Flags: --nonative-context-specialization |
7 | 7 |
8 var p0 = new Object(); | 8 var p0 = new Object(); |
9 var p1 = new Object(); | 9 var p1 = new Object(); |
10 var p2 = new Object(); | 10 var p2 = new Object(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 "use strict"; | 46 "use strict"; |
47 if (count3-- == 0) { | 47 if (count3-- == 0) { |
48 return this; | 48 return this; |
49 } | 49 } |
50 return %_TailCall(tailee3, px, this); | 50 return %_TailCall(tailee3, px, this); |
51 }; | 51 }; |
52 | 52 |
53 %OptimizeFunctionOnNextCall(tailee3); | 53 %OptimizeFunctionOnNextCall(tailee3); |
54 assertEquals(p2, tailee3.call(p1, p2)); | 54 assertEquals(p2, tailee3.call(p1, p2)); |
55 | 55 |
56 // Ensure too many parameters defeats the tail call optimization (currently | 56 // Ensure too many parameters defeats the tail call optimization if they use the |
57 // unsupported). | 57 // arguments adapter (currently unsupported). |
58 var count4 = 1000000; | 58 var count4 = 1000000; |
59 tailee4 = function(px) { | 59 tailee4 = function(px) { |
60 "use strict"; | 60 "use strict"; |
61 if (count4-- == 0) { | 61 if (count4-- == 0) { |
62 return this; | 62 return this; |
63 } | 63 } |
64 return %_TailCall(tailee4, this, px, undefined); | 64 return %_TailCall(tailee4, this, px, undefined); |
65 }; | 65 }; |
66 | 66 |
67 %OptimizeFunctionOnNextCall(tailee4); | 67 %OptimizeFunctionOnNextCall(tailee4); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 | 100 |
101 tailee9 = function(px, py, pz, pa, pb, pc) { | 101 tailee9 = function(px, py, pz, pa, pb, pc) { |
102 "use strict"; | 102 "use strict"; |
103 return %_TailCall(tailee8, this, pb, py, px, pa, pz); | 103 return %_TailCall(tailee8, this, pb, py, px, pa, pz); |
104 }; | 104 }; |
105 | 105 |
106 %OptimizeFunctionOnNextCall(tailee8); | 106 %OptimizeFunctionOnNextCall(tailee8); |
107 %OptimizeFunctionOnNextCall(tailee9); | 107 %OptimizeFunctionOnNextCall(tailee9); |
108 assertEquals(32, tailee9.call(null, 15, 16, 17, 18, 0, 110)); | 108 assertEquals(32, tailee9.call(null, 15, 16, 17, 18, 0, 110)); |
| 109 |
| 110 // Tail calls adding a single parameter. |
| 111 tailee10 = function(pb) { |
| 112 return pb; |
| 113 } |
| 114 |
| 115 tailee11 = function() { |
| 116 "use strict"; |
| 117 return %_TailCall(tailee10, this, 5); |
| 118 }; |
| 119 |
| 120 %OptimizeFunctionOnNextCall(tailee10); |
| 121 %OptimizeFunctionOnNextCall(tailee11); |
| 122 assertEquals(5, tailee11.call(null)); |
| 123 |
| 124 tailee12 = function(pa, pb, pc, pd) { |
| 125 return pa + pb + pc + pd; |
| 126 } |
| 127 |
| 128 tailee13 = function(pa, pb) { |
| 129 "use strict"; |
| 130 return %_TailCall(tailee12, 7, this, pb, pa, 13); |
| 131 }; |
| 132 |
| 133 %OptimizeFunctionOnNextCall(tailee12); |
| 134 %OptimizeFunctionOnNextCall(tailee13); |
| 135 assertEquals(41, tailee13.call(12, 15, 1)); |
| 136 |
| 137 tailee14 = function(pa, pb, pc, pd, pe, pf) { |
| 138 return pa + pb + pc + pd + pe + pf; |
| 139 } |
| 140 |
| 141 tailee15 = function(pa, pb) { |
| 142 "use strict"; |
| 143 return %_TailCall(tailee14, 7, this, pb, pa, 13, pb, pa); |
| 144 }; |
| 145 |
| 146 %OptimizeFunctionOnNextCall(tailee14); |
| 147 %OptimizeFunctionOnNextCall(tailee15); |
| 148 assertEquals(57, tailee15.call(12, 15, 1)); |
OLD | NEW |