| Index: test/mjsunit/harmony/typedarrays-fill.js
|
| diff --git a/test/mjsunit/harmony/typedarrays-fill.js b/test/mjsunit/harmony/typedarrays-fill.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..35494ac395fb4ceb6403c0911590675073a0cfef
|
| --- /dev/null
|
| +++ b/test/mjsunit/harmony/typedarrays-fill.js
|
| @@ -0,0 +1,91 @@
|
| +// 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 --allow-natives-syntax
|
| +
|
| +var typedArrayConstructors = [
|
| + Uint8Array,
|
| + Int8Array,
|
| + Uint16Array,
|
| + Int16Array,
|
| + Uint32Array,
|
| + Int32Array,
|
| + Uint8ClampedArray,
|
| + Float32Array,
|
| + Float64Array];
|
| +
|
| +function CheckTypedArrayIsNeutered(array) {
|
| + assertEquals(0, array.byteLength);
|
| + assertEquals(0, array.byteOffset);
|
| + assertEquals(0, array.length);
|
| +}
|
| +
|
| +function TestTypedArrayFill(constructor) {
|
| + assertEquals(1, constructor.prototype.fill.length);
|
| +
|
| + assertArrayEquals([], (new constructor(0)).fill(8));
|
| +
|
| + assertArrayEquals([8, 8, 8, 8, 8], (new constructor(5).fill(8)));
|
| + assertArrayEquals([0, 8, 8, 8, 8], (new constructor(5)).fill(8, 1));
|
| + assertArrayEquals([0, 0, 0, 0, 0], (new constructor(5)).fill(8, 10));
|
| + assertArrayEquals([8, 8, 8, 8, 8], (new constructor(5)).fill(8, -5));
|
| + assertArrayEquals([0, 8, 8, 8, 0], (new constructor(5)).fill(8, 1, 4));
|
| + assertArrayEquals([0, 8, 8, 8, 0], (new constructor(5)).fill(8, 1, -1));
|
| + assertArrayEquals([0, 8, 8, 8, 8], (new constructor(5)).fill(8, 1, 42));
|
| + assertArrayEquals([0, 0, 8, 8, 8], (new constructor(5)).fill(8, -3, 42));
|
| + assertArrayEquals([0, 0, 8, 8, 0], (new constructor(5)).fill(8, -3, 4));
|
| + assertArrayEquals([0, 0, 0, 8, 0], (new constructor(5)).fill(8, -2, -1));
|
| + assertArrayEquals([0, 0, 0, 0, 0], (new constructor(5)).fill(8, -1, -3));
|
| + assertArrayEquals([8, 8, 8, 8, 0], (new constructor(5)).fill(8, undefined, 4));
|
| +
|
| + // Typed arrays with float numbers are by default filled with NaN,
|
| + // the ones with integral numbers are filled with zeroes.
|
| + var D = 0;
|
| + if (constructor == Float32Array || constructor == Float64Array)
|
| + D = NaN;
|
| + assertArrayEquals([D, D, D, D, D], (new constructor(5).fill()));
|
| +
|
| + // Using .fill() on a neutered array must not cause errors,
|
| + // and the array must remain neutered afterwards.
|
| + var a = new constructor(5);
|
| + %ArrayBufferNeuter(a.buffer);
|
| + a.fill(8);
|
| + CheckTypedArrayIsNeutered(a);
|
| +
|
| + // Test exceptions
|
| + assertThrows(function () {
|
| + constructor.prototype.fill.call(null);
|
| + }, TypeError);
|
| + assertThrows(function () {
|
| + constructor.prototype.fill.call(undefined);
|
| + }, TypeError);
|
| +
|
| + // Check superficial features of %TypedArray%.prototype.fill.
|
| + var desc = Object.getOwnPropertyDescriptor(constructor.prototype, "fill");
|
| +
|
| + assertEquals(false, desc.configurable);
|
| + assertEquals(false, desc.enumerable);
|
| + assertEquals(false, desc.writable);
|
| + assertEquals(1, constructor.prototype.fill.length);
|
| +
|
| + // The %TypedArray%.prototype.fill() method should not work
|
| + // when transplanted to objects that are not typed arrays.
|
| + assertThrows(function () { constructor.prototype.fill.call([1, 2, 3], 8) }, TypeError);
|
| + assertThrows(function () { constructor.prototype.fill.call("abc", 8) }, TypeError);
|
| + assertThrows(function () { constructor.prototype.fill.call({}, 8) }, TypeError);
|
| + assertThrows(function () { constructor.prototype.fill.call({}, 8) }, TypeError);
|
| + assertThrows(function () { constructor.prototype.fill.call(0, 8) }, TypeError);
|
| +
|
| + // The method should be work on instances of other typed arrays.
|
| + for (var otherConstructor of typedArrayConstructors) {
|
| + a = new otherConstructor(5);
|
| + constructor.prototype.fill.call(a, 8);
|
| + assertArrayEquals([8, 8, 8, 8, 8], a);
|
| + }
|
| +}
|
| +
|
| +
|
| +for (var x of typedArrayConstructors) {
|
| + TestTypedArrayFill(x);
|
| +}
|
|
|