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

Unified Diff: test/mjsunit/es6/typedarray-fill.js

Issue 2735563002: Migrate %TypedArray%.prototype.fill to C++ (Closed)
Patch Set: fix fp and no args bugs 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/js/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/es6/typedarray-fill.js
diff --git a/test/mjsunit/es6/typedarray-fill.js b/test/mjsunit/es6/typedarray-fill.js
index 2c612016f6187e43fa91a0c31554e71ed51fad7b..be9acdba7f464b52dba0e96402191031c8dcd600 100644
--- a/test/mjsunit/es6/typedarray-fill.js
+++ b/test/mjsunit/es6/typedarray-fill.js
@@ -16,6 +16,7 @@ var typedArrayConstructors = [
for (var constructor of typedArrayConstructors) {
assertEquals(1, constructor.prototype.fill.length);
+ assertArrayEquals(new constructor([0]).fill(), [0]);
rongjie 2017/03/14 11:17:15 This line fails with "Failure (array element at in
rongjie 2017/03/14 12:54:01 Test fixed.
assertArrayEquals(new constructor([]).fill(8), []);
assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8), [8, 8, 8, 8, 8]);
assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 1), [0, 8, 8, 8, 8]);
@@ -30,11 +31,34 @@ for (var constructor of typedArrayConstructors) {
assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -1, -3), [0, 0, 0, 0, 0]);
assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 0, 4), [8, 8, 8, 8, 0]);
+ assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, Infinity), [0, 0, 0, 0, 0]);
+ assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, -Infinity), [8, 8, 8, 8, 8]);
+ assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 0, Infinity), [8, 8, 8, 8, 8]);
+ assertArrayEquals(new constructor([0, 0, 0, 0, 0]).fill(8, 0, -Infinity), [0, 0, 0, 0, 0]);
+
// Test exceptions
assertThrows('constructor.prototype.fill.call(null)', TypeError);
assertThrows('constructor.prototype.fill.call(undefined)', TypeError);
assertThrows('constructor.prototype.fill.call([])', TypeError);
+ // Test ToNumber
+ var s = "";
+ var p = new Proxy({}, {get(t,k) { s += k.toString() + '\n'; return Reflect.get(t, k)}})
+ new constructor(3).fill(p);
+ assertEquals(`Symbol(Symbol.toPrimitive)
+valueOf
+toString
+Symbol(Symbol.toStringTag)
+Symbol(Symbol.toPrimitive)
+valueOf
+toString
+Symbol(Symbol.toStringTag)
+Symbol(Symbol.toPrimitive)
+valueOf
+toString
+Symbol(Symbol.toStringTag)
+`, s);
+
// Shadowing length doesn't affect fill, unlike Array.prototype.fill
var a = new constructor([2, 2]);
Object.defineProperty(a, 'length', {value: 1});
@@ -43,3 +67,18 @@ for (var constructor of typedArrayConstructors) {
Array.prototype.fill.call(a, 4);
assertArrayEquals([a[0], a[1]], [4, 3]);
}
+
+// Clamping
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(-10), [0, 0, 0, 0, 0]);
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1000), [255, 255, 255, 255, 255]);
+
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0.50001), [1, 1, 1, 1, 1]);
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0.50000), [0, 0, 0, 0, 0]);
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(0.49999), [0, 0, 0, 0, 0]);
+// Check round half to even
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(1.50000), [2, 2, 2, 2, 2]);
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2.50000), [2, 2, 2, 2, 2]);
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(2.50001), [3, 3, 3, 3, 3]);
+// Check infinity clamping.
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(-Infinity), [0, 0, 0, 0, 0]);
+assertArrayEquals(new Uint8ClampedArray([0, 0, 0, 0, 0]).fill(Infinity), [255, 255, 255, 255, 255]);
« no previous file with comments | « src/js/typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698