Chromium Code Reviews| Index: test/mjsunit/harmony/array-fill.js |
| diff --git a/test/mjsunit/harmony/array-fill.js b/test/mjsunit/harmony/array-fill.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c2101c57d8cbe05db3d07c33b8dc5fd31fd32d1f |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/array-fill.js |
| @@ -0,0 +1,29 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --harmony-arrays |
| + |
| +assertEquals(1, Array.prototype.find.length); |
| + |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(), [undefined, undefined, undefined, undefined, undefined]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8), [8, 8, 8, 8, 8]); |
|
Dmitry Lomov (no reviews)
2014/04/28 11:18:25
Add test for empty array.
Add test for negative s
|
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, 1), [0, 8, 8, 8, 8]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, 1, 4), [0, 8, 8, 8, 0]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, 1, -1), [0, 8, 8, 8, 0]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, 1, 42), [0, 8, 8, 8, 8]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, -3, 42), [0, 0, 8, 8, 8]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, -3, 4), [0, 0, 8, 8, 0]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, -2, -1), [0, 0, 0, 8, 0]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, -1, -3), [0, 0, 0, 0, 0]); |
| +assertArrayEquals([0, 0, 0, 0, 0].fill(8, undefined, 4), [8, 8, 8, 8, 0]); |
| +assertArrayEquals([ , , , , 0].fill(8, 1, 3), [, 8, 8, , 0]); |
| + |
| +// If the range if empty, the array is not actually modified and |
| +// should not throw, even when applied to a frozen object. |
| +assertArrayEquals(Object.freeze([1, 2, 3]).fill(0, 0, 0), [1, 2, 3]); |
| + |
| +// Test exceptions |
| +assertThrows('Object.freeze([0]).fill()', TypeError); |
| +assertThrows('Array.prototype.fill.call(null)', TypeError); |
| +assertThrows('Array.prototype.fill.call(undefined)', TypeError); |