diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt')
51 files changed, 2600 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js new file mode 100644 index 0000000000..6631699cb4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js @@ -0,0 +1,37 @@ +// 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.set-array-offset +description: > + Throw a RangeError exception if targetOffset < 0 +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert.throws(RangeError, function() { + sample.set([1n], -1); + }, "-1"); + + assert.throws(RangeError, function() { + sample.set([1n], -1.00001); + }, "-1.00001"); + + assert.throws(RangeError, function() { + sample.set([1n], -Infinity); + }, "-Infinity"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js new file mode 100644 index 0000000000..5853c74c1e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js @@ -0,0 +1,97 @@ +// 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.set-array-offset +description: > + ToInteger(offset) operations +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([1n, 2n]); + sample.set([42n], ""); + assert(compareArray(sample, [42n, 2n]), "the empty string"); + + sample = new TA([1n, 2n]); + sample.set([42n], "0"); + assert(compareArray(sample, [42n, 2n]), "'0'"); + + sample = new TA([1n, 2n]); + sample.set([42n], false); + assert(compareArray(sample, [42n, 2n]), "false"); + + sample = new TA([1n, 2n]); + sample.set([42n], 0.1); + assert(compareArray(sample, [42n, 2n]), "0.1"); + + sample = new TA([1n, 2n]); + sample.set([42n], 0.9); + assert(compareArray(sample, [42n, 2n]), "0.9"); + + sample = new TA([1n, 2n]); + sample.set([42n], -0.5); + assert(compareArray(sample, [42n, 2n]), "-0.5"); + + sample = new TA([1n, 2n]); + sample.set([42n], 1.1); + assert(compareArray(sample, [1n, 42n]), "1.1"); + + sample = new TA([1n, 2n]); + sample.set([42n], NaN); + assert(compareArray(sample, [42n, 2n]), "NaN"); + + sample = new TA([1n, 2n]); + sample.set([42n], null); + assert(compareArray(sample, [42n, 2n]), "null"); + + sample = new TA([1n, 2n]); + sample.set([42n], undefined); + assert(compareArray(sample, [42n, 2n]), "undefined"); + + sample = new TA([1n, 2n]); + sample.set([42n], {}); + assert(compareArray(sample, [42n, 2n]), "{}"); + + sample = new TA([1n, 2n]); + sample.set([42n], []); + assert(compareArray(sample, [42n, 2n]), "[]"); + + sample = new TA([1n, 2n]); + sample.set([42n], [0]); + assert(compareArray(sample, [42n, 2n]), "[0]"); + + sample = new TA([1n, 2n]); + sample.set([42n], true); + assert(compareArray(sample, [1n, 42n]), "true"); + + sample = new TA([1n, 2n]); + sample.set([42n], "1"); + assert(compareArray(sample, [1n, 42n]), "'1'"); + + sample = new TA([1n, 2n]); + sample.set([42n], [1]); + assert(compareArray(sample, [1n, 42n]), "[1]"); + + sample = new TA([1n, 2n]); + sample.set([42n], { valueOf: function() {return 1;} }); + assert(compareArray(sample, [1n, 42n]), "valueOf"); + + sample = new TA([1n, 2n]); + sample.set([42n], { toString: function() {return 1;} }); + assert(compareArray(sample, [1n, 42n]), "toString"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-primitive-toobject.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-primitive-toobject.js new file mode 100644 index 0000000000..d2fe88d0d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-primitive-toobject.js @@ -0,0 +1,51 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Primitive `array` argument is coerced to an object. +info: | + %TypedArray%.prototype.set ( typedArray [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object + with a [[TypedArrayName]] internal slot. If it is such an Object, + the definition in 22.2.3.23.2 applies. + [...] + 14. Let src be ? ToObject(array). + 15. Let srcLength be ? LengthOfArrayLike(src). + [...] + 19. Let limit be targetByteIndex + targetElementSize × srcLength. + 20. Repeat, while targetByteIndex < limit, + a. Let Pk be ! ToString(k). + b. Let value be ? Get(src, Pk). + c. If target.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + [...] + f. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, Unordered). + [...] +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray, Symbol] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta1 = new TA([1n, 2n, 3n, 4n]); + ta1.set("567"); + assert.compareArray(ta1, [5n, 6n, 7n, 4n], "string"); + + var ta2 = new TA([1n, 2n, 3n]); + ta2.set(-10, 2); + assert.compareArray(ta2, [1n, 2n, 3n], "number"); + + var ta3 = new TA([1n]); + ta3.set(false); + assert.compareArray(ta3, [1n], "boolean"); + + var ta4 = new TA([1n, 2n]); + ta4.set(Symbol("desc"), 0); + assert.compareArray(ta4, [1n, 2n], "symbol"); + + var ta5 = new TA([1n, 2n]); + ta5.set(4n, 1); + assert.compareArray(ta5, [1n, 2n], "bigint"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js new file mode 100644 index 0000000000..86b73fc62d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js @@ -0,0 +1,35 @@ +// 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.set-array-offset +description: > + Return abrupt getting src "length" +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js new file mode 100644 index 0000000000..6d1a90022e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js @@ -0,0 +1,50 @@ +// 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.set-array-offset +description: > + Return abrupt from getting src property value +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42n, + "1": 43n, + "3": 44n + }; + Object.defineProperty(obj, "2", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([1n, 2n, 3n, 4n]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42n, 43n, 3n, 4n]), + "values are set until exception" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js new file mode 100644 index 0000000000..aee3df52d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js @@ -0,0 +1,32 @@ +// 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.set-array-offset +description: > + Return abrupt getting src "length" as symbol +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var obj = { + length: Symbol("1") +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + + assert.throws(TypeError, function() { + sample.set(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js new file mode 100644 index 0000000000..4c8f69a59b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js @@ -0,0 +1,48 @@ +// 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.set-array-offset +description: > + Return abrupt from ToLength(src "length") +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; + +var obj2 = { + length: { + toString: function() { + throw new Test262Error(); + } + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + + assert.throws(Test262Error, function() { + sample.set(obj1); + }, "valueOf"); + + assert.throws(Test262Error, function() { + sample.set(obj2); + }, "toString"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js new file mode 100644 index 0000000000..df47d391a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js @@ -0,0 +1,46 @@ +// 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.set-array-offset +description: > + Return abrupt from ToNumber(src property symbol value) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42n, + "1": 43n, + "2": Symbol("1"), + "3": 44n + }; + + var sample = new TA([1n, 2n, 3n, 4n]); + + assert.throws(TypeError, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42n, 43n, 3n, 4n]), + "values are set until exception" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js new file mode 100644 index 0000000000..99ba4c3b67 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js @@ -0,0 +1,50 @@ +// 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.set-array-offset +description: > + Return abrupt from ToNumber(src property value) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42n, + "1": 43n, + "2": { + valueOf: function() { + throw new Test262Error(); + } + }, + "3": 44n + }; + + var sample = new TA([1n, 2n, 3n, 4n]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42n, 43n, 3n, 4n]), + "values are set until exception" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js new file mode 100644 index 0000000000..be0d63523a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js @@ -0,0 +1,29 @@ +// 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.set-array-offset +description: > + Return abrupt from ToInteger(Symbol offset) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.set([1n], s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js new file mode 100644 index 0000000000..680bd3591c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js @@ -0,0 +1,43 @@ +// 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.set-array-offset +description: > + Return abrupt from ToInteger(offset) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.set([], obj1); + }, "abrupt from valueOf"); + + assert.throws(Test262Error, function() { + sample.set([], obj2); + }, "abrupt from toString"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js new file mode 100644 index 0000000000..f0170ebe63 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js @@ -0,0 +1,32 @@ +// 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.set-array-offset +description: > + Return abrupt from ToObject(array) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 15. Let src be ? ToObject(array). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + + assert.throws(TypeError, function() { + sample.set(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.set(null); + }, "null"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js new file mode 100644 index 0000000000..9449aeca3b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js @@ -0,0 +1,74 @@ +// 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.set-array-offset +description: > + Get and set each value in order +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(5); + var calls = []; + var obj = { + length: 3 + }; + Object.defineProperty(obj, 0, { + get: function() { + calls.push(0); + calls.push(sample.join()); + return 42n; + } + }); + + Object.defineProperty(obj, 1, { + get: function() { + calls.push(1); + calls.push(sample.join()); + return 43n; + } + }); + + Object.defineProperty(obj, 2, { + get: function() { + calls.push(2); + calls.push(sample.join()); + return 44n; + } + }); + + Object.defineProperty(obj, 3, { + get: function() { + throw new Test262Error("Should not call obj[3]"); + } + }); + + sample.set(obj, 1); + + assert( + compareArray(sample, [0n, 42n, 43n, 44n, 0n]), + "values are set for src length" + ); + + assert( + compareArray(calls, [0, "0,0,0,0,0", 1, "0,42,0,0,0", 2, "0,42,43,0,0"]), + "values are set in order" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values.js new file mode 100644 index 0000000000..d2a420b70c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values.js @@ -0,0 +1,65 @@ +// 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.set-array-offset +description: > + Set values to target and return undefined +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + Let Pk be ! ToString(k). + Let kNumber be ? ToNumber(? Get(src, Pk)). + If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, kNumber). + ... + 22. Return undefined. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var src = [42n, 43n]; + var srcObj = { + length: 2, + '0': 7n, + '1': 17n + }; + var sample, result; + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(srcObj, 0); + assert(compareArray(sample, [7n, 17n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(srcObj, 1); + assert(compareArray(sample, [1n, 7n, 17n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(srcObj, 2); + assert(compareArray(sample, [1n, 2n, 7n, 17n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js new file mode 100644 index 0000000000..ffffc3d976 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js @@ -0,0 +1,51 @@ +// 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.set-array-offset +description: > + Type conversions on ToNumber(src property value) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj1 = { + valueOf: function() { + return 42n; + } + }; + + var obj2 = { + toString: function() { + return "42"; + } + }; + + var arr = [false, true, obj1, [], [1]]; + + var sample = new TA(arr.length); + var expected = new TA([0n, 1n, 42n, 0n, 1n]); + + sample.set(arr); + + assert( + compareArray(sample, expected), + "sample: [" + sample + "], expected: [" + expected + "]" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js new file mode 100644 index 0000000000..669d1d2aa2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js @@ -0,0 +1,49 @@ +// 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.set-array-offset +description: > + Values from src array are not cached +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(5); + var obj = { + length: 5, + '1': 7n, + '2': 7n, + '3': 7n, + '4': 7n + }; + Object.defineProperty(obj, 0, { + get: function() { + obj[1] = 43n; + obj[2] = 44n; + obj[3] = 45n; + obj[4] = 46n; + return 42n; + } + }); + + sample.set(obj); + + assert(compareArray(sample, [42n, 43n, 44n, 45n, 46n])); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js new file mode 100644 index 0000000000..a6d14c115b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js @@ -0,0 +1,43 @@ +// 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.set-array-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 17. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.set([42n, 43n]); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js new file mode 100644 index 0000000000..b469bd044d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js @@ -0,0 +1,41 @@ +// 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.set-array-offset +description: > + Throws a TypeError if targetBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(sample.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set([1n], obj); + }); + + assert.sameValue(calledOffset, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js new file mode 100644 index 0000000000..9c2f286b3e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js @@ -0,0 +1,45 @@ +// 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.set-array-offset +description: > + Throws a TypeError if targetBuffer is detached +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... + 15. Let src be ? ToObject(array). + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample.set([1n]); + }, "regular check"); + + assert.throws(TypeError, function() { + sample.set(obj); + }, "IsDetachedBuffer happens before Get(src.length)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js new file mode 100644 index 0000000000..1cd0db81eb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js @@ -0,0 +1,90 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Behavior for input array of BigInts +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigInt64 + Conversion Operation: ToBigInt64 + + ToBigInt64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. If int64bit ≥ 2^63, return int64bit - 2^64; otherwise return int64bit. + +features: [BigInt, TypedArray] +---*/ + +var vals = [ + 18446744073709551618n, // 2n ** 64n + 2n + 9223372036854775810n, // 2n ** 63n + 2n + 2n, + 0n, + -2n, + -9223372036854775810n, // -(2n ** 63n) - 2n + -18446744073709551618n, // -(2n ** 64n) - 2n +]; + +var typedArray = new BigInt64Array(vals.length); +typedArray.set(vals); + +assert.sameValue(typedArray[0], 2n, + "ToBigInt64(2n ** 64n + 2n) => 2n"); + +assert.sameValue(typedArray[1], -9223372036854775806n, // 2n - 2n ** 63n + "ToBigInt64(2n ** 63n + 2n) => -9223372036854775806n"); + +assert.sameValue(typedArray[2], 2n, + "ToBigInt64(2n) => 2n"); + +assert.sameValue(typedArray[3], 0n, + "ToBigInt64(0n) => 0n"); + +assert.sameValue(typedArray[4], -2n, + "ToBigInt64( -2n) => -2n"); + +assert.sameValue(typedArray[5], 9223372036854775806n, // 2n ** 63n - 2 + "ToBigInt64( -(2n ** 64n) - 2n) => 9223372036854775806n"); + +assert.sameValue(typedArray[6], -2n, + "ToBigInt64( -(2n ** 64n) - 2n) => -2n"); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js new file mode 100644 index 0000000000..c649f8db07 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js @@ -0,0 +1,89 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Behavior for input array of BigInts +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigUint64 + Conversion Operation: ToBigUint64 + + ToBigUint64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. Return int64bit. + +features: [BigInt, TypedArray] +---*/ + +var vals = [ + 18446744073709551618n, // 2n ** 64n + 2n + 9223372036854775810n, // 2n ** 63n + 2n + 2n, + 0n, + -2n, + -9223372036854775810n, // -(2n ** 63n) - 2n + -18446744073709551618n, // -(2n ** 64n) - 2n +]; + +var typedArray = new BigUint64Array(vals.length); +typedArray.set(vals); + +assert.sameValue(typedArray[0], 2n, + "ToBigUint64(2n ** 64n + 2n) => 2n"); + +assert.sameValue(typedArray[1], 9223372036854775810n, // 2n ** 63n + 2n + "ToBigUint64(2n ** 63n + 2n) => 9223372036854775810"); + +assert.sameValue(typedArray[2], 2n, + "ToBigUint64(2n) => 2n"); + +assert.sameValue(typedArray[3], 0n, + "ToBigUint64(0n) => 0n"); + +assert.sameValue(typedArray[4], 18446744073709551614n, // 2n ** 64n - 2n + "ToBigUint64( -2n) => 18446744073709551614n"); + +assert.sameValue(typedArray[5], 9223372036854775806n, // 2n ** 63n - 2n + "ToBigUint64( -(2n ** 63n) - 2n) => 9223372036854775806n"); + +assert.sameValue(typedArray[6], 18446744073709551614n, // 2n ** 64n - 2n + "ToBigUint64( -(2n ** 64n) - 2n) => 18446744073709551614n"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/boolean-tobigint.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/boolean-tobigint.js new file mode 100644 index 0000000000..02cfee433a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/boolean-tobigint.js @@ -0,0 +1,48 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Behavior for input array of Booleans +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Boolean + Result: Return 1n if prim is true and 0n if prim is false. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(2); + typedArray.set([false, true]) + + assert.sameValue(typedArray[0], 0n, "False converts to BigInt"); + assert.sameValue(typedArray[1], 1n, "True converts to BigInt"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/null-tobigint.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/null-tobigint.js new file mode 100644 index 0000000000..f7bc8ce8d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/null-tobigint.js @@ -0,0 +1,49 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Return abrupt on null +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Null + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray.set([null]); + }, "abrupt completion from Null"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/number-tobigint.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/number-tobigint.js new file mode 100644 index 0000000000..2047fc4683 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/number-tobigint.js @@ -0,0 +1,74 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Return abrupt on Number +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Number + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray.set([1]); + }, "abrupt completion from Number: 1"); + + assert.throws(TypeError, function() { + typedArray.set([Math.pow(2, 63)]); + }, "abrupt completion from Number: 2**63"); + + assert.throws(TypeError, function() { + typedArray.set([+0]); + }, "abrupt completion from Number: +0"); + + assert.throws(TypeError, function() { + typedArray.set([-0]); + }, "abrupt completion from Number: -0"); + + assert.throws(TypeError, function() { + typedArray.set([Infinity]); + }, "abrupt completion from Number: Infinity"); + + assert.throws(TypeError, function() { + typedArray.set([-Infinity]); + }, "abrupt completion from Number: -Infinity"); + + assert.throws(TypeError, function() { + typedArray.set([NaN]); + }, "abrupt completion from Number: NaN"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-big.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-big.js new file mode 100644 index 0000000000..e8c6598330 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-big.js @@ -0,0 +1,40 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + If typedArray constructor argument is a Big(U)Int, succeed in set +info: | + %TypedArray%.prototype.set( typedArray [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the + typedArray argument object. The optional offset value indicates the first + element index in this TypedArray where values are written. If omitted, it + is assumed to be 0. + ... + 23. If one of srcType and targetType contains the substring "Big" and the + other does not, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var srcTypedArray; +var targetTypedArray; +var testValue = 42n; + +testWithBigIntTypedArrayConstructors(function(BTA1) { + + srcTypedArray = new BTA1([testValue]); + + testWithBigIntTypedArrayConstructors(function(BTA2) { + + targetTypedArray = new BTA2(1); + targetTypedArray.set(srcTypedArray); + assert.sameValue(targetTypedArray[0], testValue, + "Setting BigInt TypedArray with BigInt TypedArray should succeed.") + }); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js new file mode 100644 index 0000000000..9250e0d7fc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + If typedArray set argument is not a Big(U)Int, and target is "Big", throw +info: | + %TypedArray%.prototype.set( typedArray [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the + typedArray argument object. The optional offset value indicates the first + element index in this TypedArray where values are written. If omitted, it + is assumed to be 0. + ... + 23. If one of srcType and targetType contains the substring "Big" and the + other does not, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, testTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var bigTypedArray; +var littleTypedArray; + +testWithTypedArrayConstructors(function(TA) { + + littleTypedArray = new TA([1]); + + testWithBigIntTypedArrayConstructors(function(BTA) { + + bigTypedArray = new BTA(1); + assert.throws(TypeError, function() { + bigTypedArray.set(littleTypedArray); + }); + }); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js new file mode 100644 index 0000000000..fa8206e569 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js @@ -0,0 +1,52 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Return abrupt String, when StringToBigInt returns NaN +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(SyntaxError, function() { + typedArray.set(["definately not a number"]); + }, "StringToBigInt(prim) == NaN"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/string-tobigint.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/string-tobigint.js new file mode 100644 index 0000000000..5d6221b1ff --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/string-tobigint.js @@ -0,0 +1,68 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Behavior for input array of Strings, successful conversion +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(2); + typedArray.set(['', '1']) + + assert.sameValue(typedArray[0], 0n); + assert.sameValue(typedArray[1], 1n); + + assert.throws(SyntaxError, function() { + typedArray.set(['1n']); + }, "A StringNumericLiteral may not include a BigIntLiteralSuffix."); + + assert.throws(SyntaxError, function() { + typedArray.set(["Infinity"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity.."); + + assert.throws(SyntaxError, function() { + typedArray.set(["1.1"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... decimal points..."); + + assert.throws(SyntaxError, function() { + typedArray.set(["1e7"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... exponents..."); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/symbol-tobigint.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/symbol-tobigint.js new file mode 100644 index 0000000000..a8bdad37af --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/symbol-tobigint.js @@ -0,0 +1,52 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Return abrupt on Symbol +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Symbol + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray, Symbol] +---*/ + +var s = Symbol() + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1) + + assert.throws(TypeError, function() { + typedArray.set([s]); + }, "abrupt completion from Symbol"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js new file mode 100644 index 0000000000..2e517ead14 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js @@ -0,0 +1,35 @@ +// 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.set-typedarray-offset +description: > + Throw a RangeError exception if targetOffset < 0 +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(RangeError, function() { + sample.set(sample, -1); + }, "-1"); + + assert.throws(RangeError, function() { + sample.set(sample, -1.00001); + }, "-1.00001"); + + assert.throws(RangeError, function() { + sample.set(sample, -Infinity); + }, "-Infinity"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js new file mode 100644 index 0000000000..6ea2c61915 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js @@ -0,0 +1,95 @@ +// 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.set-typedarray-offset +description: > + ToInteger(offset) operations +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + var src = new TA([42n]); + + sample = new TA([1n, 2n]); + sample.set(src, ""); + assert(compareArray(sample, [42n, 2n]), "the empty string"); + + sample = new TA([1n, 2n]); + sample.set(src, "0"); + assert(compareArray(sample, [42n, 2n]), "'0'"); + + sample = new TA([1n, 2n]); + sample.set(src, false); + assert(compareArray(sample, [42n, 2n]), "false"); + + sample = new TA([1n, 2n]); + sample.set(src, 0.1); + assert(compareArray(sample, [42n, 2n]), "0.1"); + + sample = new TA([1n, 2n]); + sample.set(src, 0.9); + assert(compareArray(sample, [42n, 2n]), "0.9"); + + sample = new TA([1n, 2n]); + sample.set(src, -0.5); + assert(compareArray(sample, [42n, 2n]), "-0.5"); + + sample = new TA([1n, 2n]); + sample.set(src, 1.1); + assert(compareArray(sample, [1n, 42n]), "1.1"); + + sample = new TA([1n, 2n]); + sample.set(src, NaN); + assert(compareArray(sample, [42n, 2n]), "NaN"); + + sample = new TA([1n, 2n]); + sample.set(src, null); + assert(compareArray(sample, [42n, 2n]), "null"); + + sample = new TA([1n, 2n]); + sample.set(src, undefined); + assert(compareArray(sample, [42n, 2n]), "undefined"); + + sample = new TA([1n, 2n]); + sample.set(src, {}); + assert(compareArray(sample, [42n, 2n]), "{}"); + + sample = new TA([1n, 2n]); + sample.set(src, []); + assert(compareArray(sample, [42n, 2n]), "[]"); + + sample = new TA([1n, 2n]); + sample.set(src, [0]); + assert(compareArray(sample, [42n, 2n]), "[0]"); + + sample = new TA([1n, 2n]); + sample.set(src, true); + assert(compareArray(sample, [1n, 42n]), "true"); + + sample = new TA([1n, 2n]); + sample.set(src, "1"); + assert(compareArray(sample, [1n, 42n]), "'1'"); + + sample = new TA([1n, 2n]); + sample.set(src, [1]); + assert(compareArray(sample, [1n, 42n]), "[1]"); + + sample = new TA([1n, 2n]); + sample.set(src, { valueOf: function() {return 1;} }); + assert(compareArray(sample, [1n, 42n]), "valueOf"); + + sample = new TA([1n, 2n]); + sample.set(src, { toString: function() {return 1;} }); + assert(compareArray(sample, [1n, 42n]), "toString"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js new file mode 100644 index 0000000000..8826a30fea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js @@ -0,0 +1,28 @@ +// 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.set-typedarray-offset +description: > + Return abrupt from ToInteger(Symbol offset) +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.set(sample, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js new file mode 100644 index 0000000000..ba7bd03aa5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js @@ -0,0 +1,42 @@ +// 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.set-typedarray-offset +description: > + Return abrupt from ToInteger(offset) +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.set(sample, obj1); + }, "abrupt from valueOf"); + + assert.throws(Test262Error, function() { + sample.set(sample, obj2); + }, "abrupt from toString"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js new file mode 100644 index 0000000000..64b050832e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js @@ -0,0 +1,107 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sab = new SharedArrayBuffer(2 * BigInt64Array.BYTES_PER_ELEMENT); + var otherCtor = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src = new otherCtor(sab); + src[0] = 42n; + src[1] = 43n; + var sample, result; + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + src = new BigInt64Array([42n, 43n]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + var sab1 = new SharedArrayBuffer(2 * BigInt64Array.BYTES_PER_ELEMENT); + src = new BigInt64Array(sab1); + src[0] = 42n; + src[1] = 43n; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js new file mode 100644 index 0000000000..85c1cd33a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js @@ -0,0 +1,50 @@ +// 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.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + ... + 28. Else, + a. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + value). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src = new other([42n, 43n]); + var sample, result; + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js new file mode 100644 index 0000000000..25222ac4c7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js @@ -0,0 +1,107 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + + var sab = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + var src = new TA(sab); + src[0] = 42n; + src[1] = 43n; + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + src = new TA([42n, 43n]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + var sab1 = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + src = new TA(sab1); + src[0] = 42n; + src[1] = 43n; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js new file mode 100644 index 0000000000..95b210ba3a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js @@ -0,0 +1,52 @@ +// 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.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + a. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the source + data. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). + ... + 29. Return undefined. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + var src = new TA([42n, 43n]); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-resized.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-resized.js new file mode 100644 index 0000000000..64cb878109 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-resized.js @@ -0,0 +1,48 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor when underlying ArrayBuffer has been resized +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var source = new TA(ab); + var target = new TA(ab); + var expected = [10, 20, 30, 40]; + + source[0] = 10n; + source[1] = 20n; + source[2] = 30n; + source[3] = 40n; + + try { + ab.resize(BPE * 5); + expected = [10n, 20n, 30n, 40n, 0n]; + } catch (_) {} + + target.set(source); + assert(compareArray(target, expected), 'following grow'); + + try { + ab.resize(BPE * 3); + expected = [10n, 20n, 30n]; + } catch (_) {} + + target.set(source); + assert(compareArray(target, expected), 'following shrink'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js new file mode 100644 index 0000000000..d3c4b75a69 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js @@ -0,0 +1,52 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src, result, sab; + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, [1n, 2n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 1n, 2n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 1n, 2n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js new file mode 100644 index 0000000000..98dba8b03d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js @@ -0,0 +1,55 @@ +// 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.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + a. Let srcBuffer be ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, + %ArrayBuffer%). + b. NOTE: %ArrayBuffer% is used to clone srcBuffer because is it known to not + have any observable side-effects. + ... + ... + 27. If SameValue(srcType, targetType) is true, then, + a. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the source + data. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src, result; + + sample = new TA([1n, 2n, 3n, 4n]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, [1n, 2n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 1n, 2n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 1n, 2n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js new file mode 100644 index 0000000000..23a5f1b52f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js @@ -0,0 +1,43 @@ +// 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.set-typedarray-offset +description: > + Uses typedArray's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 42; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(src, "length", desc); + + sample.set(src); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js new file mode 100644 index 0000000000..0925356525 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Uses typedArray's internal [[ByteOffset]] +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 21. Let srcByteOffset be typedArray.[[ByteOffset]]. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "byteOffset", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42n, 43n]); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src2 = new other([42n, 43n]); + var src3 = new other(sample.buffer, 0, 2); + + Object.defineProperty(TA.prototype, "byteOffset", desc); + Object.defineProperty(src, "byteOffset", desc); + Object.defineProperty(src2, "byteOffset", desc); + Object.defineProperty(src3, "byteOffset", desc); + + sample.set(src); + sample.set(src2); + sample.set(src3); + + assert.sameValue(getCalls, 0, "ignores byteOffset properties"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js new file mode 100644 index 0000000000..ad6a51c6ca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js @@ -0,0 +1,53 @@ +// 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.set-typedarray-offset +description: > + If srcLength + targetOffset > targetLength, throw a RangeError exception. +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src; + + sample = new TA(2); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, 1); + }, "2 + 1 > 2"); + + sample = new TA(1); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, 0); + }, "2 + 0 > 1"); + + sample = new TA(1); + src = new TA(0); + assert.throws(RangeError, function() { + sample.set(src, 2); + }, "0 + 2 > 1"); + + sample = new TA(2); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, Infinity); + }, "2 + Infinity > 2"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js new file mode 100644 index 0000000000..9d5a06f9cd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js @@ -0,0 +1,41 @@ +// 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.set-typedarray-offset +description: > + Throws a TypeError if srcBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 11. Let srcBuffer be the value of typedArray's [[ViewedArrayBuffer]] internal + slot. + 12. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var target = new TA(); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(target.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set(target, obj); + }); + + assert.sameValue(calledOffset, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js new file mode 100644 index 0000000000..59b3c42d53 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js @@ -0,0 +1,44 @@ +// 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.set-typedarray-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + 2. Let target be the this value. + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.set(src); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js new file mode 100644 index 0000000000..eee371cf8c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js @@ -0,0 +1,46 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + 2. Let target be the this value. + ... + 16. Let targetByteOffset be target.[[ByteOffset]]. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "byteOffset", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42n, 43n]); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src2 = new other([42n, 43n]); + var src3 = new other(sample.buffer, 0, 2); + + Object.defineProperty(TA.prototype, "byteOffset", desc); + Object.defineProperty(sample, "byteOffset", desc); + + sample.set(src); + sample.set(src2); + sample.set(src3); + + assert.sameValue(getCalls, 0, "ignores byteoffset properties"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds.js new file mode 100644 index 0000000000..81abb84936 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds.js @@ -0,0 +1,46 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: Error when target TypedArray fails boundary checks +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.set, + 'function', + 'implements TypedArray.prototype.set' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 4}); + var target = new TA(ab, 0, 4); + var source = new TA(new ArrayBuffer(BPE * 4)); + + var expectedError; + try { + ab.resize(BPE * 3); + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reverse operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + target.set(source, 0); + throw new Test262Error('The `set` operation completed successfully.'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js new file mode 100644 index 0000000000..feb05e05f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js @@ -0,0 +1,41 @@ +// 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.set-typedarray-offset +description: > + Throws a TypeError if targetBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA(1); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(sample.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set(src, obj); + }); + + assert.sameValue(calledOffset, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/undefined-tobigint.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/undefined-tobigint.js new file mode 100644 index 0000000000..817a873885 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/undefined-tobigint.js @@ -0,0 +1,49 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Return abrupt on undefined +info: | + %TypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this TypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + TypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Undefined + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray.set([undefined]); + }, "abrupt completion from undefined"); + +}); + +reportCompare(0, 0); |