OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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 |
| 6 |
5 var typedArrayConstructors = [ | 7 var typedArrayConstructors = [ |
6 Uint8Array, | 8 Uint8Array, |
7 Int8Array, | 9 Int8Array, |
8 Uint16Array, | 10 Uint16Array, |
9 Int16Array, | 11 Int16Array, |
10 Uint32Array, | 12 Uint32Array, |
11 Int32Array, | 13 Int32Array, |
12 Uint8ClampedArray, | 14 Uint8ClampedArray, |
13 Float32Array, | 15 Float32Array, |
14 Float64Array | 16 Float64Array |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 assertThrows(() => constructor.prototype.slice.call([], 0, 0), TypeError); | 62 assertThrows(() => constructor.prototype.slice.call([], 0, 0), TypeError); |
61 | 63 |
62 // Check that elements are copied properly in slice | 64 // Check that elements are copied properly in slice |
63 array = new constructor([1, 2, 3, 4]); | 65 array = new constructor([1, 2, 3, 4]); |
64 var slice = array.slice(1, 3); | 66 var slice = array.slice(1, 3); |
65 assertEquals(2, slice.length); | 67 assertEquals(2, slice.length); |
66 assertEquals(2, slice[0]); | 68 assertEquals(2, slice[0]); |
67 assertEquals(3, slice[1]); | 69 assertEquals(3, slice[1]); |
68 assertTrue(slice instanceof constructor); | 70 assertTrue(slice instanceof constructor); |
69 | 71 |
| 72 // Detached Operation |
| 73 var tmp = { |
| 74 [Symbol.toPrimitive]() { |
| 75 assertUnreachable("Parameter should not be processed when " + |
| 76 "array.[[ViewedArrayBuffer]] is neutered."); |
| 77 return 0; |
| 78 } |
| 79 }; |
| 80 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 81 %ArrayBufferNeuter(array.buffer); |
| 82 assertThrows(() => array.slice(tmp, tmp), TypeError); |
| 83 |
70 // Check that the species array must be a typed array | 84 // Check that the species array must be a typed array |
71 class MyTypedArray extends constructor { | 85 class MyTypedArray extends constructor { |
72 static get[Symbol.species]() { | 86 static get[Symbol.species]() { |
73 return Array; | 87 return Array; |
74 } | 88 } |
75 } | 89 } |
76 var arr = new MyTypedArray([-1.0, 0, 1.1, 255, 256]); | 90 var arr = new MyTypedArray([-1.0, 0, 1.1, 255, 256]); |
77 assertThrows(() => arr.slice(), TypeError); | 91 assertThrows(() => arr.slice(), TypeError); |
78 } | 92 } |
79 | 93 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 let firstValue = convertedCopy[0]; | 132 let firstValue = convertedCopy[0]; |
119 assertEquals(firstValue, customArray2[0]); | 133 assertEquals(firstValue, customArray2[0]); |
120 let sliceResult = customArray2.slice(); | 134 let sliceResult = customArray2.slice(); |
121 if (superClass == speciesClass) { | 135 if (superClass == speciesClass) { |
122 assertEquals(new Array(3).fill(firstValue), Array.from(customArray2)); | 136 assertEquals(new Array(3).fill(firstValue), Array.from(customArray2)); |
123 assertEquals(new Array(3).fill(firstValue), Array.from(sliceResult)); | 137 assertEquals(new Array(3).fill(firstValue), Array.from(sliceResult)); |
124 } | 138 } |
125 assertEquals(3, customArray2.length); | 139 assertEquals(3, customArray2.length); |
126 assertEquals(3, sliceResult.length); | 140 assertEquals(3, sliceResult.length); |
127 } | 141 } |
OLD | NEW |