OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --allow-natives-syntax | |
6 | |
7 // Ensure `Array.prototype.includes` functions correctly for numerous elements | |
8 // kinds, and various exotic receiver types, | |
9 | |
10 // TODO(caitp): update kIterCount to a high enough number to trigger inlining, | |
11 // once inlining this builtin is supported | |
12 var kIterCount = 1; | |
13 var kTests = { | |
14 Array: { | |
15 FAST_ELEMENTS() { | |
16 var r = /foo/; | |
17 var s = new String("bar"); | |
18 var p = new Proxy({}, {}); | |
19 var o = {}; | |
20 | |
21 var array = [r, s, p]; | |
22 assertTrue(%HasFastObjectElements(array)); | |
23 assertFalse(%HasFastHoleyElements(array)); | |
24 | |
25 for (var i = 0; i < kIterCount; ++i) { | |
26 assertTrue(array.includes(p)); | |
27 assertFalse(array.includes(o)); | |
28 } | |
29 }, | |
30 | |
31 FAST_HOLEY_ELEMENTS() { | |
32 var r = /foo/; | |
33 var p = new Proxy({}, {}); | |
34 var o = {}; | |
35 | |
36 var array = [r, , p]; | |
37 assertTrue(%HasFastObjectElements(array)); | |
38 assertTrue(%HasFastHoleyElements(array)); | |
39 | |
40 for (var i = 0; i < kIterCount; ++i) { | |
41 assertTrue(array.includes(p)); | |
42 assertFalse(array.includes(o)); | |
43 } | |
44 }, | |
45 | |
46 FAST_SMI_ELEMENTS() { | |
47 var array = [0, 88, 9999, 1, -5, 7]; | |
48 assertTrue(%HasFastSmiElements(array)); | |
49 assertFalse(%HasFastHoleyElements(array)); | |
50 | |
51 for (var i = 0; i < kIterCount; ++i) { | |
52 assertTrue(array.includes(9999)); | |
53 assertTrue(array.includes(-5)); | |
54 assertFalse(array.includes(-5.00001)); | |
55 assertFalse(array.includes(undefined)); | |
56 assertFalse(array.includes(NaN)); | |
57 } | |
58 }, | |
59 | |
60 FAST_HOLEY_SMI_ELEMENTS() { | |
61 var array = [49, , , 72, , , 67, -48]; | |
62 assertTrue(%HasFastSmiElements(array)); | |
63 assertTrue(%HasFastHoleyElements(array)); | |
64 | |
65 for (var i = 0; i < kIterCount; ++i) { | |
66 assertTrue(array.includes(72)); | |
67 assertTrue(array.includes(-48)); | |
68 assertFalse(array.includes(72, 4)); | |
69 assertTrue(array.includes(undefined)); | |
70 assertFalse(array.includes(undefined, -2)); | |
71 assertFalse(array.includes(NaN)); | |
72 } | |
73 }, | |
74 | |
75 FAST_DOUBLE_ELEMENTS() { | |
76 var array = [7.00000001, -13000.89412, 73451.4124, | |
77 5824.48, 6.0000495, 48.3488, 44.0, 76.35, NaN, 78.4]; | |
78 assertTrue(%HasFastDoubleElements(array)); | |
79 assertFalse(%HasFastHoleyElements(array)); | |
80 | |
81 for (var i = 0; i < kIterCount; ++i) { | |
82 assertTrue(array.includes(7.00000001)); | |
83 assertFalse(array.includes(7.00000001, 2)); | |
84 assertTrue(array.includes(NaN)); | |
85 assertFalse(array.includes(NaN, -1)); | |
86 assertTrue(array.includes(-13000.89412)); | |
87 assertFalse(array.includes(-13000.89412, -2)); | |
88 assertFalse(array.includes(undefined)); | |
89 } | |
90 }, | |
91 | |
92 FAST_HOLEY_DOUBLE_ELEMENTS() { | |
93 var array = [7.00000001, -13000.89412, , | |
94 5824.48, , 48.3488, , NaN, , 78.4]; | |
95 assertTrue(%HasFastDoubleElements(array)); | |
96 assertTrue(%HasFastHoleyElements(array)); | |
97 | |
98 for (var i = 0; i < kIterCount; ++i) { | |
99 assertTrue(array.includes(7.00000001)); | |
100 assertFalse(array.includes(7.00000001, 2)); | |
101 assertTrue(array.includes(NaN)); | |
102 assertFalse(array.includes(NaN, -2)); | |
103 assertTrue(array.includes(-13000.89412)); | |
104 assertFalse(array.includes(-13000.89412, -2)); | |
105 assertTrue(array.includes(undefined, -2)); | |
106 assertFalse(array.includes(undefined, -1)); | |
107 } | |
108 }, | |
109 | |
110 DICTIONARY_ELEMENTS() { | |
111 var array = []; | |
112 Object.defineProperty(array, 4, { get() { return NaN; } }); | |
113 Object.defineProperty(array, 7, { value: Function }); | |
114 | |
115 assertTrue(%HasDictionaryElements(array)); | |
116 | |
117 for (var i = 0; i < kIterCount; ++i) { | |
118 assertTrue(array.includes(NaN)); | |
119 assertFalse(array.includes(NaN, -3)); | |
120 assertTrue(array.includes(Function)); | |
121 assertTrue(array.includes(undefined)); | |
122 assertFalse(array.includes(undefined, 7)); | |
123 } | |
124 }, | |
125 }, | |
126 | |
127 Object: { | |
128 FAST_ELEMENTS() { | |
129 var r = /foo/; | |
130 var s = new String("bar"); | |
131 var p = new Proxy({}, {}); | |
132 var o = {}; | |
133 | |
134 var object = { 0: r, 1: s, 2: p, length: 3 }; | |
135 assertTrue(%HasFastObjectElements(object)); | |
136 // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS | |
137 // assertFalse(%HasFastHoleyElements(object)); | |
138 | |
139 for (var i = 0; i < kIterCount; ++i) { | |
140 assertTrue(Array.prototype.includes.call(object, p)); | |
141 assertFalse(Array.prototype.includes.call(object, o)); | |
142 } | |
143 }, | |
144 | |
145 FAST_HOLEY_ELEMENTS() { | |
146 var r = /foo/; | |
147 var p = new Proxy({}, {}); | |
148 var o = {}; | |
149 | |
150 var object = { 0: r, 2: p, length: 3 }; | |
151 assertTrue(%HasFastObjectElements(object)); | |
152 assertTrue(%HasFastHoleyElements(object)); | |
153 | |
154 for (var i = 0; i < kIterCount; ++i) { | |
155 assertTrue(Array.prototype.includes.call(object, p)); | |
156 assertFalse(Array.prototype.includes.call(object, o)); | |
157 } | |
158 }, | |
159 | |
160 FAST_SMI_ELEMENTS() { | |
161 var object = { 0: 0, 1: 88, 2: 9999, 3: 1, 4: -5, 5: 7, length: 6 }; | |
162 // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS | |
163 // assertTrue(%HasFastSmiElements(object)); | |
164 // assertFalse(%HasFastHoleyElements(object)); | |
165 | |
166 for (var i = 0; i < kIterCount; ++i) { | |
167 assertTrue(Array.prototype.includes.call(object, 9999)); | |
168 assertTrue(Array.prototype.includes.call(object, -5)); | |
169 assertFalse(Array.prototype.includes.call(object, -5.00001)); | |
170 assertFalse(Array.prototype.includes.call(object, undefined)); | |
171 assertFalse(Array.prototype.includes.call(object, NaN)); | |
172 } | |
173 }, | |
174 | |
175 FAST_HOLEY_SMI_ELEMENTS() { | |
176 var object = { 0: 49, 3: 72, 6: 67, 7: -48, length: 8 }; | |
177 // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS | |
178 // assertTrue(%HasFastSmiElements(object)); | |
179 // assertTrue(%HasFastHoleyElements(object)); | |
180 | |
181 for (var i = 0; i < kIterCount; ++i) { | |
182 assertTrue(Array.prototype.includes.call(object, 72)); | |
183 assertTrue(Array.prototype.includes.call(object, -48)); | |
184 assertFalse(Array.prototype.includes.call(object, 72, 4)); | |
185 assertTrue(Array.prototype.includes.call(object, undefined)); | |
186 assertFalse(Array.prototype.includes.call(object, undefined, -2)); | |
187 assertFalse(Array.prototype.includes.call(object, NaN)); | |
188 } | |
189 }, | |
190 | |
191 FAST_DOUBLE_ELEMENTS() { | |
192 var object = { 0: 7.00000001, 1: -13000.89412, 2: 73451.4124, | |
193 3: 5824.48, 4: 6.0000495, 5: 48.3488, 6: 44.0, 7: 76.35, | |
194 8: NaN, 9: 78.4, length: 10 }; | |
195 // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS | |
196 // assertTrue(%HasFastDoubleElements(object)); | |
197 // assertFalse(%HasFastHoleyElements(object)); | |
198 | |
199 for (var i = 0; i < kIterCount; ++i) { | |
200 assertTrue(Array.prototype.includes.call(object, 7.00000001)); | |
201 assertFalse(Array.prototype.includes.call(object, 7.00000001, 2)); | |
202 assertTrue(Array.prototype.includes.call(object, NaN)); | |
203 assertFalse(Array.prototype.includes.call(object, NaN, -1)); | |
204 assertTrue(Array.prototype.includes.call(object, -13000.89412)); | |
205 assertFalse(Array.prototype.includes.call(object, -13000.89412, -2)); | |
206 assertFalse(Array.prototype.includes.call(object, undefined)); | |
207 } | |
208 }, | |
209 | |
210 FAST_HOLEY_DOUBLE_ELEMENTS() { | |
211 var object = { 0: 7.00000001, 1: -13000.89412, 3: 5824.48, 5: 48.3488, | |
212 7: NaN, 9: 78.4, length: 10 }; | |
213 // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS | |
214 // assertTrue(%HasFastDoubleElements(object)); | |
215 // assertTrue(%HasFastHoleyElements(object)); | |
216 | |
217 for (var i = 0; i < kIterCount; ++i) { | |
218 assertTrue(Array.prototype.includes.call(object, 7.00000001)); | |
219 assertFalse(Array.prototype.includes.call(object, 7.00000001, 2)); | |
220 assertTrue(Array.prototype.includes.call(object, NaN)); | |
221 assertFalse(Array.prototype.includes.call(object, NaN, -2)); | |
222 assertTrue(Array.prototype.includes.call(object, -13000.89412)); | |
223 assertFalse(Array.prototype.includes.call(object, -13000.89412, -2)); | |
224 assertTrue(Array.prototype.includes.call(object, undefined, -2)); | |
225 assertFalse(Array.prototype.includes.call(object, undefined, -1)); | |
226 } | |
227 }, | |
228 | |
229 DICTIONARY_ELEMENTS() { | |
230 var object = { length: 8 }; | |
231 Object.defineProperty(object, 4, { get() { return NaN; } }); | |
232 Object.defineProperty(object, 7, { value: Function }); | |
233 | |
234 assertTrue(%HasDictionaryElements(object)); | |
235 | |
236 for (var i = 0; i < kIterCount; ++i) { | |
237 assertTrue(Array.prototype.includes.call(object, NaN)); | |
238 assertFalse(Array.prototype.includes.call(object, NaN, -3)); | |
239 assertTrue(Array.prototype.includes.call(object, Function)); | |
240 assertTrue(Array.prototype.includes.call(object, undefined)); | |
241 assertFalse(Array.prototype.includes.call(object, undefined, 7)); | |
242 } | |
243 | |
244 (function prototypeModifiedDuringAccessor() { | |
245 function O() { | |
246 return { | |
247 __proto__: {}, | |
248 get 0() { | |
249 this.__proto__.__proto__ = { | |
250 get 1() { | |
251 this[2] = "c"; | |
252 return "b"; | |
253 } | |
254 }; | |
255 return "a"; | |
256 }, | |
257 length: 3 | |
258 }; | |
259 } | |
260 | |
261 // Switch to slow path when first accessor modifies the prototype | |
262 assertTrue(Array.prototype.includes.call(O(), "a")); | |
263 assertTrue(Array.prototype.includes.call(O(), "b")); | |
264 assertTrue(Array.prototype.includes.call(O(), "c")); | |
265 | |
266 // Avoid switching to slow path due to avoiding the accessor | |
267 assertFalse(Array.prototype.includes.call(O(), "c", 2)); | |
268 assertFalse(Array.prototype.includes.call(O(), "b", 1)); | |
269 assertTrue(Array.prototype.includes.call(O(), undefined, 1)); | |
270 }); | |
271 }, | |
272 }, | |
273 | |
274 String: { | |
275 FAST_STRING_ELEMENTS() { | |
276 for (var i = 0; i < kIterCount; ++i) { | |
277 assertTrue(Array.prototype.includes.call("froyo", "y")); | |
278 assertFalse(Array.prototype.includes.call("froyo", "y", -1)); | |
279 assertTrue(Array.prototype.includes.call("froyo", "y", -2)); | |
280 assertFalse(Array.prototype.includes.call("froyo", NaN)); | |
281 assertFalse(Array.prototype.includes.call("froyo", undefined)); | |
282 } | |
283 }, | |
284 | |
285 SLOW_STRING_ELEMENTS() { | |
286 var string = new String("froyo"); | |
287 | |
288 // Never accessible from A.p.includes as 'length' is not configurable | |
289 Object.defineProperty(string, 34, { value: NaN }); | |
290 Object.defineProperty(string, 12, { get() { return "nope" } }); | |
291 | |
292 for (var i = 0; i < kIterCount; ++i) { | |
293 assertTrue(Array.prototype.includes.call("froyo", "y")); | |
294 assertFalse(Array.prototype.includes.call("froyo", "y", -1)); | |
295 assertTrue(Array.prototype.includes.call("froyo", "y", -2)); | |
296 assertFalse(Array.prototype.includes.call(string, NaN)); | |
297 assertFalse(Array.prototype.includes.call(string, undefined)); | |
298 assertFalse(Array.prototype.includes.call(string, "nope")); | |
299 } | |
300 }, | |
301 }, | |
302 | |
303 Arguments: { | |
304 FAST_SLOPPY_ARGUMENTS_ELEMENTS() { | |
305 var args = (function(a, b) { return arguments; })("foo", NaN, "bar"); | |
306 assertTrue(%HasSloppyArgumentsElements(args)); | |
307 | |
308 for (var i = 0; i < kIterCount; ++i) { | |
309 assertFalse(Array.prototype.includes.call(args, undefined)); | |
310 assertTrue(Array.prototype.includes.call(args, NaN)); | |
311 assertFalse(Array.prototype.includes.call(args, NaN, -1)); | |
312 assertTrue(Array.prototype.includes.call(args, "bar", -1)); | |
313 } | |
314 }, | |
315 | |
316 SLOW_SLOPPY_ARGUMENTS_ELEMENTS() { | |
317 var args = (function(a, a) { return arguments; })("foo", NaN, "bar"); | |
318 Object.defineProperty(args, 3, { get() { return "silver"; } }); | |
319 Object.defineProperty(args, "length", { value: 4 }); | |
320 assertTrue(%HasSloppyArgumentsElements(args)); | |
321 | |
322 for (var i = 0; i < kIterCount; ++i) { | |
323 assertFalse(Array.prototype.includes.call(args, undefined)); | |
324 assertTrue(Array.prototype.includes.call(args, NaN)); | |
325 assertFalse(Array.prototype.includes.call(args, NaN, -2)); | |
326 assertTrue(Array.prototype.includes.call(args, "bar", -2)); | |
327 assertTrue(Array.prototype.includes.call(args, "silver", -1)); | |
328 } | |
329 } | |
330 }, | |
331 | |
332 TypedArray: { | |
333 Int8Array() { | |
334 var array = new Int8Array([-129, 128, | |
335 NaN /* 0 */, +0 /* 0 */, -0 /* 0 */, | |
336 +Infinity /* 0 */, -Infinity /* 0 */, | |
337 255 /* -1 */, 127 /* 127 */, -255 /* 1 */]); | |
338 assertFalse(Array.prototype.includes.call(array, -129)); | |
339 assertFalse(Array.prototype.includes.call(array, 128)); | |
340 | |
341 assertTrue(Array.prototype.includes.call(array, 0, 2)); | |
342 assertTrue(Array.prototype.includes.call(array, 0, 3)); | |
343 assertTrue(Array.prototype.includes.call(array, 0, 4)); | |
344 assertTrue(Array.prototype.includes.call(array, 0, 5)); | |
345 assertTrue(Array.prototype.includes.call(array, 0, 6)); | |
346 assertFalse(Array.prototype.includes.call(array, 0, 7)); | |
347 | |
348 assertTrue(Array.prototype.includes.call(array, -1, 7)); | |
349 assertFalse(Array.prototype.includes.call(array, -1, 8)); | |
350 | |
351 assertTrue(Array.prototype.includes.call(array, 127, 8)); | |
352 assertFalse(Array.prototype.includes.call(array, 127, 9)); | |
353 | |
354 assertTrue(Array.prototype.includes.call(array, 1, 9)); | |
355 }, | |
356 | |
357 Detached_Int8Array() { | |
358 var array = new Int8Array(10); | |
359 %ArrayBufferNeuter(array.buffer); | |
360 assertFalse(Array.prototype.includes.call(array, 0)); | |
361 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
362 }, | |
363 | |
364 Uint8Array() { | |
365 var array = new Uint8Array([-1, 256, | |
366 NaN /* 0 */, +0 /* 0 */, -0 /* 0 */, | |
367 +Infinity /* 0 */, -Infinity /* 0 */, | |
368 255 /* 255 */, 257 /* 1 */, -128 /* 128 */, | |
369 -2 /* 254 */]); | |
370 assertFalse(Array.prototype.includes.call(array, -1)); | |
371 assertFalse(Array.prototype.includes.call(array, 256)); | |
372 | |
373 assertTrue(Array.prototype.includes.call(array, 0, 2)); | |
374 assertTrue(Array.prototype.includes.call(array, 0, 3)); | |
375 assertTrue(Array.prototype.includes.call(array, 0, 4)); | |
376 assertTrue(Array.prototype.includes.call(array, 0, 5)); | |
377 assertTrue(Array.prototype.includes.call(array, 0, 6)); | |
378 assertFalse(Array.prototype.includes.call(array, 0, 7)); | |
379 | |
380 assertTrue(Array.prototype.includes.call(array, 255, 7)); | |
381 assertFalse(Array.prototype.includes.call(array, 255, 8)); | |
382 | |
383 assertTrue(Array.prototype.includes.call(array, 1, 8)); | |
384 assertFalse(Array.prototype.includes.call(array, 1, 9)); | |
385 | |
386 assertTrue(Array.prototype.includes.call(array, 128, 9)); | |
387 assertFalse(Array.prototype.includes.call(array, 128, 10)); | |
388 | |
389 assertTrue(Array.prototype.includes.call(array, 254, 10)); | |
390 }, | |
391 | |
392 Detached_Uint8Array() { | |
393 var array = new Uint8Array(10); | |
394 %ArrayBufferNeuter(array.buffer); | |
395 assertFalse(Array.prototype.includes.call(array, 0)); | |
396 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
397 }, | |
398 | |
399 Uint8ClampedArray() { | |
400 var array = new Uint8ClampedArray([-1 /* 0 */, NaN /* 0 */, 256 /* 255 */, | |
401 127.6 /* 128 */, 127.4 /* 127 */, | |
402 121.5 /* 122 */, 124.5 /* 124 */]); | |
403 assertFalse(Array.prototype.includes.call(array, -1)); | |
404 assertFalse(Array.prototype.includes.call(array, 256)); | |
405 | |
406 assertTrue(Array.prototype.includes.call(array, 0)); | |
407 assertTrue(Array.prototype.includes.call(array, 0, 1)); | |
408 assertTrue(Array.prototype.includes.call(array, 255, 2)); | |
409 | |
410 assertTrue(Array.prototype.includes.call(array, 128, 3)); | |
411 assertFalse(Array.prototype.includes.call(array, 128, 4)); | |
412 | |
413 assertTrue(Array.prototype.includes.call(array, 127, 4)); | |
414 assertFalse(Array.prototype.includes.call(array, 127, 5)); | |
415 | |
416 assertTrue(Array.prototype.includes.call(array, 122, 5)); | |
417 assertFalse(Array.prototype.includes.call(array, 122, 6)); | |
418 | |
419 assertTrue(Array.prototype.includes.call(array, 124, 6)); | |
420 }, | |
421 | |
422 Detached_Uint8ClampedArray() { | |
423 var array = new Uint8ClampedArray(10); | |
424 %ArrayBufferNeuter(array.buffer); | |
425 assertFalse(Array.prototype.includes.call(array, 0)); | |
426 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
427 }, | |
428 | |
429 Int16Array() { | |
430 var array = new Int16Array([-32769, 32768, | |
431 NaN /* 0 */, Infinity /* 0 */, | |
432 -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, | |
433 0x7FFFF /* -1 */, 30000 /* 30000 */, | |
434 300000 /* -27680 */]); | |
435 assertFalse(Array.prototype.includes.call(array, -32769)); | |
436 assertFalse(Array.prototype.includes.call(array, 32768)); | |
437 | |
438 assertTrue(Array.prototype.includes.call(array, 0, 2)); | |
439 assertTrue(Array.prototype.includes.call(array, 0, 3)); | |
440 assertTrue(Array.prototype.includes.call(array, 0, 4)); | |
441 assertTrue(Array.prototype.includes.call(array, 0, 5)); | |
442 assertTrue(Array.prototype.includes.call(array, 0, 6)); | |
443 assertFalse(Array.prototype.includes.call(array, 0, 7)); | |
444 | |
445 assertTrue(Array.prototype.includes.call(array, -1, 7)); | |
446 assertFalse(Array.prototype.includes.call(array, -1, 8)); | |
447 | |
448 assertTrue(Array.prototype.includes.call(array, 30000, 8)); | |
449 assertFalse(Array.prototype.includes.call(array, 30000, 9)); | |
450 | |
451 assertTrue(Array.prototype.includes.call(array, -27680, 9)); | |
452 }, | |
453 | |
454 Detached_Int16Array() { | |
455 var array = new Int16Array(10); | |
456 %ArrayBufferNeuter(array.buffer); | |
457 assertFalse(Array.prototype.includes.call(array, 0)); | |
458 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
459 }, | |
460 | |
461 Uint16Array() { | |
462 var array = new Uint16Array([-1, 65536, | |
463 NaN /* 0 */, Infinity /* 0 */, | |
464 -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, | |
465 0x7FFFF /* 65535 */, 300000 /* 37856 */, | |
466 3000000 /* 50880 */]); | |
467 assertFalse(Array.prototype.includes.call(array, -1)); | |
468 assertFalse(Array.prototype.includes.call(array, 65536)); | |
469 | |
470 assertTrue(Array.prototype.includes.call(array, 0, 2)); | |
471 assertTrue(Array.prototype.includes.call(array, 0, 3)); | |
472 assertTrue(Array.prototype.includes.call(array, 0, 4)); | |
473 assertTrue(Array.prototype.includes.call(array, 0, 5)); | |
474 assertTrue(Array.prototype.includes.call(array, 0, 6)); | |
475 assertFalse(Array.prototype.includes.call(array, 0, 7)); | |
476 | |
477 assertTrue(Array.prototype.includes.call(array, 65535, 7)); | |
478 assertFalse(Array.prototype.includes.call(array, 65535, 8)); | |
479 | |
480 assertTrue(Array.prototype.includes.call(array, 37856, 8)); | |
481 assertFalse(Array.prototype.includes.call(array, 37856, 9)); | |
482 | |
483 assertTrue(Array.prototype.includes.call(array, 50880, 9)); | |
484 }, | |
485 | |
486 Detached_Uint16Array() { | |
487 var array = new Uint16Array(10); | |
488 %ArrayBufferNeuter(array.buffer); | |
489 assertFalse(Array.prototype.includes.call(array, 0)); | |
490 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
491 }, | |
492 | |
493 Int32Array() { | |
494 var array = new Int32Array([-2147483649, 2147483648, | |
495 NaN /* 0 */, Infinity /* 0 */, | |
496 -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, | |
497 0x7FFFFFFFF /* -1 */, 4294968064 /* 768 */, | |
498 4294959447 /* -7849 */]); | |
499 assertFalse(Array.prototype.includes.call(array, -2147483649)); | |
500 assertFalse(Array.prototype.includes.call(array, 2147483648)); | |
501 | |
502 assertTrue(Array.prototype.includes.call(array, 0.0, 2)); | |
503 assertTrue(Array.prototype.includes.call(array, 0.0, 3)); | |
504 assertTrue(Array.prototype.includes.call(array, 0, 4)); | |
505 assertTrue(Array.prototype.includes.call(array, 0, 5)); | |
506 assertTrue(Array.prototype.includes.call(array, 0.0, 6)); | |
507 assertFalse(Array.prototype.includes.call(array, 0.0, 7)); | |
508 | |
509 assertTrue(Array.prototype.includes.call(array, -1, 7)); | |
510 assertFalse(Array.prototype.includes.call(array, -1, 8)); | |
511 | |
512 assertTrue(Array.prototype.includes.call(array, 768, 8)); | |
513 assertFalse(Array.prototype.includes.call(array, 768, 9)); | |
514 | |
515 assertTrue(Array.prototype.includes.call(array, -7849, 9)); | |
516 }, | |
517 | |
518 Detached_Int32Array() { | |
519 var array = new Int32Array(10); | |
520 %ArrayBufferNeuter(array.buffer); | |
521 assertFalse(Array.prototype.includes.call(array, 0)); | |
522 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
523 }, | |
524 | |
525 Uint32Array() { | |
526 var array = new Uint32Array([-1, 4294967296, | |
527 NaN /* 0 */, Infinity /* 0 */, | |
528 -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, | |
529 0x7FFFFFFFF /* 4294967295 */, | |
530 4294968064 /* 768 */, | |
531 4295079447 /* 112151 */]); | |
532 assertFalse(Array.prototype.includes.call(array, -1)); | |
533 assertFalse(Array.prototype.includes.call(array, 4294967296)); | |
534 | |
535 assertTrue(Array.prototype.includes.call(array, 0.0, 2)); | |
536 assertTrue(Array.prototype.includes.call(array, 0.0, 3)); | |
537 assertTrue(Array.prototype.includes.call(array, 0, 4)); | |
538 assertTrue(Array.prototype.includes.call(array, 0, 5)); | |
539 assertTrue(Array.prototype.includes.call(array, 0.0, 6)); | |
540 assertFalse(Array.prototype.includes.call(array, 0.0, 7)); | |
541 | |
542 assertTrue(Array.prototype.includes.call(array, 4294967295, 7)); | |
543 assertFalse(Array.prototype.includes.call(array, 4294967295, 8)); | |
544 | |
545 assertTrue(Array.prototype.includes.call(array, 768, 8)); | |
546 assertFalse(Array.prototype.includes.call(array, 768, 9)); | |
547 | |
548 assertTrue(Array.prototype.includes.call(array, 112151, 9)); | |
549 }, | |
550 | |
551 Detached_Uint32Array() { | |
552 var array = new Uint32Array(10); | |
553 %ArrayBufferNeuter(array.buffer); | |
554 assertFalse(Array.prototype.includes.call(array, 0)); | |
555 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
556 }, | |
557 | |
558 Float32Array() { | |
559 var array = new Float32Array([-1, 4294967296, | |
560 NaN, Infinity /* 0 */, | |
561 -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, | |
562 0x7FFFFFFFF /* 34359738368.0 */, | |
563 -4294968064 /* -4294968320.0 */, | |
564 4295079447 /* 4295079424.0 */]); | |
565 assertTrue(Array.prototype.includes.call(array, -1.0)); | |
566 assertTrue(Array.prototype.includes.call(array, 4294967296)); | |
567 | |
568 assertTrue(Array.prototype.includes.call(array, NaN, 2)); | |
569 assertTrue(Array.prototype.includes.call(array, Infinity, 3)); | |
570 assertTrue(Array.prototype.includes.call(array, -Infinity, 4)); | |
571 assertTrue(Array.prototype.includes.call(array, 0, 5)); | |
572 assertTrue(Array.prototype.includes.call(array, 0, 6)); | |
573 assertFalse(Array.prototype.includes.call(array, 0.0, 7)); | |
574 | |
575 assertTrue(Array.prototype.includes.call(array, 34359738368.0, 7)); | |
576 assertFalse(Array.prototype.includes.call(array, 34359738368.0, 8)); | |
577 | |
578 assertTrue(Array.prototype.includes.call(array, -4294968320.0, 8)); | |
579 assertFalse(Array.prototype.includes.call(array, -4294968320.0, 9)); | |
580 | |
581 assertTrue(Array.prototype.includes.call(array, 4295079424.0, 9)); | |
582 }, | |
583 | |
584 Detached_Float32Array() { | |
585 var array = new Float32Array(10); | |
586 %ArrayBufferNeuter(array.buffer); | |
587 assertFalse(Array.prototype.includes.call(array, 0)); | |
588 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
589 }, | |
590 | |
591 Float64Array() { | |
592 var array = new Float64Array([-1, 4294967296, | |
593 NaN, Infinity /* 0 */, | |
594 -Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */, | |
595 0x7FFFFFFFF /* 34359738367.0 */, | |
596 -4294968064 /* -4294968064.0 */, | |
597 4295079447 /* 4295079447.0 */]); | |
598 assertTrue(Array.prototype.includes.call(array, -1.0)); | |
599 assertTrue(Array.prototype.includes.call(array, 4294967296)); | |
600 | |
601 assertTrue(Array.prototype.includes.call(array, NaN, 2)); | |
602 assertTrue(Array.prototype.includes.call(array, Infinity, 3)); | |
603 assertTrue(Array.prototype.includes.call(array, -Infinity, 4)); | |
604 assertTrue(Array.prototype.includes.call(array, 0, 5)); | |
605 assertTrue(Array.prototype.includes.call(array, 0, 6)); | |
606 assertFalse(Array.prototype.includes.call(array, 0.0, 7)); | |
607 | |
608 assertTrue(Array.prototype.includes.call(array, 34359738367.0, 7)); | |
609 assertFalse(Array.prototype.includes.call(array, 34359738367.0, 8)); | |
610 | |
611 assertTrue(Array.prototype.includes.call(array, -4294968064.0, 8)); | |
612 assertFalse(Array.prototype.includes.call(array, -4294968064.0, 9)); | |
613 | |
614 assertTrue(Array.prototype.includes.call(array, 4295079447.0, 9)); | |
615 }, | |
616 | |
617 Detached_Float64Array() { | |
618 var array = new Float32Array(10); | |
619 %ArrayBufferNeuter(array.buffer); | |
Dan Ehrenberg
2016/08/01 21:50:23
FWIW this is spec-non-compliant behavior; a TODO (
caitp
2016/08/01 21:57:35
It's actually perfectly spec-compliant, as far as
| |
620 assertFalse(Array.prototype.includes.call(array, 0)); | |
621 assertFalse(Array.prototype.includes.call(array, 0, 10)); | |
622 }, | |
623 } | |
624 }; | |
625 | |
626 function runSuites(suites) { | |
627 Object.keys(suites).forEach(suite => runSuite(suites[suite])); | |
628 | |
629 function runSuite(suite) { | |
630 Object.keys(suite).forEach(test => suite[test]()); | |
631 } | |
632 } | |
633 | |
634 runSuites(kTests); | |
OLD | NEW |