| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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: --harmony-arrays | |
| 6 | |
| 7 var typedArrayConstructors = [ | |
| 8 Uint8Array, | |
| 9 Int8Array, | |
| 10 Uint16Array, | |
| 11 Int16Array, | |
| 12 Uint32Array, | |
| 13 Int32Array, | |
| 14 Uint8ClampedArray, | |
| 15 Float32Array, | |
| 16 Float64Array | |
| 17 ]; | |
| 18 | |
| 19 for (var constructor of typedArrayConstructors) { | |
| 20 var array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]); | |
| 21 | |
| 22 // ---------------------------------------------------------------------- | |
| 23 // %TypedArray%.prototype.indexOf. | |
| 24 // ---------------------------------------------------------------------- | |
| 25 | |
| 26 // Negative cases. | |
| 27 assertEquals(-1, new constructor([]).indexOf(1)); | |
| 28 assertEquals(-1, array.indexOf(4)); | |
| 29 assertEquals(-1, array.indexOf(3, array.length)); | |
| 30 | |
| 31 assertEquals(2, array.indexOf(3)); | |
| 32 // Negative index out of range. | |
| 33 assertEquals(0, array.indexOf(1, -17)); | |
| 34 // Negative index in rage. | |
| 35 assertEquals(3, array.indexOf(1, -11)); | |
| 36 // Index in range. | |
| 37 assertEquals(3, array.indexOf(1, 1)); | |
| 38 assertEquals(3, array.indexOf(1, 3)); | |
| 39 assertEquals(6, array.indexOf(1, 4)); | |
| 40 | |
| 41 // Basic TypedArray function properties | |
| 42 assertEquals(1, array.indexOf.length); | |
| 43 assertThrows(function(){ array.indexOf.call([1], 1); }, TypeError); | |
| 44 Object.defineProperty(array, 'length', {value: 1}); | |
| 45 assertEquals(array.indexOf(2), 1); | |
| 46 | |
| 47 | |
| 48 // ---------------------------------------------------------------------- | |
| 49 // %TypedArray%.prototype.lastIndexOf. | |
| 50 // ---------------------------------------------------------------------- | |
| 51 array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]); | |
| 52 | |
| 53 // Negative cases. | |
| 54 assertEquals(-1, new constructor([]).lastIndexOf(1)); | |
| 55 assertEquals(-1, array.lastIndexOf(1, -17)); | |
| 56 | |
| 57 assertEquals(9, array.lastIndexOf(1)); | |
| 58 // Index out of range. | |
| 59 assertEquals(9, array.lastIndexOf(1, array.length)); | |
| 60 // Index in range. | |
| 61 assertEquals(0, array.lastIndexOf(1, 2)); | |
| 62 assertEquals(3, array.lastIndexOf(1, 4)); | |
| 63 assertEquals(3, array.lastIndexOf(1, 3)); | |
| 64 // Negative index in range. | |
| 65 assertEquals(0, array.lastIndexOf(1, -11)); | |
| 66 | |
| 67 // Basic TypedArray function properties | |
| 68 assertEquals(1, array.lastIndexOf.length); | |
| 69 assertThrows(function(){ array.lastIndexOf.call([1], 1); }, TypeError); | |
| 70 Object.defineProperty(array, 'length', {value: 1}); | |
| 71 assertEquals(array.lastIndexOf(2), 10); | |
| 72 delete array.length; | |
| 73 } | |
| OLD | NEW |