1// Copyright 2014 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 7assertEquals(1, Array.prototype.fill.length); 8 9assertArrayEquals([].fill(8), []); 10assertArrayEquals([0, 0, 0, 0, 0].fill(), [undefined, undefined, undefined, undefined, undefined]); 11assertArrayEquals([0, 0, 0, 0, 0].fill(8), [8, 8, 8, 8, 8]); 12assertArrayEquals([0, 0, 0, 0, 0].fill(8, 1), [0, 8, 8, 8, 8]); 13assertArrayEquals([0, 0, 0, 0, 0].fill(8, 10), [0, 0, 0, 0, 0]); 14assertArrayEquals([0, 0, 0, 0, 0].fill(8, -5), [8, 8, 8, 8, 8]); 15assertArrayEquals([0, 0, 0, 0, 0].fill(8, 1, 4), [0, 8, 8, 8, 0]); 16assertArrayEquals([0, 0, 0, 0, 0].fill(8, 1, -1), [0, 8, 8, 8, 0]); 17assertArrayEquals([0, 0, 0, 0, 0].fill(8, 1, 42), [0, 8, 8, 8, 8]); 18assertArrayEquals([0, 0, 0, 0, 0].fill(8, -3, 42), [0, 0, 8, 8, 8]); 19assertArrayEquals([0, 0, 0, 0, 0].fill(8, -3, 4), [0, 0, 8, 8, 0]); 20assertArrayEquals([0, 0, 0, 0, 0].fill(8, -2, -1), [0, 0, 0, 8, 0]); 21assertArrayEquals([0, 0, 0, 0, 0].fill(8, -1, -3), [0, 0, 0, 0, 0]); 22assertArrayEquals([0, 0, 0, 0, 0].fill(8, undefined, 4), [8, 8, 8, 8, 0]); 23assertArrayEquals([ , , , , 0].fill(8, 1, 3), [, 8, 8, , 0]); 24 25// If the range is empty, the array is not actually modified and 26// should not throw, even when applied to a frozen object. 27assertArrayEquals(Object.freeze([1, 2, 3]).fill(0, 0, 0), [1, 2, 3]); 28 29// Test exceptions 30assertThrows('Object.freeze([0]).fill()', TypeError); 31assertThrows('Array.prototype.fill.call(null)', TypeError); 32assertThrows('Array.prototype.fill.call(undefined)', TypeError); 33