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 "use strict"; | 6 "use strict"; |
7 | 7 |
8 Error.prepareStackTrace = (error,stack) => { | 8 Error.prepareStackTrace = (error,stack) => { |
9 error.strace = stack; | 9 error.strace = stack; |
10 return error.message + "\n at " + stack.join("\n at "); | 10 return error.message + "\n at " + stack.join("\n at "); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 assertEquals(true, g2()); | 240 assertEquals(true, g2()); |
241 assertEquals(153, g3()); | 241 assertEquals(153, g3()); |
242 } | 242 } |
243 test(); | 243 test(); |
244 test(); | 244 test(); |
245 %OptimizeFunctionOnNextCall(test); | 245 %OptimizeFunctionOnNextCall(test); |
246 test(); | 246 test(); |
247 })(); | 247 })(); |
248 | 248 |
249 | 249 |
| 250 // Tail calling from various statements. |
| 251 (function() { |
| 252 function g1() { |
| 253 for (var v in {a:0}) { |
| 254 return f_153([f_153, g1, test]); |
| 255 } |
| 256 } |
| 257 |
| 258 function g2() { |
| 259 for (var v of [1, 2, 3]) { |
| 260 return f_153([f_153, g2, test]); |
| 261 } |
| 262 } |
| 263 |
| 264 function g3() { |
| 265 for (var i = 0; i < 10; i++) { |
| 266 return f_153([f_153, test]); |
| 267 } |
| 268 } |
| 269 |
| 270 function g4() { |
| 271 while (true) { |
| 272 return f_153([f_153, test]); |
| 273 } |
| 274 } |
| 275 |
| 276 function g5() { |
| 277 do { |
| 278 return f_153([f_153, test]); |
| 279 } while (true); |
| 280 } |
| 281 |
| 282 function test() { |
| 283 assertEquals(153, g1()); |
| 284 assertEquals(153, g2()); |
| 285 assertEquals(153, g3()); |
| 286 assertEquals(153, g4()); |
| 287 assertEquals(153, g5()); |
| 288 } |
| 289 test(); |
| 290 test(); |
| 291 %OptimizeFunctionOnNextCall(test); |
| 292 test(); |
| 293 })(); |
| 294 |
| 295 |
250 // Test tail calls from try-catch constructs. | 296 // Test tail calls from try-catch constructs. |
251 (function() { | 297 (function() { |
252 function tc1(a) { | 298 function tc1(a) { |
253 try { | 299 try { |
254 f_153([f_153, tc1, test]); | 300 f_153([f_153, tc1, test]); |
255 return f_153([f_153, tc1, test]); | 301 return f_153([f_153, tc1, test]); |
256 } catch(e) { | 302 } catch(e) { |
257 f_153([f_153, tc1, test]); | 303 f_153([f_153, tc1, test]); |
258 } | 304 } |
259 } | 305 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 452 |
407 function test() { | 453 function test() { |
408 assertEquals(153, g1()); | 454 assertEquals(153, g1()); |
409 assertEquals(153, g2()); | 455 assertEquals(153, g2()); |
410 } | 456 } |
411 test(); | 457 test(); |
412 test(); | 458 test(); |
413 %OptimizeFunctionOnNextCall(test); | 459 %OptimizeFunctionOnNextCall(test); |
414 test(); | 460 test(); |
415 })(); | 461 })(); |
OLD | NEW |