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