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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« src/harmony-typedarray.js ('K') | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 --allow-natives-syntax
6
7 function CheckTypedArrayIsNeutered(array) {
8 assertEquals(0, array.byteLength);
9 assertEquals(0, array.byteOffset);
10 assertEquals(0, array.length);
11 }
12
13 function TestTypedArrayFill(constructor) {
14 assertEquals(1, constructor.prototype.fill.length);
15
16 assertArrayEquals([], (new constructor(0)).fill(8));
17
18 assertArrayEquals([8, 8, 8, 8, 8], (new constructor(5).fill(8)));
19 assertArrayEquals([0, 8, 8, 8, 8], (new constructor(5)).fill(8, 1));
20 assertArrayEquals([0, 0, 0, 0, 0], (new constructor(5)).fill(8, 10));
21 assertArrayEquals([8, 8, 8, 8, 8], (new constructor(5)).fill(8, -5));
22 assertArrayEquals([0, 8, 8, 8, 0], (new constructor(5)).fill(8, 1, 4));
23 assertArrayEquals([0, 8, 8, 8, 0], (new constructor(5)).fill(8, 1, -1));
24 assertArrayEquals([0, 8, 8, 8, 8], (new constructor(5)).fill(8, 1, 42));
25 assertArrayEquals([0, 0, 8, 8, 8], (new constructor(5)).fill(8, -3, 42));
26 assertArrayEquals([0, 0, 8, 8, 0], (new constructor(5)).fill(8, -3, 4));
27 assertArrayEquals([0, 0, 0, 8, 0], (new constructor(5)).fill(8, -2, -1));
28 assertArrayEquals([0, 0, 0, 0, 0], (new constructor(5)).fill(8, -1, -3));
29 assertArrayEquals([8, 8, 8, 8, 0], (new constructor(5)).fill(8, undefined, 4)) ;
30
31 // Typed arrays with float numbers are by default filled with NaN,
32 // the ones with integral numbers are filled with zeroes.
33 var D = 0;
34 if (constructor == Float32Array || constructor == Float64Array)
35 D = NaN;
36 assertArrayEquals([D, D, D, D, D], (new constructor(5).fill()));
37
38 // Using .fill() on a neutered array must not cause errors,
39 // and the array must remain neutered afterwards.
40 var a = new constructor(5);
41 %ArrayBufferNeuter(a.buffer);
42 a.fill(8);
43 CheckTypedArrayIsNeutered(a);
44
45 // Test exceptions
46 assertThrows(function () {
47 constructor.prototype.fill.call(null);
48 }, TypeError);
49 assertThrows(function () {
50 constructor.prototype.fill.call(undefined);
51 }, TypeError);
52 }
53
54
55 for (var x of [Uint8Array, Int8Array, Uint16Array, Int16Array, Uint32Array,
56 Int32Array, Uint8ClampedArray, Float32Array, Float64Array]) {
57 TestTypedArrayFill(x);
58 }
OLDNEW
« src/harmony-typedarray.js ('K') | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698