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) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 assertEquals(test4(1, 2, 3), 6); | 89 assertEquals(test4(1, 2, 3), 6); |
90 })(); | 90 })(); |
91 | 91 |
92 (function ArgumentsAccessStrict () { | 92 (function ArgumentsAccessStrict () { |
93 "use strict" | 93 "use strict" |
94 function sum1(a,b,c) { | 94 function sum1(a,b,c) { |
95 var sum = 0; | 95 var sum = 0; |
96 var rest = arguments; | 96 var rest = arguments; |
97 for (var i = 0; i < rest.length; ++i) { | 97 for (var i = 0; i < rest.length; ++i) { |
98 var j = i; | 98 var j = i; |
99 if (rest.length % 15 == 0 && i == 10) j += rest.length; | 99 if (rest.length % 15 == 0 && i == 10) j += 10000; |
100 sum += rest[j] || rest[j-rest.length]; | 100 sum += rest[j] || i+1; |
101 } | 101 } |
102 return sum; | 102 return sum; |
103 }; | 103 }; |
104 | 104 |
105 var args = [] | 105 var args = [] |
106 for (var i = 1; i < 30; ++i) { | 106 for (var i = 1; i < 30; ++i) { |
107 args.push(i); | 107 args.push(i); |
108 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum1); | 108 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum1); |
109 assertEquals(i*(i+1)/2, sum1(...args)); | 109 assertEquals(i*(i+1)/2, sum1(...args)); |
110 } | 110 } |
111 })(); | 111 })(); |
112 | 112 |
113 (function ArgumentsAccessSloppy () { | 113 (function ArgumentsAccessSloppy () { |
114 function sum2(a,b,c) { | 114 function sum2(a,b,c) { |
115 var sum = 0; | 115 var sum = 0; |
116 var rest = arguments; | 116 for (var i = 0; i < arguments.length; ++i) { |
117 for (var i = 0; i < rest.length; ++i) { | |
118 var j = i; | 117 var j = i; |
119 if (rest.length % 15 == 0 && i == 10) j += rest.length; | 118 if (arguments.length % 15 == 0 && i == 10) j += 10000; |
120 sum += rest[j] || rest[j-rest.length]; | 119 sum += arguments[j] || i+1; |
121 } | 120 } |
122 return sum; | 121 return sum; |
123 }; | 122 }; |
124 | 123 |
125 var args = [] | 124 var args = [] |
126 for (var i = 1; i < 30; ++i) { | 125 for (var i = 1; i < 30; ++i) { |
127 args.push(i); | 126 args.push(i); |
128 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum2); | 127 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum2); |
129 assertEquals(i*(i+1)/2, sum2(...args)); | 128 assertEquals(i*(i+1)/2, sum2(...args)); |
130 } | 129 } |
131 })(); | 130 })(); |
132 | 131 |
133 (function RestAccess0 () { | 132 (function RestAccess0 () { |
134 function sum3(...rest) { | 133 function sum3(...rest) { |
135 var sum = 0; | 134 var sum = 0; |
136 for (var i = 0; i < rest.length; ++i) { | 135 for (var i = 0; i < rest.length; ++i) { |
137 var j = i; | 136 var j = i; |
138 if (rest.length % 15 == 0 && i == 10) j += rest.length; | 137 if (rest.length % 15 == 0 && i == 10) j += 10000; |
139 sum += rest[j] || rest[j-rest.length]; | 138 sum += rest[j] || i+1; |
140 } | 139 } |
141 return sum; | 140 return sum; |
142 }; | 141 }; |
143 | 142 |
144 var args = [] | 143 var args = [] |
145 for (var i = 1; i < 30; ++i) { | 144 for (var i = 1; i < 30; ++i) { |
146 args.push(i); | 145 args.push(i); |
147 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum3); | 146 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum3); |
148 assertEquals(i*(i+1)/2, sum3(...args)); | 147 assertEquals(i*(i+1)/2, sum3(...args)); |
149 } | 148 } |
150 })(); | 149 })(); |
151 | 150 |
152 (function RestAccess1 () { | 151 (function RestAccess1 () { |
153 function sum4(a,...rest) { | 152 function sum4(a,...rest) { |
154 var sum = 0; | 153 var sum = 0; |
155 for (var i = 0; i < rest.length; ++i) { | 154 for (var i = 0; i < rest.length; ++i) { |
156 var j = i; | 155 var j = i; |
157 if (rest.length % 15 == 0 && i == 10) j += rest.length; | 156 if (rest.length % 15 == 0 && i == 10) j += 10000; |
158 sum += rest[j] || rest[j-rest.length]; | 157 sum += rest[j] || i+2; |
159 } | 158 } |
160 return sum; | 159 return sum; |
161 }; | 160 }; |
162 | 161 |
163 var args = [] | 162 var args = [] |
164 for (var i = 1; i < 30; ++i) { | 163 for (var i = 1; i < 30; ++i) { |
165 args.push(i); | 164 args.push(i); |
166 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum4); | 165 if (i%10 == 0) %OptimizeFunctionOnNextCall(sum4); |
167 assertEquals(i*(i+1)/2-1, sum4(...args)); | 166 assertEquals(i*(i+1)/2-1, sum4(...args)); |
168 } | 167 } |
169 })(); | 168 })(); |
| 169 |
| 170 |
| 171 (function ReadArguments () { |
| 172 function read() { |
| 173 if (arguments.length % 10 == 5) %DeoptimizeNow(); |
| 174 return arguments[arguments.length-1]; |
| 175 }; |
| 176 |
| 177 var args = [] |
| 178 for (var i = 1; i < 30; ++i) { |
| 179 args.push(i); |
| 180 if (i%10 == 0) %OptimizeFunctionOnNextCall(read); |
| 181 assertEquals(i, read(...args)); |
| 182 } |
| 183 })(); |
OLD | NEW |