summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer')
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/descriptor.js24
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/extensible.js17
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-larger-no-resizable.js59
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-larger.js58
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-same-no-resizable.js60
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-same.js59
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller-no-resizable.js57
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller.js56
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-zero-no-resizable.js51
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-zero.js50
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-larger.js58
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-same.js59
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-smaller.js56
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-zero.js50
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/length.js32
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/name.js29
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/new-length-excessive.js18
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/new-length-non-number.js41
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/nonconstructor.js25
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/shell.js18
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-detached.js29
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-not-arraybuffer-object.js30
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-not-object.js46
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer.js23
25 files changed, 1005 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/browser.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/browser.js
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/descriptor.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/descriptor.js
new file mode 100644
index 0000000000..dbe4cb2b97
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/descriptor.js
@@ -0,0 +1,24 @@
+// 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-arraybuffer.prototype.transfer
+description: >
+ ArrayBuffer.prototype.transfer has default data property attributes.
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 17 ECMAScript Standard Built-in Objects:
+ 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]
+features: [arraybuffer-transfer]
+---*/
+
+verifyProperty(ArrayBuffer.prototype, 'transfer', {
+ enumerable: false,
+ writable: true,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/extensible.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/extensible.js
new file mode 100644
index 0000000000..27902e9fe6
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/extensible.js
@@ -0,0 +1,17 @@
+// 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-arraybuffer.prototype.transfer
+description: ArrayBuffer.prototype.transfer is extensible.
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 17 ECMAScript Standard Built-in Objects:
+ Unless specified otherwise, the [[Extensible]] internal slot
+ of a built-in object initially has the value true.
+features: [arraybuffer-transfer]
+---*/
+
+assert(Object.isExtensible(ArrayBuffer.prototype.transfer));
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-larger-no-resizable.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-larger-no-resizable.js
new file mode 100644
index 0000000000..0d8c738b8c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-larger-no-resizable.js
@@ -0,0 +1,59 @@
+// 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-arraybuffer.prototype.transfer
+description: Transfering from a fixed-size ArrayBuffer into a larger ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [arraybuffer-transfer]
+---*/
+
+// NOTE: This file is a copy of "from-fixed-to-larger.js" with the resizable
+// ArrayBuffer parts removed, so it can run in implementations which don't yet
+// support the "resizable-arraybuffer" feature.
+
+var source = new ArrayBuffer(4);
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(5);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.byteLength, 5, 'dest.byteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+assert.sameValue(destArray[3], 4, 'destArray[3]');
+assert.sameValue(destArray[4], 0, 'destArray[4]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-larger.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-larger.js
new file mode 100644
index 0000000000..5c834d1573
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-larger.js
@@ -0,0 +1,58 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-arraybuffer.prototype.transfer
+description: Transfering from a fixed-size ArrayBuffer into a larger ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [resizable-arraybuffer, arraybuffer-transfer]
+---*/
+
+var source = new ArrayBuffer(4);
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(5);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.resizable, false, 'dest.resizable');
+assert.sameValue(dest.byteLength, 5, 'dest.byteLength');
+assert.sameValue(dest.maxByteLength, 5, 'dest.maxByteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+assert.sameValue(destArray[3], 4, 'destArray[3]');
+assert.sameValue(destArray[4], 0, 'destArray[4]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-same-no-resizable.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-same-no-resizable.js
new file mode 100644
index 0000000000..bd33a2575b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-same-no-resizable.js
@@ -0,0 +1,60 @@
+// 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-arraybuffer.prototype.transfer
+description: |
+ Transfering from a fixed-size ArrayBuffer into an ArrayBuffer with the same
+ byte length
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [arraybuffer-transfer]
+---*/
+
+// NOTE: This file is a copy of "from-fixed-to-same.js" with the resizable
+// ArrayBuffer parts removed, so it can run in implementations which don't yet
+// support the "resizable-arraybuffer" feature.
+
+var source = new ArrayBuffer(4);
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer();
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.byteLength, 4, 'dest.byteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+assert.sameValue(destArray[3], 4, 'destArray[3]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-same.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-same.js
new file mode 100644
index 0000000000..f988fd3346
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-same.js
@@ -0,0 +1,59 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-arraybuffer.prototype.transfer
+description: |
+ Transfering from a fixed-size ArrayBuffer into an ArrayBuffer with the same
+ byte length
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [resizable-arraybuffer, arraybuffer-transfer]
+---*/
+
+var source = new ArrayBuffer(4);
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer();
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.resizable, false, 'dest.resizable');
+assert.sameValue(dest.byteLength, 4, 'dest.byteLength');
+assert.sameValue(dest.maxByteLength, 4, 'dest.maxByteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+assert.sameValue(destArray[3], 4, 'destArray[3]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller-no-resizable.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller-no-resizable.js
new file mode 100644
index 0000000000..8dac703e5d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller-no-resizable.js
@@ -0,0 +1,57 @@
+// 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-arraybuffer.prototype.transfer
+description: Transfering from a fixed-size ArrayBuffer into a smaller ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [arraybuffer-transfer]
+---*/
+
+// NOTE: This file is a copy of "from-fixed-to-smaller.js" with the resizable
+// ArrayBuffer parts removed, so it can run in implementations which don't yet
+// support the "resizable-arraybuffer" feature.
+
+var source = new ArrayBuffer(4);
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(3);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.byteLength, 3, 'dest.byteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller.js
new file mode 100644
index 0000000000..2380c0a1c5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller.js
@@ -0,0 +1,56 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-arraybuffer.prototype.transfer
+description: Transfering from a fixed-size ArrayBuffer into a smaller ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [resizable-arraybuffer, arraybuffer-transfer]
+---*/
+
+var source = new ArrayBuffer(4);
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(3);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.resizable, false, 'dest.resizable');
+assert.sameValue(dest.byteLength, 3, 'dest.byteLength');
+assert.sameValue(dest.maxByteLength, 3, 'dest.maxByteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-zero-no-resizable.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-zero-no-resizable.js
new file mode 100644
index 0000000000..268c991a47
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-zero-no-resizable.js
@@ -0,0 +1,51 @@
+// 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-arraybuffer.prototype.transfer
+description: Transfering from a fixed-size ArrayBuffer into a zero-length ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [arraybuffer-transfer]
+---*/
+
+// NOTE: This file is a copy of "from-fixed-to-zero.js" with the resizable
+// ArrayBuffer parts removed, so it can run in implementations which don't yet
+// support the "resizable-arraybuffer" feature.
+
+var source = new ArrayBuffer(4);
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(0);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.byteLength, 0, 'dest.byteLength');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-zero.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-zero.js
new file mode 100644
index 0000000000..a76368596d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-fixed-to-zero.js
@@ -0,0 +1,50 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-arraybuffer.prototype.transfer
+description: Transfering from a fixed-size ArrayBuffer into a zero-length ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [resizable-arraybuffer, arraybuffer-transfer]
+---*/
+
+var source = new ArrayBuffer(4);
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(0);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.resizable, false, 'dest.resizable');
+assert.sameValue(dest.byteLength, 0, 'dest.byteLength');
+assert.sameValue(dest.maxByteLength, 0, 'dest.maxByteLength');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-larger.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-larger.js
new file mode 100644
index 0000000000..07f564471a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-larger.js
@@ -0,0 +1,58 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-arraybuffer.prototype.transfer
+description: Transfering from a resizable ArrayBuffer into a larger ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [resizable-arraybuffer, arraybuffer-transfer]
+---*/
+
+var source = new ArrayBuffer(4, { maxByteLength: 8 });
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(5);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.resizable, true, 'dest.resizable');
+assert.sameValue(dest.byteLength, 5, 'dest.byteLength');
+assert.sameValue(dest.maxByteLength, 8, 'dest.maxByteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+assert.sameValue(destArray[3], 4, 'destArray[3]');
+assert.sameValue(destArray[4], 0, 'destArray[4]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-same.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-same.js
new file mode 100644
index 0000000000..af94449217
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-same.js
@@ -0,0 +1,59 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-arraybuffer.prototype.transfer
+description: |
+ Transfering from a resizable ArrayBuffer into an ArrayBuffer with the same
+ byte length
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [resizable-arraybuffer, arraybuffer-transfer]
+---*/
+
+var source = new ArrayBuffer(4, { maxByteLength: 8 });
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer();
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.resizable, true, 'dest.resizable');
+assert.sameValue(dest.byteLength, 4, 'dest.byteLength');
+assert.sameValue(dest.maxByteLength, 8, 'dest.maxByteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+assert.sameValue(destArray[3], 4, 'destArray[3]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-smaller.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-smaller.js
new file mode 100644
index 0000000000..14a6259778
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-smaller.js
@@ -0,0 +1,56 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-arraybuffer.prototype.transfer
+description: Transfering from a resizable ArrayBuffer into a smaller ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [resizable-arraybuffer, arraybuffer-transfer]
+---*/
+
+var source = new ArrayBuffer(4, { maxByteLength: 8 });
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(3);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.resizable, true, 'dest.resizable');
+assert.sameValue(dest.byteLength, 3, 'dest.byteLength');
+assert.sameValue(dest.maxByteLength, 8, 'dest.maxByteLength');
+
+var destArray = new Uint8Array(dest);
+
+assert.sameValue(destArray[0], 1, 'destArray[0]');
+assert.sameValue(destArray[1], 2, 'destArray[1]');
+assert.sameValue(destArray[2], 3, 'destArray[2]');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-zero.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-zero.js
new file mode 100644
index 0000000000..a0371b009c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/from-resizable-to-zero.js
@@ -0,0 +1,50 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-arraybuffer.prototype.transfer
+description: Transfering from a resizable ArrayBuffer into a zero-length ArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 7. Let new be ? Construct(%ArrayBuffer%, « 𝔽(newByteLength) »).
+ 8. NOTE: This method returns a fixed-length ArrayBuffer.
+ 9. Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
+ 10. Let fromBlock be O.[[ArrayBufferData]].
+ 11. Let toBlock be new.[[ArrayBufferData]].
+ 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
+ 13. NOTE: Neither creation of the new Data Block nor copying from the old
+ Data Block are observable. Implementations reserve the right to implement
+ this method as a zero-copy move or a realloc.
+ 14. Perform ! DetachArrayBuffer(O).
+ 15. Return new.
+features: [resizable-arraybuffer, arraybuffer-transfer]
+---*/
+
+var source = new ArrayBuffer(4, { maxByteLength: 8 });
+
+var sourceArray = new Uint8Array(source);
+sourceArray[0] = 1;
+sourceArray[1] = 2;
+sourceArray[2] = 3;
+sourceArray[3] = 4;
+
+var dest = source.transfer(0);
+
+assert.sameValue(source.byteLength, 0, 'source.byteLength');
+assert.throws(TypeError, function() {
+ source.slice();
+});
+
+assert.sameValue(dest.resizable, true, 'dest.resizable');
+assert.sameValue(dest.byteLength, 0, 'dest.byteLength');
+assert.sameValue(dest.maxByteLength, 8, 'dest.maxByteLength');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/length.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/length.js
new file mode 100644
index 0000000000..b7c9e8eedb
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/length.js
@@ -0,0 +1,32 @@
+// 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-arraybuffer.prototype.transfer
+description: >
+ ArrayBuffer.prototype.transfer.length is 0.
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 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]
+features: [arraybuffer-transfer]
+---*/
+
+verifyProperty(ArrayBuffer.prototype.transfer, 'length', {
+ value: 0,
+ enumerable: false,
+ writable: false,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/name.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/name.js
new file mode 100644
index 0000000000..b4c20b07ca
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/name.js
@@ -0,0 +1,29 @@
+// 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-arraybuffer.prototype.transfer
+description: >
+ ArrayBuffer.prototype.transfer.name is "transfer".
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 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 }.
+features: [arraybuffer-transfer]
+includes: [propertyHelper.js]
+---*/
+
+verifyProperty(ArrayBuffer.prototype.transfer, 'name', {
+ value: 'transfer',
+ enumerable: false,
+ writable: false,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/new-length-excessive.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/new-length-excessive.js
new file mode 100644
index 0000000000..d7debd55bf
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/new-length-excessive.js
@@ -0,0 +1,18 @@
+// 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-arraybuffer.prototype.transfer
+description: >
+ Throws a RangeError if the newLength is larger than 2^53 - 1 due to clamping
+ in ToIndex.
+features: [arraybuffer-transfer]
+---*/
+
+var ab = new ArrayBuffer(0);
+
+assert.throws(RangeError, function() {
+ // Math.pow(2, 53) = 9007199254740992
+ ab.transfer(9007199254740992);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/new-length-non-number.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/new-length-non-number.js
new file mode 100644
index 0000000000..b5f1de6bf1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/new-length-non-number.js
@@ -0,0 +1,41 @@
+// 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-arraybuffer.prototype.transfer
+description: Throws a TypeError if provided length cannot be coerced to a number
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. If newLength is undefined, let newByteLength be
+ O.[[ArrayBufferByteLength]].
+ 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength).
+ [...]
+features: [arraybuffer-transfer]
+---*/
+
+var log = [];
+var newLength = {
+ toString: function() {
+ log.push('toString');
+ return {};
+ },
+ valueOf: function() {
+ log.push('valueOf');
+ return {};
+ }
+};
+var ab = new ArrayBuffer(0);
+
+assert.throws(TypeError, function() {
+ ab.transfer(newLength);
+});
+
+assert.sameValue(log.length, 2);
+assert.sameValue(log[0], 'valueOf');
+assert.sameValue(log[1], 'toString');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/nonconstructor.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/nonconstructor.js
new file mode 100644
index 0000000000..5d5be42b03
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/nonconstructor.js
@@ -0,0 +1,25 @@
+// 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-arraybuffer.prototype.transfer
+description: >
+ ArrayBuffer.prototype.transfer is not a constructor function.
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 17 ECMAScript Standard Built-in 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.
+includes: [isConstructor.js]
+features: [arraybuffer-transfer, Reflect.construct]
+---*/
+
+assert(!isConstructor(ArrayBuffer.prototype.transfer), "ArrayBuffer.prototype.transfer is not a constructor");
+
+var arrayBuffer = new ArrayBuffer(8);
+assert.throws(TypeError, function() {
+ new arrayBuffer.transfer();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/shell.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/shell.js
new file mode 100644
index 0000000000..06f65290b8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/shell.js
@@ -0,0 +1,18 @@
+// GENERATED, DO NOT EDIT
+// file: detachArrayBuffer.js
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: |
+ A function used in the process of asserting correctness of TypedArray objects.
+
+ $262.detachArrayBuffer is defined by a host.
+defines: [$DETACHBUFFER]
+---*/
+
+function $DETACHBUFFER(buffer) {
+ if (!$262 || typeof $262.detachArrayBuffer !== "function") {
+ throw new Test262Error("No method available to detach an ArrayBuffer");
+ }
+ $262.detachArrayBuffer(buffer);
+}
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-detached.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-detached.js
new file mode 100644
index 0000000000..9241993b84
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-detached.js
@@ -0,0 +1,29 @@
+// 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-arraybuffer.prototype.transfer
+description: >
+ Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ [...]
+includes: [detachArrayBuffer.js]
+features: [arraybuffer-transfer]
+---*/
+
+assert.sameValue(typeof ArrayBuffer.prototype.transfer, 'function');
+
+var ab = new ArrayBuffer(1);
+
+$DETACHBUFFER(ab);
+
+assert.throws(TypeError, function() {
+ ab.transfer();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-not-arraybuffer-object.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-not-arraybuffer-object.js
new file mode 100644
index 0000000000..44d49bfba1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-not-arraybuffer-object.js
@@ -0,0 +1,30 @@
+// 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-arraybuffer.prototype.transfer
+description: >
+ Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ [...]
+features: [arraybuffer-transfer]
+---*/
+
+assert.sameValue(typeof ArrayBuffer.prototype.transfer, 'function');
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer();
+}, '`this` value is the ArrayBuffer prototype');
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call({});
+}, '`this` value is an object');
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call([]);
+}, '`this` value is an array');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-not-object.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-not-object.js
new file mode 100644
index 0000000000..25fdb9bc17
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-not-object.js
@@ -0,0 +1,46 @@
+// 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-arraybuffer.prototype.transfer
+description: Throws a TypeError if `this` valueis not an object.
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ [...]
+features: [arraybuffer-transfer, Symbol, BigInt]
+---*/
+
+assert.sameValue(typeof ArrayBuffer.prototype.transfer, "function");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call(undefined);
+}, "`this` value is undefined");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call(null);
+}, "`this` value is null");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call(true);
+}, "`this` value is Boolean");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call("");
+}, "`this` value is String");
+
+var symbol = Symbol();
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call(symbol);
+}, "`this` value is Symbol");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call(1);
+}, "`this` value is Number");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call(1n);
+}, "`this` value is bigint");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer.js
new file mode 100644
index 0000000000..0667cf9aa1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer.js
@@ -0,0 +1,23 @@
+// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally
+// 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-arraybuffer.prototype.transfer
+description: Throws a TypeError if `this` value is a SharedArrayBuffer
+info: |
+ ArrayBuffer.prototype.transfer ( [ newLength ] )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferData]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ [...]
+features: [SharedArrayBuffer, arraybuffer-transfer]
+---*/
+
+var sab = new SharedArrayBuffer(0);
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.transfer.call(sab);
+}, '`this` value cannot be a SharedArrayBuffer');
+
+reportCompare(0, 0);