OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 --turbo | 5 // Flags: --allow-natives-syntax --turbo |
6 | 6 |
7 (function MaterializeStrictArguments() { | 7 (function MaterializeStrictArguments() { |
8 "use strict" | 8 "use strict" |
9 | 9 |
10 function f(x, y) { | 10 function f(x, y) { |
11 return x + y; | 11 return x + y; |
12 } | 12 } |
13 | 13 |
14 function test() { | 14 function test1() { |
15 %DeoptimizeNow(); | 15 %DeoptimizeNow(); |
16 return f.apply(null, arguments); | 16 return f.apply(null, arguments); |
17 } | 17 } |
18 | 18 |
19 assertEquals(test(1, 2), 3); | 19 assertEquals(test1(1, 2), 3); |
20 assertEquals(test(1, 2, 3), 3); | 20 assertEquals(test1(1, 2, 3), 3); |
21 | 21 |
22 %OptimizeFunctionOnNextCall(test); | 22 %OptimizeFunctionOnNextCall(test1); |
23 assertEquals(test(1, 2), 3); | 23 assertEquals(test1(1, 2), 3); |
24 %OptimizeFunctionOnNextCall(test); | 24 %OptimizeFunctionOnNextCall(test1); |
25 assertEquals(test(1, 2, 3), 3); | 25 assertEquals(test1(1, 2, 3), 3); |
26 })(); | 26 })(); |
27 | 27 |
28 (function MaterializeSloppyArguments() { | 28 (function MaterializeSloppyArguments() { |
29 function f(x, y) { | 29 function f(x, y) { |
30 return x + y; | 30 return x + y; |
31 } | 31 } |
32 | 32 |
33 function test() { | 33 function test2() { |
34 %DeoptimizeNow(); | 34 %DeoptimizeNow(); |
35 return f.apply(null, arguments); | 35 return f.apply(null, arguments); |
36 } | 36 } |
37 | 37 |
38 assertEquals(test(1, 2), 3); | 38 assertEquals(test2(1, 2), 3); |
39 assertEquals(test(1, 2, 3), 3); | 39 assertEquals(test2(1, 2, 3), 3); |
40 | 40 |
41 %OptimizeFunctionOnNextCall(test); | 41 %OptimizeFunctionOnNextCall(test2); |
42 assertEquals(test(1, 2), 3); | 42 assertEquals(test2(1, 2), 3); |
43 %OptimizeFunctionOnNextCall(test); | 43 %OptimizeFunctionOnNextCall(test2); |
44 assertEquals(test(1, 2, 3), 3); | 44 assertEquals(test2(1, 2, 3), 3); |
45 })(); | 45 })(); |
46 | 46 |
47 (function MaterializeStrictOverwrittenArguments() { | 47 (function MaterializeStrictOverwrittenArguments() { |
48 "use strict" | 48 "use strict" |
49 | 49 |
50 function f(x, y) { | 50 function f(x, y) { |
51 return x + y; | 51 return x + y; |
52 } | 52 } |
53 | 53 |
54 function test(a, b) { | 54 function test3(a, b) { |
55 a = 4; | 55 a = 4; |
56 %DeoptimizeNow(); | 56 %DeoptimizeNow(); |
57 return f.apply(null, arguments); | 57 return f.apply(null, arguments); |
58 } | 58 } |
59 | 59 |
60 assertEquals(test(1, 2), 3); | 60 assertEquals(test3(1, 2), 3); |
61 assertEquals(test(1, 2, 3), 3); | 61 assertEquals(test3(1, 2, 3), 3); |
62 | 62 |
63 %OptimizeFunctionOnNextCall(test); | 63 %OptimizeFunctionOnNextCall(test3); |
64 assertEquals(test(1, 2), 3); | 64 assertEquals(test3(11, 12), 23); |
65 %OptimizeFunctionOnNextCall(test); | 65 %OptimizeFunctionOnNextCall(test3); |
66 assertEquals(test(1, 2, 3), 3); | 66 assertEquals(test3(11, 12, 13), 23); |
67 })(); | 67 })(); |
68 | 68 |
69 (function MaterializeSloppyOverwrittenArguments() { | 69 (function MaterializeSloppyOverwrittenArguments() { |
70 function f(x, y) { | 70 function f(x, y) { |
71 return x + y; | 71 return x + y; |
72 } | 72 } |
73 | 73 |
74 function test(a, b) { | 74 function test4(a, b) { |
75 a = 4; | 75 a = 4; |
76 %DeoptimizeNow(); | 76 %DeoptimizeNow(); |
77 return f.apply(null, arguments); | 77 return f.apply(null, arguments); |
78 } | 78 } |
79 | 79 |
80 test(1, 2); | 80 test4(1, 2); |
81 test(3, 4, 5); | 81 test4(3, 4, 5); |
82 | 82 |
83 assertEquals(test(1, 2), 6); | 83 assertEquals(test4(1, 2), 6); |
84 assertEquals(test(1, 2, 3), 6); | 84 assertEquals(test4(1, 2, 3), 6); |
85 | 85 |
86 %OptimizeFunctionOnNextCall(test); | 86 %OptimizeFunctionOnNextCall(test4); |
87 assertEquals(test(1, 2), 6); | 87 assertEquals(test4(1, 2), 6); |
88 %OptimizeFunctionOnNextCall(test); | 88 %OptimizeFunctionOnNextCall(test4); |
89 assertEquals(test(1, 2, 3), 6); | 89 assertEquals(test4(1, 2, 3), 6); |
90 })(); | 90 })(); |
| 91 |
| 92 (function ArgumentsAccessStrict () { |
| 93 "use strict" |
| 94 function sum1(a,b,c) { |
| 95 var sum = 0; |
| 96 var rest = arguments; |
| 97 for (var i = 0; i < rest.length; ++i) { |
| 98 var j = i; |
| 99 if (rest.length % 15 == 0 && i == 10) j += rest.length; |
| 100 sum += rest[j] || rest[j-rest.length]; |
| 101 } |
| 102 return sum; |
| 103 }; |
| 104 |
| 105 var args = [] |
| 106 for (var i = 1; i < 30; ++i) { |
| 107 args.push(i); |
| 108 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum1); |
| 109 assertEquals(i*(i+1)/2, sum1(...args)); |
| 110 } |
| 111 })(); |
| 112 |
| 113 (function ArgumentsAccessSloppy () { |
| 114 function sum2(a,b,c) { |
| 115 var sum = 0; |
| 116 var rest = arguments; |
| 117 for (var i = 0; i < rest.length; ++i) { |
| 118 var j = i; |
| 119 if (rest.length % 15 == 0 && i == 10) j += rest.length; |
| 120 sum += rest[j] || rest[j-rest.length]; |
| 121 } |
| 122 return sum; |
| 123 }; |
| 124 |
| 125 var args = [] |
| 126 for (var i = 1; i < 30; ++i) { |
| 127 args.push(i); |
| 128 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum2); |
| 129 assertEquals(i*(i+1)/2, sum2(...args)); |
| 130 } |
| 131 })(); |
| 132 |
| 133 (function RestAccess0 () { |
| 134 function sum3(...rest) { |
| 135 var sum = 0; |
| 136 for (var i = 0; i < rest.length; ++i) { |
| 137 var j = i; |
| 138 if (rest.length % 15 == 0 && i == 10) j += rest.length; |
| 139 sum += rest[j] || rest[j-rest.length]; |
| 140 } |
| 141 return sum; |
| 142 }; |
| 143 |
| 144 var args = [] |
| 145 for (var i = 1; i < 30; ++i) { |
| 146 args.push(i); |
| 147 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum3); |
| 148 assertEquals(i*(i+1)/2, sum3(...args)); |
| 149 } |
| 150 })(); |
| 151 |
| 152 (function RestAccess1 () { |
| 153 function sum4(a,...rest) { |
| 154 var sum = 0; |
| 155 for (var i = 0; i < rest.length; ++i) { |
| 156 var j = i; |
| 157 if (rest.length % 15 == 0 && i == 10) j += rest.length; |
| 158 sum += rest[j] || rest[j-rest.length]; |
| 159 } |
| 160 return sum; |
| 161 }; |
| 162 |
| 163 var args = [] |
| 164 for (var i = 1; i < 30; ++i) { |
| 165 args.push(i); |
| 166 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum4); |
| 167 assertEquals(i*(i+1)/2-1, sum4(...args)); |
| 168 } |
| 169 })(); |
OLD | NEW |