From b1bbf08bdca9f5fa9e2e68ff33c0e240bff6df23 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 12 Mar 2018 14:23:58 -0400 Subject: [PATCH] BigInt: some fixes listed in #1461 (#1485) test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js - Should refer to BigInt conversion instead of ToNumber test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js - Missing coverage for non-convertable values like undefined or null? - added fill-values-non-numeric-throw.js test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-tointeger-offset-symbol.js - Change [1] to [1n] to avoid possible false-positives because ToBigInt(1) also throws a TypeError. - Issue also present in other set() tests. --- .../BigInt/fill-values-conversion-once.js | 5 +- .../BigInt/fill-values-non-numeric-throw.js | 57 +++++++++++++++++++ .../fill/BigInt/fill-values-non-numeric.js | 4 +- ...rray-arg-negative-integer-offset-throws.js | 6 +- ...urn-abrupt-from-tointeger-offset-symbol.js | 2 +- ...fer-detached-on-tointeger-offset-throws.js | 2 +- .../array-arg-targetbuffer-detached-throws.js | 2 +- 7 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric-throw.js diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js index c87b864f93..47033ccce6 100644 --- a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js @@ -8,7 +8,8 @@ info: | 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) ... - 3. Let _value_ be ? ToNumber(_value_). + 3. If O.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). ... includes: [testBigIntTypedArray.js] features: [BigInt, TypedArray] @@ -20,7 +21,7 @@ testWithBigIntTypedArrayConstructors(function(TA) { var n = 1n; sample.fill({ valueOf() { return n++; } }); - assert.sameValue(n, 2n, "additional unexpected ToNumber() calls"); + assert.sameValue(n, 2n, "additional unexpected ToBigInt() calls"); assert.sameValue(sample[0], 1n, "incorrect ToNumber result in index 0"); assert.sameValue(sample[1], 1n, "incorrect ToNumber result in index 1"); }); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric-throw.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric-throw.js new file mode 100644 index 0000000000..e091e0f09c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric-throw.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +description: > + Fills all the elements with non numeric values values. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n]); + + assert.throws(TypeError, function() { + sample.fill(undefined); + }, "abrupt completion from undefined"); + + assert.throws(TypeError, function() { + sample.fill(null); + }, "abrupt completion from null"); + + assert.throws(SyntaxError, function() { + sample.fill("nonsense"); + }, "abrupt completion from string"); + +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js index 4719ac67e6..e7f9175eb3 100644 --- a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js @@ -29,7 +29,8 @@ info: | 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) ... - 3. Let numValue be ? ToNumber(value). + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). ... includes: [testBigIntTypedArray.js] @@ -69,4 +70,5 @@ testWithBigIntTypedArrayConstructors(function(TA) { } }); assert.sameValue(sample[0], 7n, "object toString when valueOf is absent"); + }); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js index a5896d24b4..18de4d017b 100644 --- a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js @@ -22,14 +22,14 @@ testWithBigIntTypedArrayConstructors(function(TA) { var sample = new TA(4); assert.throws(RangeError, function() { - sample.set([1], -1); + sample.set([1n], -1); }, "-1"); assert.throws(RangeError, function() { - sample.set([1], -1.00001); + sample.set([1n], -1.00001); }, "-1.00001"); assert.throws(RangeError, function() { - sample.set([1], -Infinity); + sample.set([1n], -Infinity); }, "-Infinity"); }); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js index f9d8699ab5..63b3095ac5 100644 --- a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js @@ -22,6 +22,6 @@ testWithBigIntTypedArrayConstructors(function(TA) { var sample = new TA(2); assert.throws(TypeError, function() { - sample.set([1], s); + sample.set([1n], s); }); }); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js index a25113b5a2..a3747af9a2 100644 --- a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js @@ -32,7 +32,7 @@ testWithBigIntTypedArrayConstructors(function(TA) { }; assert.throws(TypeError, function() { - sample.set([1], obj); + sample.set([1n], obj); }); assert.sameValue(calledOffset, 1); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js index 9a2bd25315..0b54b20cf1 100644 --- a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js @@ -34,7 +34,7 @@ testWithBigIntTypedArrayConstructors(function(TA) { $DETACHBUFFER(sample.buffer); assert.throws(TypeError, function() { - sample.set([1]); + sample.set([1n]); }, "regular check"); assert.throws(TypeError, function() {