| 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..0743e4f41a89922e6bb3613ad23df97bad6bc6bf
|
| --- /dev/null
|
| +++ b/test/mjsunit/harmony/typedarrays-fill.js
|
| @@ -0,0 +1,58 @@
|
| +// 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
|
| +
|
| +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);
|
| +}
|
| +
|
| +
|
| +for (var x of [Uint8Array, Int8Array, Uint16Array, Int16Array, Uint32Array,
|
| + Int32Array, Uint8ClampedArray, Float32Array, Float64Array]) {
|
| + TestTypedArrayFill(x);
|
| +}
|
|
|