OLD | NEW |
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 | 5 // Flags: --allow-natives-syntax --harmony-tailcalls |
| 6 // TODO(v8:4698), TODO(ishell): support these cases. |
| 7 // Flags: --max-inlined-source-size=0 |
6 "use strict"; | 8 "use strict"; |
7 | 9 |
8 Error.prepareStackTrace = (error,stack) => { | 10 Error.prepareStackTrace = (error,stack) => { |
9 error.strace = stack; | 11 error.strace = stack; |
10 return error.message + "\n at " + stack.join("\n at "); | 12 return error.message + "\n at " + stack.join("\n at "); |
11 } | 13 } |
12 | 14 |
13 | 15 |
14 function CheckStackTrace(expected) { | 16 function CheckStackTrace(expected) { |
15 var e = new Error(); | 17 var e = new Error(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 64 } |
63 function g4(a) { return f4(2); } | 65 function g4(a) { return f4(2); } |
64 | 66 |
65 function test() { | 67 function test() { |
66 assertEquals(12, g1(1)); | 68 assertEquals(12, g1(1)); |
67 assertEquals(12, g2(1, 2, 3)); | 69 assertEquals(12, g2(1, 2, 3)); |
68 assertEquals(19, g3(1)); | 70 assertEquals(19, g3(1)); |
69 assertEquals(12, g4(1)); | 71 assertEquals(12, g4(1)); |
70 } | 72 } |
71 test(); | 73 test(); |
| 74 test(); |
72 %OptimizeFunctionOnNextCall(test); | 75 %OptimizeFunctionOnNextCall(test); |
73 test(); | 76 test(); |
74 })(); | 77 })(); |
75 | 78 |
76 | 79 |
77 // Tail call when caller has an arguments adaptor frame. | 80 // Tail call when caller has an arguments adaptor frame. |
78 (function() { | 81 (function() { |
79 // Caller and callee have same number of arguments. | 82 // Caller and callee have same number of arguments. |
80 function f1(a) { | 83 function f1(a) { |
81 CheckStackTrace([f1, test]); | 84 CheckStackTrace([f1, test]); |
(...skipping 22 matching lines...) Expand all Loading... |
104 } | 107 } |
105 function g4(a) { return f4(2); } | 108 function g4(a) { return f4(2); } |
106 | 109 |
107 function test() { | 110 function test() { |
108 assertEquals(12, g1()); | 111 assertEquals(12, g1()); |
109 assertEquals(12, g2()); | 112 assertEquals(12, g2()); |
110 assertEquals(19, g3()); | 113 assertEquals(19, g3()); |
111 assertEquals(12, g4()); | 114 assertEquals(12, g4()); |
112 } | 115 } |
113 test(); | 116 test(); |
| 117 test(); |
114 %OptimizeFunctionOnNextCall(test); | 118 %OptimizeFunctionOnNextCall(test); |
115 test(); | 119 test(); |
116 })(); | 120 })(); |
117 | 121 |
118 | 122 |
119 // Tail call bound function when caller does not have an arguments | 123 // Tail call bound function when caller does not have an arguments |
120 // adaptor frame. | 124 // adaptor frame. |
121 (function() { | 125 (function() { |
122 // Caller and callee have same number of arguments. | 126 // Caller and callee have same number of arguments. |
123 function f1(a) { | 127 function f1(a) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 var b4 = f4.bind({a: 153}); | 159 var b4 = f4.bind({a: 153}); |
156 function g4(a) { return b4(2); } | 160 function g4(a) { return b4(2); } |
157 | 161 |
158 function test() { | 162 function test() { |
159 assertEquals(12, g1(1)); | 163 assertEquals(12, g1(1)); |
160 assertEquals(12, g2(1, 2, 3)); | 164 assertEquals(12, g2(1, 2, 3)); |
161 assertEquals(19, g3(1)); | 165 assertEquals(19, g3(1)); |
162 assertEquals(12, g4(1)); | 166 assertEquals(12, g4(1)); |
163 } | 167 } |
164 test(); | 168 test(); |
| 169 test(); |
165 %OptimizeFunctionOnNextCall(test); | 170 %OptimizeFunctionOnNextCall(test); |
166 test(); | 171 test(); |
167 })(); | 172 })(); |
168 | 173 |
169 | 174 |
170 // Tail call bound function when caller has an arguments adaptor frame. | 175 // Tail call bound function when caller has an arguments adaptor frame. |
171 (function() { | 176 (function() { |
172 // Caller and callee have same number of arguments. | 177 // Caller and callee have same number of arguments. |
173 function f1(a) { | 178 function f1(a) { |
174 assertEquals(153, this.a); | 179 assertEquals(153, this.a); |
(...skipping 30 matching lines...) Expand all Loading... |
205 var b4 = f4.bind({a: 153}); | 210 var b4 = f4.bind({a: 153}); |
206 function g4(a) { return b4(2); } | 211 function g4(a) { return b4(2); } |
207 | 212 |
208 function test() { | 213 function test() { |
209 assertEquals(12, g1()); | 214 assertEquals(12, g1()); |
210 assertEquals(12, g2()); | 215 assertEquals(12, g2()); |
211 assertEquals(19, g3()); | 216 assertEquals(19, g3()); |
212 assertEquals(12, g4()); | 217 assertEquals(12, g4()); |
213 } | 218 } |
214 test(); | 219 test(); |
| 220 test(); |
215 %OptimizeFunctionOnNextCall(test); | 221 %OptimizeFunctionOnNextCall(test); |
216 test(); | 222 test(); |
217 })(); | 223 })(); |
218 | 224 |
219 | 225 |
220 // Tail calling via various expressions. | 226 // Tail calling via various expressions. |
221 (function() { | 227 (function() { |
222 function g1(a) { | 228 function g1(a) { |
223 return f([f, g1, test], false) || f([f, test], true); | 229 return f([f, g1, test], false) || f([f, test], true); |
224 } | 230 } |
225 | 231 |
226 function g2(a) { | 232 function g2(a) { |
227 return f([f, g2, test], true) && f([f, test], true); | 233 return f([f, g2, test], true) && f([f, test], true); |
228 } | 234 } |
229 | 235 |
230 function g3(a) { | 236 function g3(a) { |
231 return f([f, g3, test], 13), f([f, test], 153); | 237 return f([f, g3, test], 13), f([f, test], 153); |
232 } | 238 } |
233 | 239 |
234 function test() { | 240 function test() { |
235 assertEquals(true, g1()); | 241 assertEquals(true, g1()); |
236 assertEquals(true, g2()); | 242 assertEquals(true, g2()); |
237 assertEquals(153, g3()); | 243 assertEquals(153, g3()); |
238 } | 244 } |
239 test(); | 245 test(); |
| 246 test(); |
240 %OptimizeFunctionOnNextCall(test); | 247 %OptimizeFunctionOnNextCall(test); |
241 test(); | 248 test(); |
242 })(); | 249 })(); |
243 | 250 |
244 | 251 |
245 // Test tail calls from try-catch constructs. | 252 // Test tail calls from try-catch constructs. |
246 (function() { | 253 (function() { |
247 function tc1(a) { | 254 function tc1(a) { |
248 try { | 255 try { |
249 f_153([f_153, tc1, test]); | 256 f_153([f_153, tc1, test]); |
(...skipping 23 matching lines...) Expand all Loading... |
273 f_153([f_153, tc3, test]); | 280 f_153([f_153, tc3, test]); |
274 return f_153([f_153, test]); | 281 return f_153([f_153, test]); |
275 } | 282 } |
276 | 283 |
277 function test() { | 284 function test() { |
278 assertEquals(153, tc1()); | 285 assertEquals(153, tc1()); |
279 assertEquals(153, tc2()); | 286 assertEquals(153, tc2()); |
280 assertEquals(153, tc3()); | 287 assertEquals(153, tc3()); |
281 } | 288 } |
282 test(); | 289 test(); |
| 290 test(); |
283 %OptimizeFunctionOnNextCall(test); | 291 %OptimizeFunctionOnNextCall(test); |
284 test(); | 292 test(); |
285 })(); | 293 })(); |
286 | 294 |
287 | 295 |
288 // Test tail calls from try-finally constructs. | 296 // Test tail calls from try-finally constructs. |
289 (function() { | 297 (function() { |
290 function tf1(a) { | 298 function tf1(a) { |
291 try { | 299 try { |
292 f_153([f_153, tf1, test]); | 300 f_153([f_153, tf1, test]); |
(...skipping 21 matching lines...) Expand all Loading... |
314 } | 322 } |
315 return f_153([f_153, test]); | 323 return f_153([f_153, test]); |
316 } | 324 } |
317 | 325 |
318 function test() { | 326 function test() { |
319 assertEquals(153, tf1()); | 327 assertEquals(153, tf1()); |
320 assertEquals(153, tf2()); | 328 assertEquals(153, tf2()); |
321 assertEquals(153, tf3()); | 329 assertEquals(153, tf3()); |
322 } | 330 } |
323 test(); | 331 test(); |
| 332 test(); |
324 %OptimizeFunctionOnNextCall(test); | 333 %OptimizeFunctionOnNextCall(test); |
325 test(); | 334 test(); |
326 })(); | 335 })(); |
327 | 336 |
328 | 337 |
329 // Test tail calls from try-catch-finally constructs. | 338 // Test tail calls from try-catch-finally constructs. |
330 (function() { | 339 (function() { |
331 function tcf1(a) { | 340 function tcf1(a) { |
332 try { | 341 try { |
333 f_153([f_153, tcf1, test]); | 342 f_153([f_153, tcf1, test]); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 return f_153([f_153, test]); | 383 return f_153([f_153, test]); |
375 } | 384 } |
376 | 385 |
377 function test() { | 386 function test() { |
378 assertEquals(153, tcf1()); | 387 assertEquals(153, tcf1()); |
379 assertEquals(153, tcf2()); | 388 assertEquals(153, tcf2()); |
380 assertEquals(153, tcf3()); | 389 assertEquals(153, tcf3()); |
381 assertEquals(153, tcf4()); | 390 assertEquals(153, tcf4()); |
382 } | 391 } |
383 test(); | 392 test(); |
| 393 test(); |
384 %OptimizeFunctionOnNextCall(test); | 394 %OptimizeFunctionOnNextCall(test); |
385 test(); | 395 test(); |
386 })(); | 396 })(); |
OLD | NEW |