summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin')
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js79
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js94
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js94
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js36
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.js51
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-end.js97
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js113
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js95
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js63
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-start.js79
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-target.js55
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js56
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js76
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js75
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js38
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.js37
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.js37
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-this-out-of-bounds.js62
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-this.js38
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/shell.js42
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/bit-precision.js46
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/byteoffset.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end-detached-prototype.js42
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end-detached.js40
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end.js79
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-start-detached.js40
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-start.js94
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-target.js102
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/detached-buffer.js36
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/get-length-ignores-length-prop.js51
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/invoked-as-func.js31
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/invoked-as-method.js31
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/length.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/name.js29
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-end.js97
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js113
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js95
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js63
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-start.js79
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-target.js55
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js56
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js76
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-target-and-start.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-target-start-and-end.js75
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/prop-desc.js21
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-end-is-symbol.js38
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-end.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-start-is-symbol.js37
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-start.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-target-is-symbol.js37
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-target.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds.js62
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-this.js38
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/shell.js24
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/this-is-not-object.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/this-is-not-typedarray-instance.js44
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/undefined-end.js47
65 files changed, 3558 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/browser.js
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js
new file mode 100644
index 0000000000..81c4a3a943
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js
@@ -0,0 +1,79 @@
+// 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.copywithin
+description: >
+ end argument is coerced to an integer values.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, null),
+ [0n, 1n, 2n, 3n]
+ ),
+ 'null value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, NaN),
+ [0n, 1n, 2n, 3n]
+ ),
+ 'NaN value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, false),
+ [0n, 1n, 2n, 3n]
+ ),
+ 'false value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, true),
+ [0n, 0n, 2n, 3n]
+ ),
+ 'true value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, '-2'),
+ [0n, 0n, 1n, 3n]
+ ),
+ 'string "-2" value coerced to integer -2'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, -2.5),
+ [0n, 0n, 1n, 3n]
+ ),
+ 'float -2.5 value coerced to integer -2'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js
new file mode 100644
index 0000000000..278e95b791
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js
@@ -0,0 +1,94 @@
+// 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.copywithin
+description: >
+ start argument is coerced to an integer value.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 5. Let relativeStart be ? ToInteger(start).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, undefined),
+ [0n, 0n, 1n, 2n]
+ ),
+ 'undefined value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, false),
+ [0n, 0n, 1n, 2n]
+ ),
+ 'false value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, NaN),
+ [0n, 0n, 1n, 2n]
+ ),
+ 'NaN value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, null),
+ [0n, 0n, 1n, 2n]
+ ),
+ 'null value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, true),
+ [1n, 2n, 3n, 3n]
+ ),
+ 'true value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, '1'),
+ [1n, 2n, 3n, 3n]
+ ),
+ 'string "1" value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0.5),
+ [0n, 0n, 1n, 2n]
+ ),
+ '0.5 float value coerced to integer 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1.5),
+ [1n, 2n, 3n, 3n]
+ ),
+ '1.5 float value coerced to integer 1'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js
new file mode 100644
index 0000000000..a5556c519a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js
@@ -0,0 +1,94 @@
+// 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.copywithin
+description: >
+ target argument is coerced to an integer value.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 3. Let relativeTarget be ? ToInteger(target).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(undefined, 1),
+ [1n, 2n, 3n, 3n]
+ ),
+ 'undefined value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(false, 1),
+ [1n, 2n, 3n, 3n]
+ ),
+ 'false value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(NaN, 1),
+ [1n, 2n, 3n, 3n]
+ ),
+ 'NaN value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(null, 1),
+ [1n, 2n, 3n, 3n]
+ ),
+ 'null value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(true, 0),
+ [0n, 0n, 1n, 2n]
+ ),
+ 'true value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin('1', 0),
+ [0n, 0n, 1n, 2n]
+ ),
+ 'string "1" value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0.5, 1),
+ [1n, 2n, 3n, 3n]
+ ),
+ '0.5 float value coerced to integer 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1.5, 0),
+ [0n, 0n, 1n, 2n]
+ ),
+ '1.5 float value coerced to integer 1'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js
new file mode 100644
index 0000000000..f017576090
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js
@@ -0,0 +1,36 @@
+// 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.copywithin
+description: Throws a TypeError if this has a detached buffer
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] )
+
+ This function is not generic. ValidateTypedArray is applied to the this value
+ prior to evaluating the algorithm. If its result is an abrupt completion that
+ exception is thrown instead of evaluating the algorithm.
+
+ 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
+
+ ...
+ 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
+ ...
+includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
+features: [BigInt, TypedArray]
+---*/
+
+var obj = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var sample = new TA(1);
+ $DETACHBUFFER(sample.buffer);
+ assert.throws(TypeError, function() {
+ sample.copyWithin(obj, obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.js
new file mode 100644
index 0000000000..f9e3b903d0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.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.copywithin
+description: >
+ Unreachable abrupt from Get(O, "length") as [[ArrayLength]] is returned.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ 1. Let O be ? ToObject(this value).
+ 2. Let len be ? ToLength(? Get(O, "length")).
+ ...
+includes: [testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+Object.defineProperty(TypedArray.prototype, "length", {
+ get: function() {
+ throw new Test262Error();
+ }
+});
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ Object.defineProperty(TA.prototype, "length", {
+ get: function() {
+ throw new Test262Error();
+ }
+ });
+
+ var sample = new TA();
+ Object.defineProperty(sample, "length", {
+ get: function() {
+ throw new Test262Error();
+ }
+ });
+
+ assert.sameValue(sample.copyWithin(0, 0), sample);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-end.js
new file mode 100644
index 0000000000..f1fde574bd
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-end.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.copywithin
+description: >
+ Set values with negative end argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let
+ final be min(relativeEnd, len).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, -1),
+ [1n, 2n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, -1) -> [1, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(2, 0, -1),
+ [0n, 1n, 0n, 1n, 2n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(2, 0, -1) -> [0, 1, 0, 1, 2]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(1, 2, -2),
+ [0n, 2n, 2n, 3n, 4n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(1, 2, -2) -> [0, 2, 2, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, -2, -1),
+ [2n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, -2, -1) -> [2, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(2, -2, -1),
+ [0n, 1n, 3n, 3n, 4n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(2, -2, 1) -> [0, 1, 3, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(-3, -2, -1),
+ [0n, 2n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(-3, -2, -1) -> [0, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-2, -3, -1),
+ [0n, 1n, 2n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-2, -3, -1) -> [0, 1, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-5, -2, -1),
+ [3n, 1n, 2n, 3n, 4n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-5, -2, -1) -> [3, 1, 2, 3, 4]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js
new file mode 100644
index 0000000000..55710a2447
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js
@@ -0,0 +1,113 @@
+// 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.copywithin
+description: >
+ Set values with negative out of bounds end argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let
+ final be min(relativeEnd, len).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, -10),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, 1, -Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, -2, -10),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, -2, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, -2, -Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, -9, -10),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, -9, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, -9, -Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(-3, -2, -10),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(-3, -2, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-3, -2, -Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(-7, -8, -9),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(-7, -8, -9) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-7, -8, -Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js
new file mode 100644
index 0000000000..997436c7bc
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.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.copywithin
+description: >
+ Set values with out of bounds negative start argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let
+ from be min(relativeStart, len).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, -10),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3]).copyWithin(0, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, -Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5]).copyWithin(0, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(2, -10),
+ [0n, 1n, 0n, 1n, 2n]
+ ),
+ '[0, 1, 2, 3, 4]).copyWithin(2, -2) -> [0, 1, 0, 1, 2]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(2, -Infinity),
+ [1n, 2n, 1n, 2n, 3n]
+ ),
+ '[1, 2, 3, 4, 5]).copyWithin(2, -Infinity) -> [1, 2, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(10, -10),
+ [0n, 1n, 2n, 3n, 4n]
+ ),
+ '[0, 1, 2, 3, 4]).copyWithin(10, -10) -> [0, 1, 2, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(10, -Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5]).copyWithin(10, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(-9, -10),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(-9, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-9, -Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-9, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js
new file mode 100644
index 0000000000..925be0ce7c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js
@@ -0,0 +1,63 @@
+// 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.copywithin
+description: >
+ Set values with out of bounds negative target argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let
+ to be min(relativeTarget, len).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(-10, 0),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(-10, 0) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-Infinity, 0),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-Infinity, 0) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-10, 2),
+ [2n, 3n, 4n, 3n, 4n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-10, 2) -> [2, 3, 4, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-Infinity, 2),
+ [3n, 4n, 5n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-Infinity, 2) -> [3, 4, 5, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-start.js
new file mode 100644
index 0000000000..d7ac9c82b8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-start.js
@@ -0,0 +1,79 @@
+// 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.copywithin
+description: >
+ Set values with negative start argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let
+ from be min(relativeStart, len).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, -1),
+ [3n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, -1) -> [3, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(2, -2),
+ [0n, 1n, 3n, 4n, 4n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(2, -2) -> [0, 1, 3, 4, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(1, -2),
+ [0n, 3n, 4n, 3n, 4n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(1, -2) -> [0, 3, 4, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(-1, -2),
+ [0n, 1n, 2n, 2n]
+ ),
+ '[0, 1, 2, 3].copyWithin(-1, -2) -> [ 0, 1, 2, 2 ]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-2, -3),
+ [0n, 1n, 2n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-2, -3) -> [0, 1, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-5, -2),
+ [3n, 4n, 2n, 3n, 4n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-5, -2) -> [3, 4, 2, 3, 4]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-target.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-target.js
new file mode 100644
index 0000000000..286910f628
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-target.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.copywithin
+description: >
+ Set values with negative target argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let
+ to be min(relativeTarget, len).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(-1, 0),
+ [0n, 1n, 2n, 0n]
+ ),
+ '[0, 1, 2, 3].copyWithin(-1, 0) -> [0, 1, 2, 0]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-2, 2),
+ [0n, 1n, 2n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-2, 2) -> [0, 1, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(-1, 2),
+ [0n, 1n, 2n, 2n]
+ ),
+ '[0, 1, 2, 3].copyWithin(-1, 2) -> [0, 1, 2, 2]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js
new file mode 100644
index 0000000000..45440750fb
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js
@@ -0,0 +1,56 @@
+// 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.copywithin
+description: >
+ Max value of end position is the this.length.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, 6),
+ [1n, 2n, 3n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, 6) -> [1, 2, 3, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, 1, Infinity),
+ [2n, 3n, 4n, 5n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, 1, Infinity) -> [2, 3, 4, 5, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(1, 3, 6),
+ [0n, 3n, 4n, 5n, 4n, 5n]
+ ),
+ '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6) -> [0, 3, 4, 5, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(1, 3, Infinity),
+ [1n, 4n, 5n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(1, 3, Infinity) -> [1, 4, 5, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js
new file mode 100644
index 0000000000..51f22654a3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js
@@ -0,0 +1,76 @@
+// 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.copywithin
+description: >
+ Max values of target and start positions are this.length.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(6, 0),
+ [0n, 1n, 2n, 3n, 4n, 5n]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(Infinity, 0),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(Infinity, 0) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(0, 6),
+ [0n, 1n, 2n, 3n, 4n, 5n]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(6, 6),
+ [0n, 1n, 2n, 3n, 4n, 5n]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(10, 10),
+ [0n, 1n, 2n, 3n, 4n, 5n]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(Infinity, Infinity),
+ [1n, 2n, 3n, 4n, 5n]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(Infinity, Infinity) -> [1, 2, 3, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.js
new file mode 100644
index 0000000000..137f9190cf
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.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.copywithin
+description: >
+ Copy values with non-negative target and start positions.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n, 6n]).copyWithin(0, 0),
+ [1n, 2n, 3n, 4n, 5n, 6n]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n, 6n]).copyWithin(0, 2),
+ [3n, 4n, 5n, 6n, 5n, 6n]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1n, 2n, 3n, 4n, 5n, 6n]).copyWithin(3, 0),
+ [1n, 2n, 3n, 1n, 2n, 3n]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(1, 4),
+ [0n, 4n, 5n, 3n, 4n, 5n]
+ )
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js
new file mode 100644
index 0000000000..17ddf9d1c1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js
@@ -0,0 +1,75 @@
+// 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.copywithin
+description: >
+ Copy values with non-negative target, start and end positions.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 0, 0),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 0, 0) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 0, 2),
+ [0n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 0, 2) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, 2),
+ [1n, 1n, 2n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, 2) -> [1, 1, 2, 3]'
+ );
+
+ /*
+ * 10. If from<to and to<from+count, then
+ * a. Let direction be - 1.
+ * b. Let from be from + count - 1.
+ * c. Let to be to + count - 1.
+ *
+ * 0 < 1, 1 < 0 + 2
+ * direction = -1
+ * from = 0 + 2 - 1
+ * to = 1 + 2 - 1
+ */
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, 2),
+ [0n, 0n, 1n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(1, 0, 2) -> [0, 0, 1, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(1, 3, 5),
+ [0n, 3n, 4n, 3n, 4n, 5n]
+ ),
+ '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 5) -> [0, 3, 4, 3, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js
new file mode 100644
index 0000000000..1aa2fb1f99
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js
@@ -0,0 +1,38 @@
+// 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.copywithin
+description: >
+ Return abrupt if end is a Symbol.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ ...
+includes: [testBigIntTypedArray.js]
+features: [BigInt, Symbol, TypedArray]
+---*/
+
+var s = Symbol(1);
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(TypeError, function() {
+ sample.copyWithin(0, 0, s);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.js
new file mode 100644
index 0000000000..a2cc76eb35
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.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.copywithin
+description: >
+ Return abrupt from ToInteger(end).
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ ...
+includes: [testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var o1 = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+ };
+ var sample = new TA();
+ assert.throws(Test262Error, function() {
+ sample.copyWithin(0, 0, o1);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.js
new file mode 100644
index 0000000000..2a49db8598
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.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.copywithin
+description: >
+ Return abrupt if start is a Symbol.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 5. Let relativeStart be ? ToInteger(start).
+ ...
+includes: [testBigIntTypedArray.js]
+features: [BigInt, Symbol, TypedArray]
+---*/
+
+var s = Symbol(1);
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(TypeError, function() {
+ sample.copyWithin(0, s);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js
new file mode 100644
index 0000000000..b7a03a0ea1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js
@@ -0,0 +1,47 @@
+// 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.copywithin
+description: >
+ Return abrupt from ToInteger(start).
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 5. Let relativeStart be ? ToInteger(start).
+ ...
+includes: [testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+var o = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+var err = {
+ valueOf: function() {
+ throw new Error("ToInteger(start) runs before ToInteger(end)");
+ }
+};
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(Test262Error, function() {
+ sample.copyWithin(0, o, err);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.js
new file mode 100644
index 0000000000..51851b1bfc
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.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.copywithin
+description: >
+ Return abrupt if target is a Symbol.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 3. Let relativeTarget be ? ToInteger(target).
+ ...
+includes: [testBigIntTypedArray.js]
+features: [BigInt, Symbol, TypedArray]
+---*/
+
+var s = Symbol(1);
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(TypeError, function() {
+ sample.copyWithin(s, 0);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.js
new file mode 100644
index 0000000000..d80ca93e1c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.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.copywithin
+description: >
+ Return abrupt from ToInteger(target).
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 3. Let relativeTarget be ? ToInteger(target).
+ ...
+includes: [testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+var o = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(Test262Error, function() {
+ sample.copyWithin(o);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-this-out-of-bounds.js
new file mode 100644
index 0000000000..fcf1f9323a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-this-out-of-bounds.js
@@ -0,0 +1,62 @@
+// |reftest| skip -- resizable-arraybuffer is not supported
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.copywithin
+description: Return abrupt when "this" value fails buffer boundary checks
+includes: [testBigIntTypedArray.js]
+features: [ArrayBuffer, BigInt, TypedArray, arrow-function, resizable-arraybuffer]
+---*/
+
+assert.sameValue(
+ typeof TypedArray.prototype.copyWithin,
+ 'function',
+ 'implements TypedArray.prototype.copyWithin'
+);
+
+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 * 5});
+ var array = new TA(ab, BPE, 2);
+
+ try {
+ ab.resize(BPE * 5);
+ } catch (_) {}
+
+ // no error following grow:
+ array.copyWithin(0, 0);
+
+ try {
+ ab.resize(BPE * 3);
+ } catch (_) {}
+
+ // no error following shrink (within bounds):
+ array.copyWithin(0, 0);
+
+ var expectedError;
+ try {
+ ab.resize(BPE * 2);
+ // If the preceding "resize" operation is successful, the typed array will
+ // be out out of bounds, so the subsequent prototype method should produce
+ // a TypeError due to the semantics of ValidateTypedArray.
+ expectedError = TypeError;
+ } catch (_) {
+ // The host is permitted to fail any "resize" operation at its own
+ // discretion. If that occurs, the copyWithin operation should complete
+ // successfully.
+ expectedError = Test262Error;
+ }
+
+ assert.throws(expectedError, () => {
+ array.copyWithin(0, 0);
+ throw new Test262Error('copyWithin completed successfully');
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-this.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-this.js
new file mode 100644
index 0000000000..b67372010b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/return-this.js
@@ -0,0 +1,38 @@
+// 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.copywithin
+description: >
+ Returns `this`.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ 13. Return O.
+includes: [testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var sample1 = new TA();
+ var result1 = sample1.copyWithin(0, 0);
+
+ assert.sameValue(result1, sample1);
+
+ var sample2 = new TA([1n, 2n, 3n]);
+ var result2 = sample2.copyWithin(1, 0);
+
+ assert.sameValue(result2, sample2);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/shell.js
new file mode 100644
index 0000000000..90ee9c114d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/shell.js
@@ -0,0 +1,42 @@
+// GENERATED, DO NOT EDIT
+// 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/copyWithin/BigInt/undefined-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js
new file mode 100644
index 0000000000..ea081c6ef3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js
@@ -0,0 +1,47 @@
+// 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.copywithin
+description: >
+ If `end` is undefined, set final position to `this.length`.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [BigInt, TypedArray]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, undefined),
+ [1n, 2n, 3n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, undefined) -> [1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1),
+ [1n, 2n, 3n, 3n]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1) -> [1, 2, 3, 3]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/bit-precision.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/bit-precision.js
new file mode 100644
index 0000000000..f563d813ef
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/bit-precision.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.copywithin
+description: Preservation of bit-level encoding
+info: |
+ Array.prototype.copyWithin (target, start [ , end ] )
+
+ 12. Repeat, while count > 0
+ [...]
+ d. If fromPresent is true, then
+ i. Let fromVal be ? Get(O, fromKey).
+ ii. Perform ? Set(O, toKey, fromVal, true).
+includes: [nans.js, compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+function body(FloatArray) {
+ var subject = new FloatArray(NaNs.length * 2);
+
+ NaNs.forEach(function(v, i) {
+ subject[i] = v;
+ });
+
+ var originalBytes, copiedBytes;
+ var length = NaNs.length * FloatArray.BYTES_PER_ELEMENT;
+
+ originalBytes = new Uint8Array(
+ subject.buffer,
+ 0,
+ length
+ );
+
+ subject.copyWithin(NaNs.length, 0);
+ copiedBytes = new Uint8Array(
+ subject.buffer,
+ length
+ );
+
+ assert(compareArray(originalBytes, copiedBytes));
+}
+
+testWithTypedArrayConstructors(body, [Float32Array, Float64Array]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/browser.js
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/byteoffset.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/byteoffset.js
new file mode 100644
index 0000000000..ec9f014d04
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/byteoffset.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2021 Chengzhong Wu. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.copywithin
+description: >
+ copyWithin should respect typedarray's byteOffset
+info: |
+ 22.2.3.5%TypedArray%.prototype.copyWithin ( target, start [ , end ] )
+ ...
+ 17. If count > 0, then
+ e. Let elementSize be the Element Size value specified in Table 72 for typedArrayName.
+ f. Let byteOffset be O.[[ByteOffset]].
+ g. Let toByteIndex be to × elementSize + byteOffset.
+ h. Let fromByteIndex be from × elementSize + byteOffset.
+ ...
+includes: [testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta = new TA([0, 1, 2, 3]);
+ assert.compareArray(
+ new TA(ta.buffer, TA.BYTES_PER_ELEMENT).copyWithin(2, 0),
+ [1, 2, 1],
+ 'copyWithin should respect typedarray\'s byteOffset'
+ );
+
+ assert.compareArray(
+ ta,
+ [0, 1, 2, 1],
+ 'underlying arraybuffer should have been updated'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end-detached-prototype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end-detached-prototype.js
new file mode 100644
index 0000000000..2b687ed165
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end-detached-prototype.js
@@ -0,0 +1,42 @@
+// Copyright (C) 2019 Google. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.copywithin
+description: >
+ SECURITY: end argument is coerced to an integer values
+ causing array detachment, but the value is still defined
+ by a prototype
+info: |
+ 22.2.3.5%TypedArray%.prototype.copyWithin ( target, start [ , end ] )
+ ...
+ 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end).
+ ...
+ 10. Let count be min(final - from, len - to).
+ 11. If count > 0, then
+ a. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data.
+ b. Let buffer be O.[[ViewedArrayBuffer]].
+ c. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
+ ...
+includes: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta;
+ var array = [];
+
+ function detachAndReturnIndex(){
+ $DETACHBUFFER(ta.buffer);
+ Object.setPrototypeOf(ta, array);
+ return 101;
+ }
+
+ array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed
+ array.fill(7, 0);
+ ta = new TA(array);
+ assert.throws(TypeError, function(){
+ ta.copyWithin(0, 100, {valueOf : detachAndReturnIndex});
+ }, "should throw TypeError as array is detached");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end-detached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end-detached.js
new file mode 100644
index 0000000000..484f388021
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end-detached.js
@@ -0,0 +1,40 @@
+// Copyright (C) 2019 Google. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.copywithin
+description: >
+ SECURITY: end argument is coerced to an integer values
+ causing array detachment
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin ( target, start [ , end ] )
+
+ ...
+ 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end).
+ ...
+ 10. Let count be min(final - from, len - to).
+ 11. If count > 0, then
+ a. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data.
+ b. Let buffer be O.[[ViewedArrayBuffer]].
+ c. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
+ ...
+includes: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta;
+ function detachAndReturnIndex(){
+ $DETACHBUFFER(ta.buffer);
+ return 900;
+ }
+
+ var array = [];
+ array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed
+ array.fill(7, 0);
+ ta = new TA(array);
+ assert.throws(TypeError, function(){
+ ta.copyWithin(0, 100, {valueOf : detachAndReturnIndex});
+ }, "should throw TypeError as array is detached");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end.js
new file mode 100644
index 0000000000..01a44699d5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-end.js
@@ -0,0 +1,79 @@
+// 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.copywithin
+description: >
+ end argument is coerced to an integer values.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, 0, null),
+ [0, 1, 2, 3]
+ ),
+ 'null value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, 0, NaN),
+ [0, 1, 2, 3]
+ ),
+ 'NaN value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, 0, false),
+ [0, 1, 2, 3]
+ ),
+ 'false value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, 0, true),
+ [0, 0, 2, 3]
+ ),
+ 'true value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, 0, '-2'),
+ [0, 0, 1, 3]
+ ),
+ 'string "-2" value coerced to integer -2'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, 0, -2.5),
+ [0, 0, 1, 3]
+ ),
+ 'float -2.5 value coerced to integer -2'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-start-detached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-start-detached.js
new file mode 100644
index 0000000000..559d3a18df
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-start-detached.js
@@ -0,0 +1,40 @@
+// Copyright (C) 2019 Google. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.copywithin
+description: >
+ SECURITY: start argument is coerced to an integer value, which detached
+ the array
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin ( target, start [ , end ] )
+
+ ...
+ 6. Let relativeStart be ? ToInteger(start).
+ ...
+ 10. Let count be min(final - from, len - to).
+ 11. If count > 0, then
+ a. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data.
+ b. Let buffer be O.[[ViewedArrayBuffer]].
+ c. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
+ ...
+includes: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var ta;
+ function detachAndReturnIndex(){
+ $DETACHBUFFER(ta.buffer);
+ return 100;
+ }
+
+ var array = [];
+ array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed
+ array.fill(7, 0);
+ ta = new TA(array);
+ assert.throws(TypeError, function(){
+ ta.copyWithin(0, {valueOf : detachAndReturnIndex}, 1000);
+ }, "should throw TypeError as array is detached");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-start.js
new file mode 100644
index 0000000000..9eb1399586
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-start.js
@@ -0,0 +1,94 @@
+// 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.copywithin
+description: >
+ start argument is coerced to an integer value.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 5. Let relativeStart be ? ToInteger(start).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, undefined),
+ [0, 0, 1, 2]
+ ),
+ 'undefined value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, false),
+ [0, 0, 1, 2]
+ ),
+ 'false value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, NaN),
+ [0, 0, 1, 2]
+ ),
+ 'NaN value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, null),
+ [0, 0, 1, 2]
+ ),
+ 'null value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, true),
+ [1, 2, 3, 3]
+ ),
+ 'true value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, '1'),
+ [1, 2, 3, 3]
+ ),
+ 'string "1" value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, 0.5),
+ [0, 0, 1, 2]
+ ),
+ '0.5 float value coerced to integer 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 1.5),
+ [1, 2, 3, 3]
+ ),
+ '1.5 float value coerced to integer 1'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-target.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-target.js
new file mode 100644
index 0000000000..cfe5773f8f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/coerced-values-target.js
@@ -0,0 +1,102 @@
+// 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.copywithin
+description: >
+ target argument is coerced to an integer value.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 3. Let relativeTarget be ? ToInteger(target).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(undefined, 1),
+ [1, 2, 3, 3]
+ ),
+ 'undefined value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(false, 1),
+ [1, 2, 3, 3]
+ ),
+ 'false value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(NaN, 1),
+ [1, 2, 3, 3]
+ ),
+ 'NaN value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(null, 1),
+ [1, 2, 3, 3]
+ ),
+ 'null value coerced to 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(true, 0),
+ [0, 0, 1, 2]
+ ),
+ 'true value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin('1', 0),
+ [0, 0, 1, 2]
+ ),
+ 'string "1" value coerced to 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0.5, 1),
+ [1, 2, 3, 3]
+ ),
+ '0.5 float value coerced to integer 0'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1.5, 0),
+ [0, 0, 1, 2]
+ ),
+ '1.5 float value coerced to integer 1'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin({}, 1),
+ [1, 2, 3, 3]
+ ),
+ 'object value coerced to integer 0'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/detached-buffer.js
new file mode 100644
index 0000000000..78e7bbda66
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/detached-buffer.js
@@ -0,0 +1,36 @@
+// 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.copywithin
+description: Throws a TypeError if this has a detached buffer
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] )
+
+ This function is not generic. ValidateTypedArray is applied to the this value
+ prior to evaluating the algorithm. If its result is an abrupt completion that
+ exception is thrown instead of evaluating the algorithm.
+
+ 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
+
+ ...
+ 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
+ ...
+includes: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+var obj = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(1);
+ $DETACHBUFFER(sample.buffer);
+ assert.throws(TypeError, function() {
+ sample.copyWithin(obj, obj);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/get-length-ignores-length-prop.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/get-length-ignores-length-prop.js
new file mode 100644
index 0000000000..d5cc8f993d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/get-length-ignores-length-prop.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.copywithin
+description: >
+ Unreachable abrupt from Get(O, "length") as [[ArrayLength]] is returned.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ 1. Let O be ? ToObject(this value).
+ 2. Let len be ? ToLength(? Get(O, "length")).
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+Object.defineProperty(TypedArray.prototype, "length", {
+ get: function() {
+ throw new Test262Error();
+ }
+});
+
+testWithTypedArrayConstructors(function(TA) {
+ Object.defineProperty(TA.prototype, "length", {
+ get: function() {
+ throw new Test262Error();
+ }
+ });
+
+ var sample = new TA();
+ Object.defineProperty(sample, "length", {
+ get: function() {
+ throw new Test262Error();
+ }
+ });
+
+ assert.sameValue(sample.copyWithin(0, 0), sample);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/invoked-as-func.js
new file mode 100644
index 0000000000..61da74b61a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/invoked-as-func.js
@@ -0,0 +1,31 @@
+// 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.copywithin
+description: Throws a TypeError exception when invoked as a function
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] )
+
+ This function is not generic. ValidateTypedArray is applied to the this value
+ prior to evaluating the algorithm. If its result is an abrupt completion that
+ exception is thrown instead of evaluating the algorithm.
+
+ 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
+
+ 1. If Type(O) is not Object, throw a TypeError exception.
+ 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var copyWithin = TypedArray.prototype.copyWithin;
+
+assert.sameValue(typeof copyWithin, 'function');
+
+assert.throws(TypeError, function() {
+ copyWithin();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/invoked-as-method.js
new file mode 100644
index 0000000000..1c7783022f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/invoked-as-method.js
@@ -0,0 +1,31 @@
+// 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.copywithin
+description: Requires a [[TypedArrayName]] internal slot.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] )
+
+ This function is not generic. ValidateTypedArray is applied to the this value
+ prior to evaluating the algorithm. If its result is an abrupt completion that
+ exception is thrown instead of evaluating the algorithm.
+
+ 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
+
+ 1. If Type(O) is not Object, throw a TypeError exception.
+ 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+
+assert.sameValue(typeof TypedArrayPrototype.copyWithin, 'function');
+
+assert.throws(TypeError, function() {
+ TypedArrayPrototype.copyWithin();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/length.js
new file mode 100644
index 0000000000..f7652c91da
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/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.copywithin
+description: >
+ %TypedArray%.prototype.copyWithin.length is 2.
+info: |
+ %TypedArray%.prototype.copyWithin (target, start [, end ] )
+
+ 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.copyWithin.length, 2);
+
+verifyNotEnumerable(TypedArray.prototype.copyWithin, "length");
+verifyNotWritable(TypedArray.prototype.copyWithin, "length");
+verifyConfigurable(TypedArray.prototype.copyWithin, "length");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/name.js
new file mode 100644
index 0000000000..7a888ea988
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/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.copywithin
+description: >
+ %TypedArray%.prototype.copyWithin.name is "copyWithin".
+info: |
+ %TypedArray%.prototype.copyWithin (target, start [, end ] )
+
+ 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.copyWithin.name, "copyWithin");
+
+verifyNotEnumerable(TypedArray.prototype.copyWithin, "name");
+verifyNotWritable(TypedArray.prototype.copyWithin, "name");
+verifyConfigurable(TypedArray.prototype.copyWithin, "name");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-end.js
new file mode 100644
index 0000000000..51fdfe1ab0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-end.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.copywithin
+description: >
+ Set values with negative end argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let
+ final be min(relativeEnd, len).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 1, -1),
+ [1, 2, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, -1) -> [1, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(2, 0, -1),
+ [0, 1, 0, 1, 2]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(2, 0, -1) -> [0, 1, 0, 1, 2]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(1, 2, -2),
+ [0, 2, 2, 3, 4]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(1, 2, -2) -> [0, 2, 2, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, -2, -1),
+ [2, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, -2, -1) -> [2, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(2, -2, -1),
+ [0, 1, 3, 3, 4]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(2, -2, 1) -> [0, 1, 3, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(-3, -2, -1),
+ [0, 2, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(-3, -2, -1) -> [0, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(-2, -3, -1),
+ [0, 1, 2, 2, 3]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-2, -3, -1) -> [0, 1, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(-5, -2, -1),
+ [3, 1, 2, 3, 4]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-5, -2, -1) -> [3, 1, 2, 3, 4]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js
new file mode 100644
index 0000000000..97ae46c850
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js
@@ -0,0 +1,113 @@
+// 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.copywithin
+description: >
+ Set values with negative out of bounds end argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let
+ final be min(relativeEnd, len).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 1, -10),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(0, 1, -Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, -2, -10),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, -2, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(0, -2, -Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, -9, -10),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, -9, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(0, -9, -Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(-3, -2, -10),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(-3, -2, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(-3, -2, -Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(-7, -8, -9),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(-7, -8, -9) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(-7, -8, -Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js
new file mode 100644
index 0000000000..31cfc40993
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.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.copywithin
+description: >
+ Set values with out of bounds negative start argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let
+ from be min(relativeStart, len).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, -10),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3]).copyWithin(0, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(0, -Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5]).copyWithin(0, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(2, -10),
+ [0, 1, 0, 1, 2]
+ ),
+ '[0, 1, 2, 3, 4]).copyWithin(2, -2) -> [0, 1, 0, 1, 2]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(2, -Infinity),
+ [1, 2, 1, 2, 3]
+ ),
+ '[1, 2, 3, 4, 5]).copyWithin(2, -Infinity) -> [1, 2, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(10, -10),
+ [0, 1, 2, 3, 4]
+ ),
+ '[0, 1, 2, 3, 4]).copyWithin(10, -10) -> [0, 1, 2, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(10, -Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5]).copyWithin(10, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(-9, -10),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(-9, -10) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(-9, -Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-9, -Infinity) -> [1, 2, 3, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js
new file mode 100644
index 0000000000..ac9c07bf31
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js
@@ -0,0 +1,63 @@
+// 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.copywithin
+description: >
+ Set values with out of bounds negative target argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let
+ to be min(relativeTarget, len).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(-10, 0),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(-10, 0) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(-Infinity, 0),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-Infinity, 0) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(-10, 2),
+ [2, 3, 4, 3, 4]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-10, 2) -> [2, 3, 4, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(-Infinity, 2),
+ [3, 4, 5, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(-Infinity, 2) -> [3, 4, 5, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-start.js
new file mode 100644
index 0000000000..21c18b503e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-start.js
@@ -0,0 +1,79 @@
+// 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.copywithin
+description: >
+ Set values with negative start argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let
+ from be min(relativeStart, len).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, -1),
+ [3, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, -1) -> [3, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(2, -2),
+ [0, 1, 3, 4, 4]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(2, -2) -> [0, 1, 3, 4, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(1, -2),
+ [0, 3, 4, 3, 4]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(1, -2) -> [0, 3, 4, 3, 4]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(-1, -2),
+ [0, 1, 2, 2]
+ ),
+ '[0, 1, 2, 3].copyWithin(-1, -2) -> [ 0, 1, 2, 2 ]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(-2, -3),
+ [0, 1, 2, 2, 3]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-2, -3) -> [0, 1, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(-5, -2),
+ [3, 4, 2, 3, 4]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-5, -2) -> [3, 4, 2, 3, 4]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-target.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-target.js
new file mode 100644
index 0000000000..b8fc48835a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/negative-target.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.copywithin
+description: >
+ Set values with negative target argument.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let
+ to be min(relativeTarget, len).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(-1, 0),
+ [0, 1, 2, 0]
+ ),
+ '[0, 1, 2, 3].copyWithin(-1, 0) -> [0, 1, 2, 0]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4]).copyWithin(-2, 2),
+ [0, 1, 2, 2, 3]
+ ),
+ '[0, 1, 2, 3, 4].copyWithin(-2, 2) -> [0, 1, 2, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(-1, 2),
+ [0, 1, 2, 2]
+ ),
+ '[0, 1, 2, 3].copyWithin(-1, 2) -> [0, 1, 2, 2]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js
new file mode 100644
index 0000000000..569b7d95b4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js
@@ -0,0 +1,56 @@
+// 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.copywithin
+description: >
+ Max value of end position is the this.length.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 1, 6),
+ [1, 2, 3, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, 6) -> [1, 2, 3, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(0, 1, Infinity),
+ [2, 3, 4, 5, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, 1, Infinity) -> [2, 3, 4, 5, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4, 5]).copyWithin(1, 3, 6),
+ [0, 3, 4, 5, 4, 5]
+ ),
+ '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6) -> [0, 3, 4, 5, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(1, 3, Infinity),
+ [1, 4, 5, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(1, 3, Infinity) -> [1, 4, 5, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js
new file mode 100644
index 0000000000..d2b7e87fbc
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js
@@ -0,0 +1,76 @@
+// 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.copywithin
+description: >
+ Max values of target and start positions are this.length.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4, 5]).copyWithin(6, 0),
+ [0, 1, 2, 3, 4, 5]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(Infinity, 0),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(Infinity, 0) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4, 5]).copyWithin(0, 6),
+ [0, 1, 2, 3, 4, 5]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(0, Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(0, Infinity) -> [1, 2, 3, 4, 5]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4, 5]).copyWithin(6, 6),
+ [0, 1, 2, 3, 4, 5]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4, 5]).copyWithin(10, 10),
+ [0, 1, 2, 3, 4, 5]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5]).copyWithin(Infinity, Infinity),
+ [1, 2, 3, 4, 5]
+ ),
+ '[1, 2, 3, 4, 5].copyWithin(Infinity, Infinity) -> [1, 2, 3, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-target-and-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-target-and-start.js
new file mode 100644
index 0000000000..d0d152e3d2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-target-and-start.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.copywithin
+description: >
+ Copy values with non-negative target and start positions.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5, 6]).copyWithin(0, 0),
+ [1, 2, 3, 4, 5, 6]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5, 6]).copyWithin(0, 2),
+ [3, 4, 5, 6, 5, 6]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([1, 2, 3, 4, 5, 6]).copyWithin(3, 0),
+ [1, 2, 3, 1, 2, 3]
+ )
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4, 5]).copyWithin(1, 4),
+ [0, 4, 5, 3, 4, 5]
+ )
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-target-start-and-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-target-start-and-end.js
new file mode 100644
index 0000000000..62a6bfcd4a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/non-negative-target-start-and-end.js
@@ -0,0 +1,75 @@
+// 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.copywithin
+description: >
+ Copy values with non-negative target, start and end positions.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 0, 0),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 0, 0) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 0, 2),
+ [0, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 0, 2) -> [0, 1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 1, 2),
+ [1, 1, 2, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, 2) -> [1, 1, 2, 3]'
+ );
+
+ /*
+ * 10. If from<to and to<from+count, then
+ * a. Let direction be - 1.
+ * b. Let from be from + count - 1.
+ * c. Let to be to + count - 1.
+ *
+ * 0 < 1, 1 < 0 + 2
+ * direction = -1
+ * from = 0 + 2 - 1
+ * to = 1 + 2 - 1
+ */
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(1, 0, 2),
+ [0, 0, 1, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(1, 0, 2) -> [0, 0, 1, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3, 4, 5]).copyWithin(1, 3, 5),
+ [0, 3, 4, 3, 4, 5]
+ ),
+ '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 5) -> [0, 3, 4, 3, 4, 5]'
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/not-a-constructor.js
new file mode 100644
index 0000000000..34042bfc79
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/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.copyWithin 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.copyWithin),
+ false,
+ 'isConstructor(TypedArray.prototype.copyWithin) must return false'
+);
+
+assert.throws(TypeError, () => {
+ let u8 = new Uint8Array(1); new u8.copyWithin();
+}, '`let u8 = new Uint8Array(1); new u8.copyWithin()` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/prop-desc.js
new file mode 100644
index 0000000000..96da143cac
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/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.copywithin
+description: >
+ "copyWithin" 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, 'copyWithin');
+verifyWritable(TypedArrayPrototype, 'copyWithin');
+verifyConfigurable(TypedArrayPrototype, 'copyWithin');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-end-is-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-end-is-symbol.js
new file mode 100644
index 0000000000..09d60ac7d1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-end-is-symbol.js
@@ -0,0 +1,38 @@
+// 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.copywithin
+description: >
+ Return abrupt if end is a Symbol.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ ...
+includes: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var s = Symbol(1);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(TypeError, function() {
+ sample.copyWithin(0, 0, s);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-end.js
new file mode 100644
index 0000000000..5d7ef05e4e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-end.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.copywithin
+description: >
+ Return abrupt from ToInteger(end).
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var o1 = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+ };
+ var sample = new TA();
+ assert.throws(Test262Error, function() {
+ sample.copyWithin(0, 0, o1);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-start-is-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-start-is-symbol.js
new file mode 100644
index 0000000000..4a5455bf26
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-start-is-symbol.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.copywithin
+description: >
+ Return abrupt if start is a Symbol.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 5. Let relativeStart be ? ToInteger(start).
+ ...
+includes: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var s = Symbol(1);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(TypeError, function() {
+ sample.copyWithin(0, s);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-start.js
new file mode 100644
index 0000000000..6a0843ae3f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-start.js
@@ -0,0 +1,47 @@
+// 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.copywithin
+description: >
+ Return abrupt from ToInteger(start).
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 5. Let relativeStart be ? ToInteger(start).
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var o = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+var err = {
+ valueOf: function() {
+ throw new Error("ToInteger(start) runs before ToInteger(end)");
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(Test262Error, function() {
+ sample.copyWithin(0, o, err);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-target-is-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-target-is-symbol.js
new file mode 100644
index 0000000000..a1148053a7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-target-is-symbol.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.copywithin
+description: >
+ Return abrupt if target is a Symbol.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 3. Let relativeTarget be ? ToInteger(target).
+ ...
+includes: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var s = Symbol(1);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(TypeError, function() {
+ sample.copyWithin(s, 0);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-target.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-target.js
new file mode 100644
index 0000000000..0e9c56d1a2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-target.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.copywithin
+description: >
+ Return abrupt from ToInteger(target).
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 3. Let relativeTarget be ? ToInteger(target).
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var o = {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+ assert.throws(Test262Error, function() {
+ sample.copyWithin(o);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds.js
new file mode 100644
index 0000000000..a9c562a62a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds.js
@@ -0,0 +1,62 @@
+// |reftest| skip -- resizable-arraybuffer is not supported
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.copywithin
+description: Return abrupt when "this" value fails buffer boundary checks
+includes: [testTypedArray.js]
+features: [TypedArray, resizable-arraybuffer]
+---*/
+
+assert.sameValue(
+ typeof TypedArray.prototype.copyWithin,
+ 'function',
+ 'implements TypedArray.prototype.copyWithin'
+);
+
+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 * 5});
+ var array = new TA(ab, BPE, 2);
+
+ try {
+ ab.resize(BPE * 5);
+ } catch (_) {}
+
+ // no error following grow:
+ array.copyWithin(0, 0);
+
+ try {
+ ab.resize(BPE * 3);
+ } catch (_) {}
+
+ // no error following shrink (within bounds):
+ array.copyWithin(0, 0);
+
+ var expectedError;
+ try {
+ ab.resize(BPE * 2);
+ // If the preceding "resize" operation is successful, the typed array will
+ // be out out of bounds, so the subsequent prototype method should produce
+ // a TypeError due to the semantics of ValidateTypedArray.
+ expectedError = TypeError;
+ } catch (_) {
+ // The host is permitted to fail any "resize" operation at its own
+ // discretion. If that occurs, the copyWithin operation should complete
+ // successfully.
+ expectedError = Test262Error;
+ }
+
+ assert.throws(expectedError, () => {
+ array.copyWithin(0, 0);
+ throw new Test262Error('copyWithin completed successfully');
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-this.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-this.js
new file mode 100644
index 0000000000..2ff0381574
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/return-this.js
@@ -0,0 +1,38 @@
+// 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.copywithin
+description: >
+ Returns `this`.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ 13. Return O.
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample1 = new TA();
+ var result1 = sample1.copyWithin(0, 0);
+
+ assert.sameValue(result1, sample1);
+
+ var sample2 = new TA([1, 2, 3]);
+ var result2 = sample2.copyWithin(1, 0);
+
+ assert.sameValue(result2, sample2);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/shell.js
new file mode 100644
index 0000000000..eda1477282
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/shell.js
@@ -0,0 +1,24 @@
+// 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;
+}
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/this-is-not-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/this-is-not-object.js
new file mode 100644
index 0000000000..7f19b0b3ef
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/this-is-not-object.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.copywithin
+description: Throws a TypeError exception when `this` is not Object
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ This function is not generic. ValidateTypedArray is applied to the this value
+ prior to evaluating the algorithm. If its result is an abrupt completion that
+ exception is thrown instead of evaluating the algorithm.
+
+ 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
+
+ 1. If Type(O) is not Object, throw a TypeError exception.
+ ...
+includes: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var copyWithin = TypedArray.prototype.copyWithin;
+
+assert.throws(TypeError, function() {
+ copyWithin.call(undefined, 0, 0);
+}, "this is undefined");
+
+assert.throws(TypeError, function() {
+ copyWithin.call(null, 0, 0);
+}, "this is null");
+
+assert.throws(TypeError, function() {
+ copyWithin.call(42, 0, 0);
+}, "this is 42");
+
+assert.throws(TypeError, function() {
+ copyWithin.call("1", 0, 0);
+}, "this is a string");
+
+assert.throws(TypeError, function() {
+ copyWithin.call(true, 0, 0);
+}, "this is true");
+
+assert.throws(TypeError, function() {
+ copyWithin.call(false, 0, 0);
+}, "this is false");
+
+var s = Symbol("s");
+assert.throws(TypeError, function() {
+ copyWithin.call(s, 0, 0);
+}, "this is a Symbol");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/this-is-not-typedarray-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/this-is-not-typedarray-instance.js
new file mode 100644
index 0000000000..9bd0b0458d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/this-is-not-typedarray-instance.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.copywithin
+description: >
+ Throws a TypeError exception when `this` is not a TypedArray instance
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ This function is not generic. ValidateTypedArray is applied to the this value
+ prior to evaluating the algorithm. If its result is an abrupt completion that
+ exception is thrown instead of evaluating the algorithm.
+
+ 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
+
+ 1. If Type(O) is not Object, throw a TypeError exception.
+ 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var copyWithin = TypedArray.prototype.copyWithin;
+
+assert.throws(TypeError, function() {
+ copyWithin.call({}, 0, 0);
+}, "this is an Object");
+
+assert.throws(TypeError, function() {
+ copyWithin.call([], 0, 0);
+}, "this is an Array");
+
+var ab = new ArrayBuffer(8);
+assert.throws(TypeError, function() {
+ copyWithin.call(ab, 0, 0);
+}, "this is an ArrayBuffer instance");
+
+var dv = new DataView(new ArrayBuffer(8), 0, 1);
+assert.throws(TypeError, function() {
+ copyWithin.call(dv, 0, 0);
+}, "this is a DataView instance");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/undefined-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/undefined-end.js
new file mode 100644
index 0000000000..e4e7072486
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/copyWithin/undefined-end.js
@@ -0,0 +1,47 @@
+// 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.copywithin
+description: >
+ If `end` is undefined, set final position to `this.length`.
+info: |
+ 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] )
+
+ %TypedArray%.prototype.copyWithin is a distinct function that implements the
+ same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except
+ that the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length" and the actual copying of values in step 12
+ must be performed in a manner that preserves the bit-level encoding of the
+ source data.
+
+ ...
+
+ 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+ ...
+ 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ?
+ ToInteger(end).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 1, undefined),
+ [1, 2, 3, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1, undefined) -> [1, 2, 3]'
+ );
+
+ assert(
+ compareArray(
+ new TA([0, 1, 2, 3]).copyWithin(0, 1),
+ [1, 2, 3, 3]
+ ),
+ '[0, 1, 2, 3].copyWithin(0, 1) -> [1, 2, 3, 3]'
+ );
+});
+
+reportCompare(0, 0);