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 for (var constructor of typedArrayConstructors) { | |
19 assertEquals(1, constructor.prototype.fill.length); | |
20 | |
21 assertArrayEquals(new constructor([]).fill(8), []); | |
22 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8), [8, 8, 8, 8, 8]); | |
23 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1), [0, 8, 8, 8, 8]
); | |
24 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 10), [0, 0, 0, 0, 0
]); | |
25 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -5), [8, 8, 8, 8, 8
]); | |
26 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1, 4), [0, 8, 8, 8,
0]); | |
27 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1, -1), [0, 8, 8, 8
, 0]); | |
28 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1, 42), [0, 8, 8, 8
, 8]); | |
29 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -3, 42), [0, 0, 8,
8, 8]); | |
30 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -3, 4), [0, 0, 8, 8
, 0]); | |
31 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -2, -1), [0, 0, 0,
8, 0]); | |
32 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -1, -3), [0, 0, 0,
0, 0]); | |
33 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 0, 4), [8, 8, 8, 8,
0]); | |
34 | |
35 // Test exceptions | |
36 assertThrows('constructor.prototype.fill.call(null)', TypeError); | |
37 assertThrows('constructor.prototype.fill.call(undefined)', TypeError); | |
38 assertThrows('constructor.prototype.fill.call([])', TypeError); | |
39 | |
40 // Shadowing length doesn't affect fill, unlike Array.prototype.fill | |
41 var a = new constructor([2, 2]); | |
42 Object.defineProperty(a, 'length', {value: 1}); | |
43 a.fill(3); | |
44 assertArrayEquals([a[0], a[1]], [3, 3]); | |
45 Array.prototype.fill.call(a, 4); | |
46 assertArrayEquals([a[0], a[1]], [4, 3]); | |
47 } | |
OLD | NEW |