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

Side by Side Diff: test/mjsunit/es6/typedarray-fill.js

Issue 2735563002: Migrate %TypedArray%.prototype.fill to C++ (Closed)
Patch Set: Merge branch 'master' into fill Created 3 years, 9 months 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
« src/elements.cc ('K') | « src/js/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
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var typedArrayConstructors = [ 5 var typedArrayConstructors = [
6 Uint8Array, 6 Uint8Array,
7 Int8Array, 7 Int8Array,
8 Uint16Array, 8 Uint16Array,
9 Int16Array, 9 Int16Array,
10 Uint32Array, 10 Uint32Array,
11 Int32Array, 11 Int32Array,
12 Uint8ClampedArray, 12 Uint8ClampedArray,
13 Float32Array, 13 Float32Array,
14 Float64Array]; 14 Float64Array];
15 15
16 for (var constructor of typedArrayConstructors) { 16 for (var constructor of typedArrayConstructors) {
17 assertEquals(1, constructor.prototype.fill.length); 17 assertEquals(1, constructor.prototype.fill.length);
18 18
19 assertArrayEquals(new constructor([]).fill(8), []); 19 assertArrayEquals([], new constructor([]).fill(8));
20 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8), [8, 8, 8, 8, 8]); 20 assertArrayEquals([8, 8, 8, 8, 8], new constructor([0, 0, 0, 0, 0]).fill(8));
21 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1), [0, 8, 8, 8, 8] ); 21 assertArrayEquals([0, 8, 8, 8, 8], new constructor([0, 0, 0, 0, 0]).fill(8, 1) );
22 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 10), [0, 0, 0, 0, 0 ]); 22 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill(8, 10 ));
23 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -5), [8, 8, 8, 8, 8 ]); 23 assertArrayEquals([8, 8, 8, 8, 8], new constructor([0, 0, 0, 0, 0]).fill(8, -5 ));
24 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1, 4), [0, 8, 8, 8, 0]); 24 assertArrayEquals([0, 8, 8, 8, 0], new constructor([0, 0, 0, 0, 0]).fill(8, 1, 4));
25 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1, -1), [0, 8, 8, 8 , 0]); 25 assertArrayEquals([0, 8, 8, 8, 0], new constructor([0, 0, 0, 0, 0]).fill(8, 1, -1));
26 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1, 42), [0, 8, 8, 8 , 8]); 26 assertArrayEquals([0, 8, 8, 8, 8], new constructor([0, 0, 0, 0, 0]).fill(8, 1, 42));
27 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -3, 42), [0, 0, 8, 8, 8]); 27 assertArrayEquals([0, 0, 8, 8, 8], new constructor([0, 0, 0, 0, 0]).fill(8, -3 , 42));
28 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -3, 4), [0, 0, 8, 8 , 0]); 28 assertArrayEquals([0, 0, 8, 8, 0], new constructor([0, 0, 0, 0, 0]).fill(8, -3 , 4));
29 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -2, -1), [0, 0, 0, 8, 0]); 29 assertArrayEquals([0, 0, 0, 8, 0], new constructor([0, 0, 0, 0, 0]).fill(8, -2 , -1));
30 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -1, -3), [0, 0, 0, 0, 0]); 30 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill(8, -1 , -3));
31 assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 0, 4), [8, 8, 8, 8, 0]); 31 assertArrayEquals([8, 8, 8, 8, 0], new constructor([0, 0, 0, 0, 0]).fill(8, 0, 4));
32
33 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill(8, In finity));
34 assertArrayEquals([8, 8, 8, 8, 8], new constructor([0, 0, 0, 0, 0]).fill(8, -I nfinity));
35 assertArrayEquals([8, 8, 8, 8, 8], new constructor([0, 0, 0, 0, 0]).fill(8, 0, Infinity));
36 assertArrayEquals([0, 0, 0, 0, 0], new constructor([0, 0, 0, 0, 0]).fill(8, 0, -Infinity));
32 37
33 // Test exceptions 38 // Test exceptions
34 assertThrows('constructor.prototype.fill.call(null)', TypeError); 39 assertThrows('constructor.prototype.fill.call(null)', TypeError);
35 assertThrows('constructor.prototype.fill.call(undefined)', TypeError); 40 assertThrows('constructor.prototype.fill.call(undefined)', TypeError);
36 assertThrows('constructor.prototype.fill.call([])', TypeError); 41 assertThrows('constructor.prototype.fill.call([])', TypeError);
37 42
43 // Test ToNumber
44 var s = "";
45 var p = new Proxy({}, {get(t,k) { s += k.toString() + '\n'; return Reflect.get (t, k)}})
46 new constructor(3).fill(p);
47 assertEquals(s, `Symbol(Symbol.toPrimitive)
48 valueOf
49 toString
50 Symbol(Symbol.toStringTag)
51 Symbol(Symbol.toPrimitive)
52 valueOf
53 toString
54 Symbol(Symbol.toStringTag)
55 Symbol(Symbol.toPrimitive)
56 valueOf
57 toString
58 Symbol(Symbol.toStringTag)
59 `);
60
38 // Shadowing length doesn't affect fill, unlike Array.prototype.fill 61 // Shadowing length doesn't affect fill, unlike Array.prototype.fill
39 var a = new constructor([2, 2]); 62 var a = new constructor([2, 2]);
40 Object.defineProperty(a, 'length', {value: 1}); 63 Object.defineProperty(a, 'length', {value: 1});
41 a.fill(3); 64 a.fill(3);
42 assertArrayEquals([a[0], a[1]], [3, 3]); 65 assertArrayEquals([3, 3], [a[0], a[1]]);
43 Array.prototype.fill.call(a, 4); 66 Array.prototype.fill.call(a, 4);
44 assertArrayEquals([a[0], a[1]], [4, 3]); 67 assertArrayEquals([4, 3], [a[0], a[1]]);
45 } 68 }
69
70 // Empty args
71 assertArrayEquals([0], new Uint8Array([0]).fill());
72 assertArrayEquals([NaN], new Float32Array([0]).fill());
73
74 // Clamping
75 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- 10));
76 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1000));
77
78 assertArrayEquals([1, 1, 1, 1, 1], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50001));
79 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .50000));
80 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0 .49999));
81 // Check round half to even
82 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1 .50000));
83 assertArrayEquals([2, 2, 2, 2, 2], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50000));
84 assertArrayEquals([3, 3, 3, 3, 3], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2 .50001));
85 // Check infinity clamping.
86 assertArrayEquals([0, 0, 0, 0, 0], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(- Infinity));
87 assertArrayEquals([255, 255, 255, 255, 255], new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(Infinity));
OLDNEW
« src/elements.cc ('K') | « src/js/typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698