OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax --nostress-opt --turbo |
| 6 |
| 7 var p0 = new Object(); |
| 8 var p1 = new Object(); |
| 9 var p2 = new Object(); |
| 10 |
| 11 // Ensure 1 parameter passed straight-through is handled correctly |
| 12 var count1 = 100000; |
| 13 tailee1 = function() { |
| 14 "use strict"; |
| 15 if (count1-- == 0) { |
| 16 return this; |
| 17 } |
| 18 return %_CallFunction(this, tailee1); |
| 19 }; |
| 20 |
| 21 %OptimizeFunctionOnNextCall(tailee1); |
| 22 assertEquals(p0, tailee1.call(p0)); |
| 23 |
| 24 // Ensure 2 parameters passed straight-through trigger a tail call are handled |
| 25 // correctly and don't cause a stack overflow. |
| 26 var count2 = 100000; |
| 27 tailee2 = function(px) { |
| 28 "use strict"; |
| 29 assertEquals(p2, px); |
| 30 assertEquals(p1, this); |
| 31 count2 = ((count2 | 0) - 1) | 0; |
| 32 if ((count2 | 0) === 0) { |
| 33 return this; |
| 34 } |
| 35 return %_CallFunction(this, px, tailee2); |
| 36 }; |
| 37 |
| 38 %OptimizeFunctionOnNextCall(tailee2); |
| 39 assertEquals(p1, tailee2.call(p1, p2)); |
| 40 |
| 41 // Ensure swapped 2 parameters don't trigger a tail call (parameter swizzling |
| 42 // for the tail call isn't supported yet). |
| 43 var count3 = 100000; |
| 44 tailee3 = function(px) { |
| 45 "use strict"; |
| 46 if (count3-- == 0) { |
| 47 return this; |
| 48 } |
| 49 return %_CallFunction(px, this, tailee3); |
| 50 }; |
| 51 |
| 52 %OptimizeFunctionOnNextCall(tailee3); |
| 53 assertThrows(function() { tailee3.call(p1, p2); }); |
| 54 |
| 55 // Ensure too many parameters defeats the tail call optimization (currently |
| 56 // unsupported). |
| 57 var count4 = 1000000; |
| 58 tailee4 = function(px) { |
| 59 "use strict"; |
| 60 if (count4-- == 0) { |
| 61 return this; |
| 62 } |
| 63 return %_CallFunction(this, px, undefined, tailee4); |
| 64 }; |
| 65 |
| 66 %OptimizeFunctionOnNextCall(tailee4); |
| 67 assertThrows(function() { tailee4.call(p1, p2); }); |
| 68 |
| 69 // Ensure too few parameters defeats the tail call optimization (currently |
| 70 // unsupported). |
| 71 var count5 = 1000000; |
| 72 tailee5 = function(px) { |
| 73 "use strict"; |
| 74 if (count5-- == 0) { |
| 75 return this; |
| 76 } |
| 77 return %_CallFunction(this, tailee5); |
| 78 }; |
| 79 |
| 80 %OptimizeFunctionOnNextCall(tailee5); |
| 81 assertThrows(function() { tailee5.call(p1, p2); }); |
OLD | NEW |