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 "); |
11 } | 11 } |
12 | 12 |
13 | 13 |
14 function CheckStackTrace(expected) { | 14 function CheckStackTrace(expected) { |
15 var e = new Error(); | 15 var e = new Error(); |
16 e.stack; // prepare stack trace | 16 e.stack; // prepare stack trace |
17 var stack = e.strace; | 17 var stack = e.strace; |
18 assertEquals("CheckStackTrace", stack[0].getFunctionName()); | 18 assertEquals("CheckStackTrace", stack[0].getFunctionName()); |
19 for (var i = 0; i < expected.length; i++) { | 19 for (var i = 0; i < expected.length; i++) { |
20 assertEquals(expected[i].name, stack[i + 1].getFunctionName()); | 20 assertEquals(expected[i].name, stack[i + 1].getFunctionName()); |
21 } | 21 } |
22 } | 22 } |
| 23 %NeverOptimizeFunction(CheckStackTrace); |
| 24 |
23 | 25 |
24 function f(expected_call_stack, a, b) { | 26 function f(expected_call_stack, a, b) { |
25 CheckStackTrace(expected_call_stack); | 27 CheckStackTrace(expected_call_stack); |
26 return a; | 28 return a; |
27 } | 29 } |
28 | 30 |
29 function f_153(expected_call_stack, a) { | 31 function f_153(expected_call_stack, a) { |
30 CheckStackTrace(expected_call_stack); | 32 CheckStackTrace(expected_call_stack); |
31 return 153; | 33 return 153; |
32 } | 34 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 assertEquals(19, g3()); | 216 assertEquals(19, g3()); |
215 assertEquals(12, g4()); | 217 assertEquals(12, g4()); |
216 } | 218 } |
217 test(); | 219 test(); |
218 test(); | 220 test(); |
219 %OptimizeFunctionOnNextCall(test); | 221 %OptimizeFunctionOnNextCall(test); |
220 test(); | 222 test(); |
221 })(); | 223 })(); |
222 | 224 |
223 | 225 |
| 226 // Tail calling from getter. |
| 227 (function() { |
| 228 function g(v) { |
| 229 CheckStackTrace([g, test]); |
| 230 %DeoptimizeFunction(test); |
| 231 return 153; |
| 232 } |
| 233 %NeverOptimizeFunction(g); |
| 234 |
| 235 function f(v) { |
| 236 return g(); |
| 237 } |
| 238 %SetForceInlineFlag(f); |
| 239 |
| 240 function test() { |
| 241 var o = {}; |
| 242 o.__defineGetter__('p', f); |
| 243 assertEquals(153, o.p); |
| 244 } |
| 245 |
| 246 test(); |
| 247 test(); |
| 248 %OptimizeFunctionOnNextCall(test); |
| 249 test(); |
| 250 })(); |
| 251 |
| 252 |
| 253 // Tail calling from setter. |
| 254 (function() { |
| 255 function g() { |
| 256 CheckStackTrace([g, test]); |
| 257 %DeoptimizeFunction(test); |
| 258 return 153; |
| 259 } |
| 260 %NeverOptimizeFunction(g); |
| 261 |
| 262 var context = 10; |
| 263 function f(v) { |
| 264 return g(context); |
| 265 } |
| 266 %SetForceInlineFlag(f); |
| 267 |
| 268 function test() { |
| 269 var o = {}; |
| 270 o.__defineSetter__('q', f); |
| 271 assertEquals(1, o.q = 1); |
| 272 } |
| 273 |
| 274 test(); |
| 275 test(); |
| 276 %OptimizeFunctionOnNextCall(test); |
| 277 test(); |
| 278 })(); |
| 279 |
| 280 |
| 281 // Tail calling from constructor. |
| 282 (function() { |
| 283 function g(context) { |
| 284 CheckStackTrace([g, test]); |
| 285 %DeoptimizeFunction(test); |
| 286 return {x: 153}; |
| 287 } |
| 288 %NeverOptimizeFunction(g); |
| 289 |
| 290 function A() { |
| 291 this.x = 42; |
| 292 return g(); |
| 293 } |
| 294 |
| 295 function test() { |
| 296 var o = new A(); |
| 297 %DebugPrint(o); |
| 298 assertEquals(153, o.x); |
| 299 } |
| 300 |
| 301 test(); |
| 302 test(); |
| 303 %OptimizeFunctionOnNextCall(test); |
| 304 test(); |
| 305 })(); |
| 306 |
| 307 |
224 // Tail calling via various expressions. | 308 // Tail calling via various expressions. |
225 (function() { | 309 (function() { |
226 function g1(a) { | 310 function g1(a) { |
227 return f([f, g1, test], false) || f([f, test], true); | 311 return f([f, g1, test], false) || f([f, test], true); |
228 } | 312 } |
229 | 313 |
230 function g2(a) { | 314 function g2(a) { |
231 return f([f, g2, test], true) && f([f, test], true); | 315 return f([f, g2, test], true) && f([f, test], true); |
232 } | 316 } |
233 | 317 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 536 |
453 function test() { | 537 function test() { |
454 assertEquals(153, g1()); | 538 assertEquals(153, g1()); |
455 assertEquals(153, g2()); | 539 assertEquals(153, g2()); |
456 } | 540 } |
457 test(); | 541 test(); |
458 test(); | 542 test(); |
459 %OptimizeFunctionOnNextCall(test); | 543 %OptimizeFunctionOnNextCall(test); |
460 test(); | 544 test(); |
461 })(); | 545 })(); |
OLD | NEW |