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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // test array length remains same | 166 // test array length remains same |
165 assertEquals(large, arr.length); | 167 assertEquals(large, arr.length); |
166 }); | 168 }); |
167 | 169 |
168 | 170 |
169 CheckEachTypedArray(function copyWithinNullEnd(constructor) { | 171 CheckEachTypedArray(function copyWithinNullEnd(constructor) { |
170 // test null on third argument is converted to +0 | 172 // test null on third argument is converted to +0 |
171 assertArrayEquals([1, 2, 3, 4, 5], | 173 assertArrayEquals([1, 2, 3, 4, 5], |
172 new constructor([1, 2, 3, 4, 5]).copyWithin(0, 3, null)); | 174 new constructor([1, 2, 3, 4, 5]).copyWithin(0, 3, null)); |
173 }); | 175 }); |
| 176 |
| 177 |
| 178 CheckEachTypedArray(function copyWithinMinusInfinityTarget(constructor) { |
| 179 var arr = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 180 var expected = [6, 7, 8, 9, 10, 6, 7, 8, 9, 10]; |
| 181 |
| 182 assertArrayEquals(expected, arr.copyWithin(-Infinity, 5)); |
| 183 assertEquals(10, arr.length); |
| 184 }); |
| 185 |
| 186 |
| 187 CheckEachTypedArray(function copyWithinPositiveInfinityTarget(constructor) { |
| 188 var arr = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 189 var expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 190 |
| 191 assertArrayEquals(expected, arr.copyWithin(+Infinity, 5)); |
| 192 assertEquals(10, arr.length); |
| 193 }); |
| 194 |
| 195 |
| 196 CheckEachTypedArray(function copyWithinMinusInfinityStart(constructor) { |
| 197 var arr = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 198 var expected = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]; |
| 199 |
| 200 assertArrayEquals(expected, arr.copyWithin(5, -Infinity)); |
| 201 assertEquals(10, arr.length); |
| 202 }); |
| 203 |
| 204 |
| 205 CheckEachTypedArray(function copyWithinPositiveInfinityStart(constructor) { |
| 206 var arr = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 207 var expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 208 |
| 209 assertArrayEquals(expected, arr.copyWithin(5, +Infinity)); |
| 210 assertEquals(10, arr.length); |
| 211 }); |
| 212 |
| 213 |
| 214 CheckEachTypedArray(function copyWithinMinusInfinityEnd(constructor) { |
| 215 var arr = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 216 var expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 217 |
| 218 assertArrayEquals(expected, arr.copyWithin(5, 0, -Infinity)); |
| 219 assertEquals(10, arr.length); |
| 220 }); |
| 221 |
| 222 |
| 223 CheckEachTypedArray(function copyWithinPositiveInfinityEnd(constructor) { |
| 224 var arr = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 225 var expected = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]; |
| 226 |
| 227 assertArrayEquals(expected, arr.copyWithin(5, 0, +Infinity)); |
| 228 assertEquals(10, arr.length); |
| 229 }); |
| 230 |
| 231 CheckEachTypedArray(function parametersNotCalledIfDetached(constructor) { |
| 232 var tmp = { |
| 233 [Symbol.toPrimitive]() { |
| 234 assertUnreachable("Parameter should not be processed when " + |
| 235 "array.[[ViewedArrayBuffer]] is neutered."); |
| 236 return 0; |
| 237 } |
| 238 }; |
| 239 |
| 240 var array = new constructor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 241 %ArrayBufferNeuter(array.buffer); |
| 242 |
| 243 // TODO(caitp): this should throw due to being invoked on a TypedArray with a |
| 244 // detached buffer (per v8:4648). |
| 245 array.copyWithin(tmp, tmp, tmp); |
| 246 assertEquals(0, array.length, "array.[[ViewedArrayBuffer]] is detached"); |
| 247 }); |
OLD | NEW |