OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 assertTrue(%HasFastSmiElements(a3r)); | 144 assertTrue(%HasFastSmiElements(a3r)); |
145 assertTrue(%HasFastSmiElements(a3)); | 145 assertTrue(%HasFastSmiElements(a3)); |
146 assertEquals([], a3r); | 146 assertEquals([], a3r); |
147 assertEquals([2, 1, 2, 3], a3); | 147 assertEquals([2, 1, 2, 3], a3); |
148 a3 = [1,2,3]; | 148 a3 = [1,2,3]; |
149 a3r = a3.splice(0, 1, 2); | 149 a3r = a3.splice(0, 1, 2); |
150 assertTrue(%HasFastSmiElements(a3r)); | 150 assertTrue(%HasFastSmiElements(a3r)); |
151 assertTrue(%HasFastSmiElements(a3)); | 151 assertTrue(%HasFastSmiElements(a3)); |
152 assertEquals([1], a3r); | 152 assertEquals([1], a3r); |
153 assertEquals([2, 2, 3], a3); | 153 assertEquals([2, 2, 3], a3); |
| 154 |
154 a3 = [1.1,2,3]; | 155 a3 = [1.1,2,3]; |
155 a3r = a3.splice(0, 0); | 156 a3r = a3.splice(0, 0); |
156 assertTrue(%HasFastDoubleElements(a3r)); | 157 assertTrue(%HasFastDoubleElements(a3r)); |
157 assertTrue(%HasFastDoubleElements(a3)); | 158 assertTrue(%HasFastDoubleElements(a3)); |
158 assertEquals([], a3r); | 159 assertEquals([], a3r); |
159 assertEquals([1.1, 2, 3], a3); | 160 assertEquals([1.1, 2, 3], a3); |
160 a3 = [1.1,2,3]; | 161 a3 = [1.1,2,3]; |
161 a3r = a3.splice(0, 1); | 162 a3r = a3.splice(0, 1); |
162 assertTrue(%HasFastDoubleElements(a3r)); | 163 assertTrue(%HasFastDoubleElements(a3r)); |
163 assertTrue(%HasFastDoubleElements(a3)); | 164 assertTrue(%HasFastDoubleElements(a3)); |
164 assertEquals([1.1], a3r); | 165 assertEquals([1.1], a3r); |
165 assertEquals([2, 3], a3); | 166 assertEquals([2, 3], a3); |
166 a3 = [1.1,2,3]; | 167 a3 = [1.1,2,3]; |
167 a3r = a3.splice(0, 0, 2); | 168 a3r = a3.splice(0, 0, 2); |
168 assertTrue(%HasFastDoubleElements(a3r)); | 169 // Commented out since handled in js, which takes the best fit. |
| 170 // assertTrue(%HasFastDoubleElements(a3r)); |
| 171 assertTrue(%HasFastSmiElements(a3r)); |
169 assertTrue(%HasFastDoubleElements(a3)); | 172 assertTrue(%HasFastDoubleElements(a3)); |
170 assertEquals([], a3r); | 173 assertEquals([], a3r); |
171 assertEquals([2, 1.1, 2, 3], a3); | 174 assertEquals([2, 1.1, 2, 3], a3); |
172 a3 = [1.1,2,3]; | 175 a3 = [1.1,2,3]; |
173 assertTrue(%HasFastDoubleElements(a3)); | |
174 a3r = a3.splice(0, 1, 2); | 176 a3r = a3.splice(0, 1, 2); |
175 assertTrue(%HasFastDoubleElements(a3r)); | 177 assertTrue(%HasFastDoubleElements(a3r)); |
176 assertTrue(%HasFastDoubleElements(a3)); | 178 assertTrue(%HasFastDoubleElements(a3)); |
177 assertEquals([1.1], a3r); | 179 assertEquals([1.1], a3r); |
178 assertEquals([2, 2, 3], a3); | 180 assertEquals([2, 2, 3], a3); |
179 a3 = [1.1,2,3]; | 181 a3 = [1.1,2,3]; |
180 a3r = a3.splice(0, 0, 2.1); | 182 a3r = a3.splice(0, 0, 2.1); |
181 assertTrue(%HasFastDoubleElements(a3r)); | 183 // Commented out since handled in js, which takes the best fit. |
| 184 // assertTrue(%HasFastDoubleElements(a3r)); |
| 185 assertTrue(%HasFastSmiElements(a3r)); |
182 assertTrue(%HasFastDoubleElements(a3)); | 186 assertTrue(%HasFastDoubleElements(a3)); |
183 assertEquals([], a3r); | 187 assertEquals([], a3r); |
184 assertEquals([2.1, 1.1, 2, 3], a3); | 188 assertEquals([2.1, 1.1, 2, 3], a3); |
185 a3 = [1.1,2,3]; | 189 a3 = [1.1,2,3]; |
186 a3r = a3.splice(0, 1, 2.2); | 190 a3r = a3.splice(0, 1, 2.2); |
187 assertTrue(%HasFastDoubleElements(a3r)); | 191 assertTrue(%HasFastDoubleElements(a3r)); |
188 assertTrue(%HasFastDoubleElements(a3)); | 192 assertTrue(%HasFastDoubleElements(a3)); |
189 assertEquals([1.1], a3r); | 193 assertEquals([1.1], a3r); |
190 assertEquals([2.2, 2, 3], a3); | 194 assertEquals([2.2, 2, 3], a3); |
191 a3 = [1,2,3]; | 195 a3 = [1,2,3]; |
192 a3r = a3.splice(0, 0, 2.1); | 196 a3r = a3.splice(0, 0, 2.1); |
193 assertTrue(%HasFastDoubleElements(a3r)); | 197 // Commented out since handled in js, which takes the best fit. |
| 198 // assertTrue(%HasFastDoubleElements(a3r)); |
| 199 assertTrue(%HasFastSmiElements(a3r)); |
194 assertTrue(%HasFastDoubleElements(a3)); | 200 assertTrue(%HasFastDoubleElements(a3)); |
195 assertEquals([], a3r); | 201 assertEquals([], a3r); |
196 assertEquals([2.1, 1, 2, 3], a3); | 202 assertEquals([2.1, 1, 2, 3], a3); |
197 a3 = [1,2,3]; | 203 a3 = [1,2,3]; |
198 a3r = a3.splice(0, 1, 2.2); | 204 a3r = a3.splice(0, 1, 2.2); |
199 assertTrue(%HasFastDoubleElements(a3r)); | 205 assertTrue(%HasFastDoubleElements(a3r)); |
200 assertTrue(%HasFastDoubleElements(a3)); | 206 assertTrue(%HasFastDoubleElements(a3)); |
201 assertEquals([1], a3r); | 207 assertEquals([1], a3r); |
202 assertEquals([2.2, 2, 3], a3); | 208 assertEquals([2.2, 2, 3], a3); |
| 209 |
203 a3 = [{},2,3]; | 210 a3 = [{},2,3]; |
204 a3r = a3.splice(0, 0); | 211 a3r = a3.splice(0, 0); |
205 assertTrue(%HasFastObjectElements(a3r)); | 212 assertTrue(%HasFastObjectElements(a3r)); |
206 assertTrue(%HasFastObjectElements(a3)); | 213 assertTrue(%HasFastObjectElements(a3)); |
207 assertEquals([], a3r); | 214 assertEquals([], a3r); |
208 assertEquals([{}, 2, 3], a3); | 215 assertEquals([{}, 2, 3], a3); |
209 a3 = [1,2,{}]; | 216 a3 = [1,2,{}]; |
210 a3r = a3.splice(0, 1); | 217 a3r = a3.splice(0, 1); |
211 assertTrue(%HasFastObjectElements(a3r)); | 218 assertTrue(%HasFastObjectElements(a3r)); |
212 assertTrue(%HasFastObjectElements(a3)); | 219 assertTrue(%HasFastObjectElements(a3)); |
213 assertEquals([1], a3r); | 220 assertEquals([1], a3r); |
214 assertEquals([2, {}], a3); | 221 assertEquals([2, {}], a3); |
215 a3 = [1,2,3]; | 222 a3 = [1,2,3]; |
216 a3r = a3.splice(0, 0, {}); | 223 a3r = a3.splice(0, 0, {}); |
217 assertTrue(%HasFastObjectElements(a3r)); | 224 assertTrue(%HasFastObjectElements(a3r)); |
218 assertTrue(%HasFastObjectElements(a3)); | 225 assertTrue(%HasFastObjectElements(a3)); |
219 assertEquals([], a3r); | 226 assertEquals([], a3r); |
220 assertEquals([{}, 1, 2, 3], a3); | 227 assertEquals([{}, 1, 2, 3], a3); |
221 a3 = [1,2,3]; | 228 a3 = [1,2,3]; |
222 a3r = a3.splice(0, 1, {}); | 229 a3r = a3.splice(0, 1, {}); |
223 assertTrue(%HasFastObjectElements(a3r)); | 230 assertTrue(%HasFastObjectElements(a3r)); |
224 assertTrue(%HasFastObjectElements(a3)); | 231 assertTrue(%HasFastObjectElements(a3)); |
225 assertEquals([1], a3r); | 232 assertEquals([1], a3r); |
226 assertEquals([{}, 2, 3], a3); | 233 assertEquals([{}, 2, 3], a3); |
| 234 |
227 a3 = [1.1,2,3]; | 235 a3 = [1.1,2,3]; |
228 a3r = a3.splice(0, 0, {}); | 236 a3r = a3.splice(0, 0, {}); |
229 assertTrue(%HasFastObjectElements(a3r)); | 237 assertTrue(%HasFastObjectElements(a3r)); |
230 assertTrue(%HasFastObjectElements(a3)); | 238 assertTrue(%HasFastObjectElements(a3)); |
231 assertEquals([], a3r); | 239 assertEquals([], a3r); |
232 assertEquals([{}, 1.1, 2, 3], a3); | 240 assertEquals([{}, 1.1, 2, 3], a3); |
233 a3 = [1.1,2,3]; | 241 a3 = [1.1,2,3]; |
234 a3r = a3.splice(0, 1, {}); | 242 a3r = a3.splice(0, 1, {}); |
235 assertTrue(%HasFastObjectElements(a3r)); | 243 assertTrue(%HasFastObjectElements(a3r)); |
236 assertTrue(%HasFastObjectElements(a3)); | 244 assertTrue(%HasFastObjectElements(a3)); |
237 assertEquals([1.1], a3r); | 245 assertEquals([1.1], a3r); |
238 assertEquals([{}, 2, 3], a3); | 246 assertEquals([{}, 2, 3], a3); |
239 // Splice large objects | |
240 var a3 = new Array(1024 * 1024); | |
241 a3[1024*1024-1] = 1; | |
242 var a3r; | |
243 a3r = a3.splice(-1, 1); | |
244 assertTrue(%HasFastSmiElements(a3r)); | |
245 assertTrue(%HasFastSmiElements(a3)); | |
246 assertEquals([1], a3r); | |
247 assertEquals(new Array(1024 * 1024 - 1), a3); | |
248 var a3 = new Array(1024 * 1024); | |
249 a3[0] = 1; | |
250 var a3r; | |
251 a3r = a3.splice(0, 1); | |
252 assertTrue(%HasFastSmiElements(a3r)); | |
253 assertTrue(%HasFastSmiElements(a3)); | |
254 assertEquals([1], a3r); | |
255 assertEquals(new Array(1024 * 1024 - 1), a3); | |
256 // Splice array with large enough backing store | |
257 a3 = [1.1, 2.2, 3.3]; | |
258 a3r = a3.splice(2, 1); | |
259 assertTrue(%HasFastDoubleElements(a3r)); | |
260 assertTrue(%HasFastDoubleElements(a3)); | |
261 assertEquals([3.3], a3r); | |
262 assertEquals([1.1, 2.2], a3); | |
263 a3r = a3.splice(1, 1, 4.4, 5.5); | |
264 assertTrue(%HasFastDoubleElements(a3r)); | |
265 assertTrue(%HasFastDoubleElements(a3)); | |
266 assertEquals([2.2], a3r); | |
267 assertEquals([1.1, 4.4, 5.5], a3); | |
268 | 247 |
269 // Pop | 248 // Pop |
270 var a4 = [1,2,3]; | 249 var a4 = [1,2,3]; |
271 assertEquals(3, a4.pop()); | 250 assertEquals(3, a4.pop()); |
272 assertTrue(%HasFastSmiElements(a4)); | 251 assertTrue(%HasFastSmiElements(a4)); |
273 a4 = [1.1,2,3]; | 252 a4 = [1.1,2,3]; |
274 assertEquals(3, a4.pop()); | 253 assertEquals(3, a4.pop()); |
275 assertTrue(%HasFastDoubleElements(a4)); | 254 assertTrue(%HasFastDoubleElements(a4)); |
276 a4 = [{},2,3]; | 255 a4 = [{},2,3]; |
277 assertEquals(3, a4.pop()); | 256 assertEquals(3, a4.pop()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 a4.unshift(1.1); | 288 a4.unshift(1.1); |
310 assertTrue(%HasFastObjectElements(a4)); | 289 assertTrue(%HasFastObjectElements(a4)); |
311 assertEquals([1.1,{},2,3], a4); | 290 assertEquals([1.1,{},2,3], a4); |
312 } | 291 } |
313 | 292 |
314 for (var i = 0; i < 3; i++) { | 293 for (var i = 0; i < 3; i++) { |
315 array_natives_test(); | 294 array_natives_test(); |
316 } | 295 } |
317 %OptimizeFunctionOnNextCall(array_natives_test); | 296 %OptimizeFunctionOnNextCall(array_natives_test); |
318 array_natives_test(); | 297 array_natives_test(); |
OLD | NEW |