Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1198)

Unified Diff: test/mjsunit/harmony/typedarrays-fill.js

Issue 699953003: Implement .fill() on typed arrays Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Make .fill() work only on typed arrays, use internal slot for length Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« no previous file with comments | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698