summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/set
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/set')
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js37
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js97
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-primitive-toobject.js51
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js46
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js29
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js74
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values.js65
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js51
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js45
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js90
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js89
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/boolean-tobigint.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/null-tobigint.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/number-tobigint.js74
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-big.js40
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js39
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/string-tobigint.js68
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/symbol-tobigint.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js95
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js28
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js42
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js107
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js107
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-resized.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js55
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js53
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js44
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js46
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds.js46
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/BigInt/undefined-tobigint.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-negative-integer-offset-throws.js37
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-offset-tointeger.js97
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-primitive-toobject.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-length.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-value.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length-symbol.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value-symbol.js46
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset-symbol.js29
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-toobject-offset.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-set-values-in-order.js74
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-set-values.js65
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js33
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-type-conversions.js51
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-src-values-are-not-cached.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-target-arraylength-internal.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js38
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-throws.js45
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/bit-precision.js37
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/invoked-as-func.js23
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/invoked-as-method.js23
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/length.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/name.js29
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/prop-desc.js21
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/shell.js66
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/src-typedarray-big-throws.js39
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/this-is-not-object.js77
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/this-is-not-typedarray-instance.js58
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-negative-integer-offset-throws.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-offset-tointeger.js95
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js28
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset.js42
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js54
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions.js40
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js110
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js110
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js62
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-resized.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js54
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type.js55
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-src-arraylength-internal.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-src-byteoffset-internal.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js53
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-target-arraylength-internal.js44
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-target-byteoffset-internal.js46
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-target-out-of-bounds.js46
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js41
106 files changed, 5222 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..d1f6a00315
--- /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| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// 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..743bc563d4
--- /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| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// 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);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-negative-integer-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-negative-integer-offset-throws.js
new file mode 100644
index 0000000000..a181191cc9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(4);
+
+ assert.throws(RangeError, function() {
+ sample.set([1], -1);
+ }, "-1");
+
+ assert.throws(RangeError, function() {
+ sample.set([1], -1.00001);
+ }, "-1.00001");
+
+ assert.throws(RangeError, function() {
+ sample.set([1], -Infinity);
+ }, "-Infinity");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-offset-tointeger.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-offset-tointeger.js
new file mode 100644
index 0000000000..dbf9ca1d3f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+
+ sample = new TA([1, 2]);
+ sample.set([42], "");
+ assert(compareArray(sample, [42, 2]), "the empty string");
+
+ sample = new TA([1, 2]);
+ sample.set([42], "0");
+ assert(compareArray(sample, [42, 2]), "'0'");
+
+ sample = new TA([1, 2]);
+ sample.set([42], false);
+ assert(compareArray(sample, [42, 2]), "false");
+
+ sample = new TA([1, 2]);
+ sample.set([42], 0.1);
+ assert(compareArray(sample, [42, 2]), "0.1");
+
+ sample = new TA([1, 2]);
+ sample.set([42], 0.9);
+ assert(compareArray(sample, [42, 2]), "0.9");
+
+ sample = new TA([1, 2]);
+ sample.set([42], -0.5);
+ assert(compareArray(sample, [42, 2]), "-0.5");
+
+ sample = new TA([1, 2]);
+ sample.set([42], 1.1);
+ assert(compareArray(sample, [1, 42]), "1.1");
+
+ sample = new TA([1, 2]);
+ sample.set([42], NaN);
+ assert(compareArray(sample, [42, 2]), "NaN");
+
+ sample = new TA([1, 2]);
+ sample.set([42], null);
+ assert(compareArray(sample, [42, 2]), "null");
+
+ sample = new TA([1, 2]);
+ sample.set([42], undefined);
+ assert(compareArray(sample, [42, 2]), "undefined");
+
+ sample = new TA([1, 2]);
+ sample.set([42], {});
+ assert(compareArray(sample, [42, 2]), "{}");
+
+ sample = new TA([1, 2]);
+ sample.set([42], []);
+ assert(compareArray(sample, [42, 2]), "[]");
+
+ sample = new TA([1, 2]);
+ sample.set([42], [0]);
+ assert(compareArray(sample, [42, 2]), "[0]");
+
+ sample = new TA([1, 2]);
+ sample.set([42], true);
+ assert(compareArray(sample, [1, 42]), "true");
+
+ sample = new TA([1, 2]);
+ sample.set([42], "1");
+ assert(compareArray(sample, [1, 42]), "'1'");
+
+ sample = new TA([1, 2]);
+ sample.set([42], [1]);
+ assert(compareArray(sample, [1, 42]), "[1]");
+
+ sample = new TA([1, 2]);
+ sample.set([42], { valueOf: function() {return 1;} });
+ assert(compareArray(sample, [1, 42]), "valueOf");
+
+ sample = new TA([1, 2]);
+ sample.set([42], { toString: function() {return 1;} });
+ assert(compareArray(sample, [1, 42]), "toString");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-primitive-toobject.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-primitive-toobject.js
new file mode 100644
index 0000000000..ed577e2012
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-primitive-toobject.js
@@ -0,0 +1,48 @@
+// 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).
+ [...]
+ d. Otherwise, set value to ? ToNumber(value).
+ [...]
+ f. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, Unordered).
+ [...]
+includes: [testTypedArray.js, compareArray.js]
+features: [TypedArray, Symbol]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta1 = new TA([1, 2, 3, 4, 5]);
+ ta1.set("678", 1);
+ assert.compareArray(ta1, [1, 6, 7, 8, 5], "string");
+
+ var ta2 = new TA([1, 2, 3]);
+ ta2.set(0);
+ assert.compareArray(ta2, [1, 2, 3], "number");
+
+ var ta3 = new TA([1, 2, 3]);
+ ta3.set(true, 2);
+ assert.compareArray(ta3, [1, 2, 3], "boolean");
+
+ var ta4 = new TA([1]);
+ ta4.set(Symbol());
+ assert.compareArray(ta4, [1], "symbol");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-length.js
new file mode 100644
index 0000000000..cfbf10dbea
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var obj = {};
+Object.defineProperty(obj, "length", {
+ get: function() {
+ throw new Test262Error();
+ }
+});
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([1, 2, 3]);
+
+ assert.throws(Test262Error, function() {
+ sample.set(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-value.js
new file mode 100644
index 0000000000..bec35b327b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var obj = {
+ length: 4,
+ "0": 42,
+ "1": 43,
+ "3": 44
+ };
+ Object.defineProperty(obj, "2", {
+ get: function() {
+ throw new Test262Error();
+ }
+ });
+
+ var sample = new TA([1, 2, 3, 4]);
+
+ assert.throws(Test262Error, function() {
+ sample.set(obj);
+ });
+
+ assert(
+ compareArray(sample, [42, 43, 3, 4]),
+ "values are set until exception"
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length-symbol.js
new file mode 100644
index 0000000000..07c226e5b7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var obj = {
+ length: Symbol("1")
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([1, 2, 3]);
+
+ assert.throws(TypeError, function() {
+ sample.set(obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length.js
new file mode 100644
index 0000000000..c046c5c12d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var obj1 = {
+ length: {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+ }
+};
+
+var obj2 = {
+ length: {
+ toString: function() {
+ throw new Test262Error();
+ }
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([1, 2, 3]);
+
+ 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/array-arg-return-abrupt-from-src-tonumber-value-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value-symbol.js
new file mode 100644
index 0000000000..ef71d78dd0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var obj = {
+ length: 4,
+ "0": 42,
+ "1": 43,
+ "2": Symbol("1"),
+ "3": 44
+ };
+
+ var sample = new TA([1, 2, 3, 4]);
+
+ assert.throws(TypeError, function() {
+ sample.set(obj);
+ });
+
+ assert(
+ compareArray(sample, [42, 43, 3, 4]),
+ "values are set until exception"
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value.js
new file mode 100644
index 0000000000..79a87c36b3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var obj = {
+ length: 4,
+ "0": 42,
+ "1": 43,
+ "2": {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+ },
+ "3": 44
+ };
+
+ var sample = new TA([1, 2, 3, 4]);
+
+ assert.throws(Test262Error, function() {
+ sample.set(obj);
+ });
+
+ assert(
+ compareArray(sample, [42, 43, 3, 4]),
+ "values are set until exception"
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset-symbol.js
new file mode 100644
index 0000000000..ae70c2693e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var s = Symbol("1");
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+
+ assert.throws(TypeError, function() {
+ sample.set([1], s);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset.js
new file mode 100644
index 0000000000..a2afd09f7e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var obj1 = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+var obj2 = {
+ toString: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithTypedArrayConstructors(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/array-arg-return-abrupt-from-toobject-offset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-return-abrupt-from-toobject-offset.js
new file mode 100644
index 0000000000..f479186b51
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([1, 2, 3]);
+
+ 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/array-arg-set-values-in-order.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-set-values-in-order.js
new file mode 100644
index 0000000000..e74106d4c7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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 42;
+ }
+ });
+
+ Object.defineProperty(obj, 1, {
+ get: function() {
+ calls.push(1);
+ calls.push(sample.join());
+ return 43;
+ }
+ });
+
+ Object.defineProperty(obj, 2, {
+ get: function() {
+ calls.push(2);
+ calls.push(sample.join());
+ return 44;
+ }
+ });
+
+ Object.defineProperty(obj, 3, {
+ get: function() {
+ throw new Test262Error("Should not call obj[3]");
+ }
+ });
+
+ sample.set(obj, 1);
+
+ assert(
+ compareArray(sample, [0, 42, 43, 44, 0]),
+ "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/array-arg-set-values.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-set-values.js
new file mode 100644
index 0000000000..4a5c4acb8a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var src = [42, 43];
+ var srcObj = {
+ length: 2,
+ '0': 7,
+ '1': 17
+ };
+ var sample, result;
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "offset: 2, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(srcObj, 0);
+ assert(compareArray(sample, [7, 17, 3, 4]), "offset: 0, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(srcObj, 1);
+ assert(compareArray(sample, [1, 7, 17, 4]), "offset: 1, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(srcObj, 2);
+ assert(compareArray(sample, [1, 2, 7, 17]), "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/array-arg-src-tonumber-value-conversions.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js
new file mode 100644
index 0000000000..fe4bef4fe0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js
@@ -0,0 +1,33 @@
+// 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 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: [byteConversionValues.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) {
+ var sample = new TA([initial]);
+
+ sample.set([value]);
+
+ assert.sameValue(sample[0], expected, "["+value+"] => ["+expected +"]");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-type-conversions.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-src-tonumber-value-type-conversions.js
new file mode 100644
index 0000000000..135588343b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var obj1 = {
+ valueOf: function() {
+ return 42;
+ }
+ };
+
+ var obj2 = {
+ toString: function() {
+ return "42";
+ }
+ };
+
+ var arr = ["1", "", false, true, null, obj1, obj2, [], [1]];
+
+ var sample = new TA(arr.length);
+ var expected = new TA([1, 0, 0, 1, 0, 42, 42, 0, 1]);
+
+ 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/array-arg-src-values-are-not-cached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-src-values-are-not-cached.js
new file mode 100644
index 0000000000..b2440a89db
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(5);
+ var obj = {
+ length: 5,
+ '1': 7,
+ '2': 7,
+ '3': 7,
+ '4': 7
+ };
+ Object.defineProperty(obj, 0, {
+ get: function() {
+ obj[1] = 43;
+ obj[2] = 44;
+ obj[3] = 45;
+ obj[4] = 46;
+ return 42;
+ }
+ });
+
+ sample.set(obj);
+
+ assert(compareArray(sample, [42, 43, 44, 45, 46]));
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-target-arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-target-arraylength-internal.js
new file mode 100644
index 0000000000..8992c3eb34
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var getCalls = 0;
+var desc = {
+ get: function() {
+ getCalls++;
+ return 0;
+ }
+};
+
+Object.defineProperty(TypedArray.prototype, "length", desc);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+
+ Object.defineProperty(TA.prototype, "length", desc);
+ Object.defineProperty(sample, "length", desc);
+
+ sample.set([42, 43]);
+
+ assert.sameValue(getCalls, 0, "ignores length properties");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js
new file mode 100644
index 0000000000..e67af3acb5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js
@@ -0,0 +1,38 @@
+// Copyright (C) 2022 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: >
+ Does not throw if target TA is detached mid-iteration
+includes: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([1, 2, 3]);
+ var obj = {
+ length: 3,
+ "0": 42
+ };
+ Object.defineProperty(obj, 1, {
+ get: function() {
+ $DETACHBUFFER(sample.buffer);
+ }
+ });
+ let get2Called = false;
+ Object.defineProperty(obj, 2, {
+ get: function() {
+ get2Called = true;
+ return 2;
+ }
+ });
+
+ sample.set(obj);
+
+ assert.sameValue(true, get2Called);
+ assert.sameValue(0, sample.byteLength);
+ assert.sameValue(0, sample.byteOffset);
+ assert.sameValue(0, sample.length);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js
new file mode 100644
index 0000000000..8cf8a6ffb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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([1], obj);
+ });
+
+ assert.sameValue(calledOffset, 1);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/array-arg-targetbuffer-detached-throws.js
new file mode 100644
index 0000000000..aaf0b2ef01
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+var obj = {};
+Object.defineProperty(obj, "length", {
+ get: function() {
+ throw new Test262Error();
+ }
+});
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+ $DETACHBUFFER(sample.buffer);
+
+ assert.throws(TypeError, function() {
+ sample.set([1]);
+ }, "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/bit-precision.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/bit-precision.js
new file mode 100644
index 0000000000..dd56f5e98a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/bit-precision.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.2
+description: Preservation of bit-level encoding
+info: |
+ [...]
+ 28. Else,
+ 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).
+ iii. Set srcByteIndex to srcByteIndex + 1.
+ iv. Set targetByteIndex to targetByteIndex + 1.
+includes: [nans.js, compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+function body(FA) {
+ var source = new FA(NaNs);
+ var target = new FA(NaNs.length);
+ var sourceBytes, targetBytes;
+
+ target.set(source);
+
+ sourceBytes = new Uint8Array(source.buffer);
+ targetBytes = new Uint8Array(target.buffer);
+
+ assert(compareArray(sourceBytes, targetBytes))
+}
+
+testWithTypedArrayConstructors(body, floatArrayConstructors);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/browser.js
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/invoked-as-func.js
new file mode 100644
index 0000000000..3201477ce0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/invoked-as-func.js
@@ -0,0 +1,23 @@
+// 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
+description: Throws a TypeError exception when invoked as a function
+info: |
+ 22.2.3.22 %TypedArray%.prototype.set ( overloaded [ , offset ])
+
+ This function is not generic. The this value must be an object with a
+ [[TypedArrayName]] internal slot.
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var set = TypedArray.prototype.set;
+
+assert.sameValue(typeof set, 'function');
+
+assert.throws(TypeError, function() {
+ set();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/invoked-as-method.js
new file mode 100644
index 0000000000..9636b4a1de
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/invoked-as-method.js
@@ -0,0 +1,23 @@
+// 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
+description: Requires a [[TypedArrayName]] internal slot.
+info: |
+ 22.2.3.22 %TypedArray%.prototype.set ( overloaded [ , offset ])
+
+ This function is not generic. The this value must be an object with a
+ [[TypedArrayName]] internal slot.
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+
+assert.sameValue(typeof TypedArrayPrototype.set, 'function');
+
+assert.throws(TypeError, function() {
+ TypedArrayPrototype.set();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/length.js
new file mode 100644
index 0000000000..83ece00244
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/length.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.set
+description: >
+ %TypedArray%.prototype.set.length is 1.
+info: |
+ %TypedArray%.prototype.set ( overloaded [ , offset ])
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, has a length
+ property whose value is an integer. Unless otherwise specified, this
+ value is equal to the largest number of named arguments shown in the
+ subclause headings for the function description, including optional
+ parameters. However, rest parameters shown using the form “...name”
+ are not included in the default argument count.
+
+ Unless otherwise specified, the length property of a built-in Function
+ object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
+ [[Configurable]]: true }.
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+assert.sameValue(TypedArray.prototype.set.length, 1);
+
+verifyNotEnumerable(TypedArray.prototype.set, "length");
+verifyNotWritable(TypedArray.prototype.set, "length");
+verifyConfigurable(TypedArray.prototype.set, "length");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/name.js
new file mode 100644
index 0000000000..cdaf0d8382
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/name.js
@@ -0,0 +1,29 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.set
+description: >
+ %TypedArray%.prototype.set.name is "set".
+info: |
+ %TypedArray%.prototype.set ( overloaded [ , offset ])
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, that is not
+ identified as an anonymous function has a name property whose value
+ is a String.
+
+ Unless otherwise specified, the name property of a built-in Function
+ object, if it exists, has the attributes { [[Writable]]: false,
+ [[Enumerable]]: false, [[Configurable]]: true }.
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+assert.sameValue(TypedArray.prototype.set.name, "set");
+
+verifyNotEnumerable(TypedArray.prototype.set, "name");
+verifyNotWritable(TypedArray.prototype.set, "name");
+verifyConfigurable(TypedArray.prototype.set, "name");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/not-a-constructor.js
new file mode 100644
index 0000000000..818ea73dbd
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/not-a-constructor.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+ TypedArray.prototype.set does not implement [[Construct]], is not new-able
+info: |
+ ECMAScript Function Objects
+
+ Built-in function objects that are not identified as constructors do not
+ implement the [[Construct]] internal method unless otherwise specified in
+ the description of a particular function.
+
+ sec-evaluatenew
+
+ ...
+ 7. If IsConstructor(constructor) is false, throw a TypeError exception.
+ ...
+includes: [isConstructor.js, testTypedArray.js]
+features: [Reflect.construct, arrow-function, TypedArray]
+---*/
+
+assert.sameValue(
+ isConstructor(TypedArray.prototype.set),
+ false,
+ 'isConstructor(TypedArray.prototype.set) must return false'
+);
+
+assert.throws(TypeError, () => {
+ let u8 = new Uint8Array(1); new u8.set([0], 0);
+}, '`let u8 = new Uint8Array(1); new u8.set([0], 0)` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/prop-desc.js
new file mode 100644
index 0000000000..6c78673324
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/prop-desc.js
@@ -0,0 +1,21 @@
+// 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
+description: >
+ "set" property of TypedArrayPrototype
+info: |
+ ES6 section 17: Every other data property described in clauses 18 through 26
+ and in Annex B.2 has the attributes { [[Writable]]: true,
+ [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified.
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+
+verifyNotEnumerable(TypedArrayPrototype, 'set');
+verifyWritable(TypedArrayPrototype, 'set');
+verifyConfigurable(TypedArrayPrototype, 'set');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/shell.js
new file mode 100644
index 0000000000..b8ead56aef
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/shell.js
@@ -0,0 +1,66 @@
+// GENERATED, DO NOT EDIT
+// file: isConstructor.js
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: |
+ Test if a given function is a constructor function.
+defines: [isConstructor]
+features: [Reflect.construct]
+---*/
+
+function isConstructor(f) {
+ if (typeof f !== "function") {
+ throw new Test262Error("isConstructor invoked with a non-function value");
+ }
+
+ try {
+ Reflect.construct(function(){}, [], f);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
+
+// file: testBigIntTypedArray.js
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: |
+ Collection of functions used to assert the correctness of BigInt TypedArray objects.
+defines:
+ - TypedArray
+ - testWithBigIntTypedArrayConstructors
+---*/
+
+/**
+ * The %TypedArray% intrinsic constructor function.
+ */
+var TypedArray = Object.getPrototypeOf(Int8Array);
+
+/**
+ * Calls the provided function for every typed array constructor.
+ *
+ * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
+ * @param {Array} selected - An optional Array with filtered typed arrays
+ */
+function testWithBigIntTypedArrayConstructors(f, selected) {
+ /**
+ * Array containing every BigInt typed array constructor.
+ */
+ var constructors = selected || [
+ BigInt64Array,
+ BigUint64Array
+ ];
+
+ for (var i = 0; i < constructors.length; ++i) {
+ var constructor = constructors[i];
+ try {
+ f(constructor);
+ } catch (e) {
+ e.message += " (Testing with " + constructor.name + ".)";
+ throw e;
+ }
+ }
+}
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/src-typedarray-big-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/src-typedarray-big-throws.js
new file mode 100644
index 0000000000..bd388c9953
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/src-typedarray-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 a Big(U)Int, and target not "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;
+
+testWithBigIntTypedArrayConstructors(function(BTA) {
+
+ bigTypedArray = new BTA([1n]);
+
+ testWithTypedArrayConstructors(function(TA) {
+
+ littleTypedArray = new TA(1);
+ assert.throws(TypeError, function() {
+ littleTypedArray.set(bigTypedArray);
+ });
+ });
+
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/this-is-not-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/this-is-not-object.js
new file mode 100644
index 0000000000..d8b62e11a2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/this-is-not-object.js
@@ -0,0 +1,77 @@
+// 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-overloaded-offset
+description: Throws a TypeError exception when `this` is not Object
+info: |
+ 22.2.3.23 %TypedArray%.prototype.set
+
+ ...
+ 2. Let target be the this value.
+ 3. If Type(target) is not Object, throw a TypeError exception.
+ ...
+includes: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var set = TypedArray.prototype.set;
+
+assert.throws(TypeError, function() {
+ set.call(undefined, []);
+}, "this is undefined");
+
+assert.throws(TypeError, function() {
+ set.call(null, []);
+}, "this is null");
+
+assert.throws(TypeError, function() {
+ set.call(undefined, new Int8Array());
+}, "this is undefined");
+
+assert.throws(TypeError, function() {
+ set.call(null, new Int8Array());
+}, "this is null");
+
+assert.throws(TypeError, function() {
+ set.call(42, []);
+}, "this is 42");
+
+assert.throws(TypeError, function() {
+ set.call("1", []);
+}, "this is a string");
+
+assert.throws(TypeError, function() {
+ set.call(true, []);
+}, "this is true");
+
+assert.throws(TypeError, function() {
+ set.call(false, []);
+}, "this is false");
+
+var s1 = Symbol("s");
+assert.throws(TypeError, function() {
+ set.call(s1, []);
+}, "this is a Symbol");
+
+assert.throws(TypeError, function() {
+ set.call(42, new Int8Array(1));
+}, "this is 42");
+
+assert.throws(TypeError, function() {
+ set.call("1", new Int8Array(1));
+}, "this is a string");
+
+assert.throws(TypeError, function() {
+ set.call(true, new Int8Array(1));
+}, "this is true");
+
+assert.throws(TypeError, function() {
+ set.call(false, new Int8Array(1));
+}, "this is false");
+
+var s2 = Symbol("s");
+assert.throws(TypeError, function() {
+ set.call(s2, new Int8Array(1));
+}, "this is a Symbol");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/this-is-not-typedarray-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/this-is-not-typedarray-instance.js
new file mode 100644
index 0000000000..fdac8e08cd
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/this-is-not-typedarray-instance.js
@@ -0,0 +1,58 @@
+// 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-overloaded-offset
+description: >
+ Throws a TypeError exception when `this` is not a TypedArray instance
+info: |
+ 22.2.3.23 %TypedArray%.prototype.set
+
+ ...
+ 2. Let target be the this value.
+ 3. If Type(target) is not Object, throw a TypeError exception.
+ 4. If target does not have a [[TypedArrayName]] internal slot, throw a
+ TypeError exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var set = TypedArray.prototype.set;
+
+assert.throws(TypeError, function() {
+ set.call({}, []);
+}, "this is an Object");
+
+assert.throws(TypeError, function() {
+ set.call([], []);
+}, "this is an Array");
+
+var ab1 = new ArrayBuffer(8);
+assert.throws(TypeError, function() {
+ set.call(ab1, []);
+}, "this is an ArrayBuffer instance");
+
+var dv1 = new DataView(new ArrayBuffer(8), 0, 1);
+assert.throws(TypeError, function() {
+ set.call(dv1, []);
+}, "this is a DataView instance");
+
+assert.throws(TypeError, function() {
+ set.call({}, new Int8Array());
+}, "this is an Object");
+
+assert.throws(TypeError, function() {
+ set.call([], new Int8Array());
+}, "this is an Array");
+
+var ab2 = new ArrayBuffer(8);
+assert.throws(TypeError, function() {
+ set.call(ab2, new Int8Array());
+}, "this is an ArrayBuffer instance");
+
+var dv2 = new DataView(new ArrayBuffer(8), 0, 1);
+assert.throws(TypeError, function() {
+ set.call(dv2, new Int8Array());
+}, "this is a DataView instance");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-negative-integer-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-negative-integer-offset-throws.js
new file mode 100644
index 0000000000..26a9ef1064
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/typedarray-arg-offset-tointeger.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-offset-tointeger.js
new file mode 100644
index 0000000000..e4c73580bb
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample;
+ var src = new TA([42]);
+
+ sample = new TA([1, 2]);
+ sample.set(src, "");
+ assert(compareArray(sample, [42, 2]), "the empty string");
+
+ sample = new TA([1, 2]);
+ sample.set(src, "0");
+ assert(compareArray(sample, [42, 2]), "'0'");
+
+ sample = new TA([1, 2]);
+ sample.set(src, false);
+ assert(compareArray(sample, [42, 2]), "false");
+
+ sample = new TA([1, 2]);
+ sample.set(src, 0.1);
+ assert(compareArray(sample, [42, 2]), "0.1");
+
+ sample = new TA([1, 2]);
+ sample.set(src, 0.9);
+ assert(compareArray(sample, [42, 2]), "0.9");
+
+ sample = new TA([1, 2]);
+ sample.set(src, -0.5);
+ assert(compareArray(sample, [42, 2]), "-0.5");
+
+ sample = new TA([1, 2]);
+ sample.set(src, 1.1);
+ assert(compareArray(sample, [1, 42]), "1.1");
+
+ sample = new TA([1, 2]);
+ sample.set(src, NaN);
+ assert(compareArray(sample, [42, 2]), "NaN");
+
+ sample = new TA([1, 2]);
+ sample.set(src, null);
+ assert(compareArray(sample, [42, 2]), "null");
+
+ sample = new TA([1, 2]);
+ sample.set(src, undefined);
+ assert(compareArray(sample, [42, 2]), "undefined");
+
+ sample = new TA([1, 2]);
+ sample.set(src, {});
+ assert(compareArray(sample, [42, 2]), "{}");
+
+ sample = new TA([1, 2]);
+ sample.set(src, []);
+ assert(compareArray(sample, [42, 2]), "[]");
+
+ sample = new TA([1, 2]);
+ sample.set(src, [0]);
+ assert(compareArray(sample, [42, 2]), "[0]");
+
+ sample = new TA([1, 2]);
+ sample.set(src, true);
+ assert(compareArray(sample, [1, 42]), "true");
+
+ sample = new TA([1, 2]);
+ sample.set(src, "1");
+ assert(compareArray(sample, [1, 42]), "'1'");
+
+ sample = new TA([1, 2]);
+ sample.set(src, [1]);
+ assert(compareArray(sample, [1, 42]), "[1]");
+
+ sample = new TA([1, 2]);
+ sample.set(src, { valueOf: function() {return 1;} });
+ assert(compareArray(sample, [1, 42]), "valueOf");
+
+ sample = new TA([1, 2]);
+ sample.set(src, { toString: function() {return 1;} });
+ assert(compareArray(sample, [1, 42]), "toString");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js
new file mode 100644
index 0000000000..5672695847
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var s = Symbol("1");
+
+testWithTypedArrayConstructors(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/typedarray-arg-return-abrupt-from-tointeger-offset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset.js
new file mode 100644
index 0000000000..a5f8f15186
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var obj1 = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+var obj2 = {
+ toString: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithTypedArrayConstructors(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/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js
new file mode 100644
index 0000000000..b2eb05f8af
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js
@@ -0,0 +1,54 @@
+// |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 converted values from different buffer of different types and different type instances
+includes: [byteConversionValues.js, testTypedArray.js]
+features: [SharedArrayBuffer]
+---*/
+
+testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) {
+ if (TA === Float64Array || TA === Float32Array || (typeof Float16Array !== 'undefined' && TA === Float16Array) || TA === Uint8ClampedArray) {
+ return;
+ }
+ if (TA === Int32Array) {
+ return;
+ }
+
+ var sab, src, target;
+
+ sab = new SharedArrayBuffer(4);
+ src = new Int32Array(sab);
+ src[0] = value;
+ target = new TA([initial]);
+
+ target.set(src);
+
+ assert.sameValue(target[0], expected, "src is SAB-backed");
+
+ sab = new SharedArrayBuffer(4);
+ src = new Int32Array([value]);
+ target = new TA(sab);
+ target[0] = initial;
+
+ target.set(src);
+
+ assert.sameValue(target[0], expected, "target is SAB-backed");
+
+ var sab1 = new SharedArrayBuffer(4);
+ var sab2 = new SharedArrayBuffer(4);
+ src = new Int32Array(sab1);
+ src[0] = value;
+ target = new TA(sab2);
+ target[0] = initial;
+
+ target.set(src);
+
+ assert.sameValue(target[0], expected, "src and target are SAB-backed");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions.js
new file mode 100644
index 0000000000..8b6f0655ea
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions.js
@@ -0,0 +1,40 @@
+// 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 converted values from different buffer and different type instances
+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: [byteConversionValues.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) {
+ if (TA === Float64Array) {
+ return;
+ }
+ var src = new Float64Array([value]);
+ var target = new TA([initial]);
+
+ target.set(src);
+
+ assert.sameValue(target[0], expected);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js
new file mode 100644
index 0000000000..3e289e32ae
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js
@@ -0,0 +1,110 @@
+// |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: [testTypedArray.js, compareArray.js]
+features: [SharedArrayBuffer, TypedArray]
+---*/
+
+var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
+
+testWithTypedArrayConstructors(function(TA) {
+ var other = Int32Array;
+ var sab = new SharedArrayBuffer(2 * other.BYTES_PER_ELEMENT);
+ var src = new other(sab);
+ src[0] = 42;
+ src[1] = 43;
+ var sample, result;
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+
+ src = new other([42, 43]);
+
+ sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
+ sample = new TA(sab);
+ sample[0] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "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] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "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] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ var sab1 = new SharedArrayBuffer(2 * other.BYTES_PER_ELEMENT);
+ src = new other(sab1);
+ src[0] = 42;
+ src[1] = 43;
+
+ var sab2;
+ sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
+ sample = new TA(sab2);
+ sample[0] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "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] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "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] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+}, int_views);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type.js
new file mode 100644
index 0000000000..75dca6862e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var other = TA === Float32Array ? Float64Array : Float32Array;
+ var src = new other([42, 43]);
+ var sample, result;
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "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/typedarray-arg-set-values-diff-buffer-same-type-sab.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js
new file mode 100644
index 0000000000..c7e109ba8d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js
@@ -0,0 +1,110 @@
+// |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: [testTypedArray.js, compareArray.js]
+features: [SharedArrayBuffer, TypedArray]
+---*/
+
+var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample, result;
+
+ var sab = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT);
+ var src = new TA(sab);
+ src[0] = 42;
+ src[1] = 43;
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+
+ src = new TA([42, 43]);
+
+ sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
+ sample = new TA(sab);
+ sample[0] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "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] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "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] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "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] = 42;
+ src[1] = 43;
+
+ var sab2;
+ sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
+ sample = new TA(sab2);
+ sample[0] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "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] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "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] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+}, int_views);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type.js
new file mode 100644
index 0000000000..1990f48b7d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample, result;
+ var src = new TA([42, 43]);
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 42, 43]), "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/typedarray-arg-set-values-same-buffer-other-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js
new file mode 100644
index 0000000000..d5af3ec6ec
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js
@@ -0,0 +1,62 @@
+// 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 different
+ constructor.
+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,
+ ...
+ 28. Else,
+ a. Repeat, while targetByteIndex < limit
+ i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType).
+ ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType,
+ value).
+ ...
+ 29. Return undefined.
+includes: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+var expected = {
+ Float64Array: [1.0000002464512363, 42, 1.875, 4, 5, 6, 7, 8],
+ Float32Array: [0, 42, 512.0001220703125, 4, 5, 6, 7, 8],
+ Float16Array: [0, 42, 513, 4, 5, 6, 7, 8],
+ Int32Array: [1109917696, 42, 0, 4, 5, 6, 7, 8],
+ Int16Array: [0, 42, 0, 4, 5, 6, 7, 8],
+ Int8Array: [0, 42, 0, 66, 5, 6, 7, 8],
+ Uint32Array: [1109917696, 42, 0, 4, 5, 6, 7, 8],
+ Uint16Array: [0, 42, 0, 4, 5, 6, 7, 8],
+ Uint8Array: [0, 42, 0, 66, 5, 6, 7, 8],
+ Uint8ClampedArray: [0, 42, 0, 66, 5, 6, 7, 8]
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var other = TA === Float32Array ? Float64Array : Float32Array;
+
+ var sample = new TA([1, 2, 3, 4, 5, 6, 7, 8]);
+ var src = new other(sample.buffer, 0, 2);
+
+ // Reflect changes on sample object
+ src[0] = 42;
+
+ var result = sample.set(src, 1);
+
+ assert(compareArray(sample, expected[TA.name]), sample);
+ assert.sameValue(result, undefined, "returns undefined");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-resized.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-resized.js
new file mode 100644
index 0000000000..c50f9a9606
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-resized.js
@@ -0,0 +1,48 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// 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: [testTypedArray.js, compareArray.js]
+features: [TypedArray, resizable-arraybuffer]
+---*/
+
+assert.sameValue(
+ typeof ArrayBuffer.prototype.resize,
+ 'function',
+ 'implements ArrayBuffer.prototype.resize'
+);
+
+testWithTypedArrayConstructors(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] = 10;
+ source[1] = 20;
+ source[2] = 30;
+ source[3] = 40;
+
+ try {
+ ab.resize(BPE * 5);
+ expected = [10, 20, 30, 40, 0];
+ } catch (_) {}
+
+ target.set(source);
+ assert(compareArray(target, expected), 'following grow');
+
+ try {
+ ab.resize(BPE * 3);
+ expected = [10, 20, 30];
+ } 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/typedarray-arg-set-values-same-buffer-same-type-sab.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js
new file mode 100644
index 0000000000..40cf0eecb5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js
@@ -0,0 +1,54 @@
+// |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: [testTypedArray.js, compareArray.js]
+features: [SharedArrayBuffer, TypedArray]
+---*/
+
+var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample, src, result, sab;
+
+ sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
+ sample = new TA(sab);
+ sample[0] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ src = new TA(sample.buffer, 0, 2);
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [1, 2, 3, 4]), "offset: 0, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
+ sample = new TA(sab);
+ sample[0] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ src = new TA(sample.buffer, 0, 2);
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 1, 2, 4]), "offset: 1, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT);
+ sample = new TA(sab);
+ sample[0] = 1;
+ sample[1] = 2;
+ sample[2] = 3;
+ sample[3] = 4;
+ src = new TA(sample.buffer, 0, 2);
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 1, 2]), "offset: 2, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+}, int_views);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type.js
new file mode 100644
index 0000000000..25a20358b0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample, src, result;
+
+ sample = new TA([1, 2, 3, 4]);
+ src = new TA(sample.buffer, 0, 2);
+ result = sample.set(src, 0);
+ assert(compareArray(sample, [1, 2, 3, 4]), "offset: 0, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ src = new TA(sample.buffer, 0, 2);
+ result = sample.set(src, 1);
+ assert(compareArray(sample, [1, 1, 2, 4]), "offset: 1, result: " + sample);
+ assert.sameValue(result, undefined, "returns undefined");
+
+ sample = new TA([1, 2, 3, 4]);
+ src = new TA(sample.buffer, 0, 2);
+ result = sample.set(src, 2);
+ assert(compareArray(sample, [1, 2, 1, 2]), "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/typedarray-arg-src-arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-src-arraylength-internal.js
new file mode 100644
index 0000000000..29e8a8ca3a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var getCalls = 0;
+var desc = {
+ get: function getLen() {
+ getCalls++;
+ return 42;
+ }
+};
+
+Object.defineProperty(TypedArray.prototype, "length", desc);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+ var src = new TA([42, 43]);
+
+ 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/typedarray-arg-src-byteoffset-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-src-byteoffset-internal.js
new file mode 100644
index 0000000000..0d9d251568
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var getCalls = 0;
+var desc = {
+ get: function getLen() {
+ getCalls++;
+ return 0;
+ }
+};
+
+Object.defineProperty(TypedArray.prototype, "byteOffset", desc);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+ var src = new TA([42, 43]);
+ var differentTA = TA === Uint8Array ? Int8Array : Uint8Array;
+ var src2 = new differentTA([42, 43]);
+ var src3 = new differentTA(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/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js
new file mode 100644
index 0000000000..4a4af2c71d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js
new file mode 100644
index 0000000000..a43d522c01
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/typedarray-arg-target-arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-target-arraylength-internal.js
new file mode 100644
index 0000000000..ae3ef5b834
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var getCalls = 0;
+var desc = {
+ get: function() {
+ getCalls++;
+ return 0;
+ }
+};
+
+Object.defineProperty(TypedArray.prototype, "length", desc);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+ var src = new TA([42, 43]);
+
+ 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/typedarray-arg-target-byteoffset-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-target-byteoffset-internal.js
new file mode 100644
index 0000000000..9e852856ec
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var getCalls = 0;
+var desc = {
+ get: function() {
+ getCalls++;
+ return 0;
+ }
+};
+
+Object.defineProperty(TypedArray.prototype, "byteOffset", desc);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+ var src = new TA([42, 43]);
+ var differentTA = TA === Uint8Array ? Int8Array : Uint8Array;
+ var src2 = new differentTA([42, 43]);
+ var src3 = new differentTA(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/typedarray-arg-target-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-target-out-of-bounds.js
new file mode 100644
index 0000000000..bb7cbe0ad2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-target-out-of-bounds.js
@@ -0,0 +1,46 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// 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: [testTypedArray.js]
+features: [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'
+);
+
+testWithTypedArrayConstructors(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/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/set/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js
new file mode 100644
index 0000000000..521772dfff
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/set/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: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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);