summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize')
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/descriptor.js25
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/extensible.js18
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/length.js33
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/name.js30
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-excessive.js28
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-negative.js28
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-non-number.js40
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/nonconstructor.js26
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-grow.js80
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-explicit.js81
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js81
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size.js81
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-explicit.js80
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-implicit.js80
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink.js80
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/shell.js18
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-detached.js30
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-arraybuffer-object.js31
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-object.js47
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-resizable-arraybuffer-object.js41
-rw-r--r--js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-sharedarraybuffer.js23
22 files changed, 981 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/browser.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/browser.js
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/descriptor.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/descriptor.js
new file mode 100644
index 0000000000..96e5f76fa0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/descriptor.js
@@ -0,0 +1,25 @@
+// |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.resize
+description: >
+ ArrayBuffer.prototype.resize has default data property attributes.
+info: |
+ ArrayBuffer.prototype.resize ( 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: [resizable-arraybuffer]
+---*/
+
+verifyProperty(ArrayBuffer.prototype, 'resize', {
+ enumerable: false,
+ writable: true,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/extensible.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/extensible.js
new file mode 100644
index 0000000000..8c4323e6df
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/extensible.js
@@ -0,0 +1,18 @@
+// |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.resize
+description: ArrayBuffer.prototype.resize is extensible.
+info: |
+ ArrayBuffer.prototype.resize ( 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: [resizable-arraybuffer]
+---*/
+
+assert(Object.isExtensible(ArrayBuffer.prototype.resize));
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/length.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/length.js
new file mode 100644
index 0000000000..25772a6f33
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/length.js
@@ -0,0 +1,33 @@
+// |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.resize
+description: >
+ ArrayBuffer.prototype.resize.length is 1.
+info: |
+ ArrayBuffer.prototype.resize ( 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: [resizable-arraybuffer]
+---*/
+
+verifyProperty(ArrayBuffer.prototype.resize, 'length', {
+ value: 1,
+ enumerable: false,
+ writable: false,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/name.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/name.js
new file mode 100644
index 0000000000..c75828f521
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/name.js
@@ -0,0 +1,30 @@
+// |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.resize
+description: >
+ ArrayBuffer.prototype.resize.name is "resize".
+info: |
+ ArrayBuffer.prototype.resize ( 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: [resizable-arraybuffer]
+includes: [propertyHelper.js]
+---*/
+
+verifyProperty(ArrayBuffer.prototype.resize, 'name', {
+ value: 'resize',
+ enumerable: false,
+ writable: false,
+ configurable: true
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-excessive.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-excessive.js
new file mode 100644
index 0000000000..81988067b5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-excessive.js
@@ -0,0 +1,28 @@
+// |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.resize
+description: >
+ Throws a RangeError the newLength value is larger than the max byte length
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ [...]
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(4, {maxByteLength: 4});
+
+assert.throws(RangeError, function() {
+ ab.resize(5);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-negative.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-negative.js
new file mode 100644
index 0000000000..e47ae27a03
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-negative.js
@@ -0,0 +1,28 @@
+// |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.resize
+description: >
+ Throws a RangeError the newLength value is less than zero
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ [...]
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(4, {maxByteLength: 4});
+
+assert.throws(RangeError, function() {
+ ab.resize(-1);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-non-number.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-non-number.js
new file mode 100644
index 0000000000..db3059d21c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-non-number.js
@@ -0,0 +1,40 @@
+// |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.resize
+description: Throws a TypeError if provided length cannot be coerced to a number
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ [...]
+features: [resizable-arraybuffer]
+---*/
+
+var log = [];
+var newLength = {
+ toString: function() {
+ log.push('toString');
+ return {};
+ },
+ valueOf: function() {
+ log.push('valueOf');
+ return {};
+ }
+};
+var ab = new ArrayBuffer(0, {maxByteLength: 4});
+
+assert.throws(TypeError, function() {
+ ab.resize(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/resize/nonconstructor.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/nonconstructor.js
new file mode 100644
index 0000000000..d14b6ae15f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/nonconstructor.js
@@ -0,0 +1,26 @@
+// |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.resize
+description: >
+ ArrayBuffer.prototype.resize is not a constructor function.
+info: |
+ ArrayBuffer.prototype.resize ( 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: [resizable-arraybuffer, Reflect.construct]
+---*/
+
+assert(!isConstructor(ArrayBuffer.prototype.resize), "ArrayBuffer.prototype.resize is not a constructor");
+
+var arrayBuffer = new ArrayBuffer(8);
+assert.throws(TypeError, function() {
+ new arrayBuffer.resize();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-grow.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-grow.js
new file mode 100644
index 0000000000..adb95fe528
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-grow.js
@@ -0,0 +1,80 @@
+// |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.resize
+description: Behavior when attempting to grow a resizable array buffer
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ 7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
+ [...]
+
+ HostResizeArrayBuffer ( buffer, newByteLength )
+
+ The implementation of HostResizeArrayBuffer must conform to the following
+ requirements:
+
+ - The abstract operation does not detach buffer.
+ - The abstract operation may complete normally or abruptly.
+ - If the abstract operation completes normally with handled,
+ buffer.[[ArrayBufferByteLength]] is newByteLength.
+ - The return value is either handled or unhandled.
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(4, {maxByteLength: 5});
+var caught = false;
+var result;
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ab.resize, 'function');
+
+try {
+ result = ab.resize(5);
+} catch (_) {
+ caught = true;
+}
+
+try {
+ ab.slice();
+} catch (_) {
+ throw new Test262Error('The ArrayBuffer under test was detached');
+}
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation and conforms to the
+// invarient regarding [[ArrayBufferByteLength]]
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method updates [[ArrayBufferByteLength]]
+//
+// The final two conditions are indistinguishable.
+assert(caught || ab.byteLength === 5, 'byteLength');
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation, and the `resize`
+// method returns early
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method executes its final steps
+//
+// All three conditions have the same effect on the value of `result`.
+assert.sameValue(result, undefined, 'normal completion value');
+
+// The contents of the ArrayBuffer are not guaranteed by the host-defined
+// abstract operation, so they are not asserted in this test.
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-explicit.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-explicit.js
new file mode 100644
index 0000000000..068735c98d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-explicit.js
@@ -0,0 +1,81 @@
+// |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.resize
+description: >
+ Behavior when attempting to reset the size of a resizable array buffer to zero explicitly
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ 7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
+ [...]
+
+ HostResizeArrayBuffer ( buffer, newByteLength )
+
+ The implementation of HostResizeArrayBuffer must conform to the following
+ requirements:
+
+ - The abstract operation does not detach buffer.
+ - The abstract operation may complete normally or abruptly.
+ - If the abstract operation completes normally with handled,
+ buffer.[[ArrayBufferByteLength]] is newByteLength.
+ - The return value is either handled or unhandled.
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(0, {maxByteLength: 0});
+var caught = false;
+var result;
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ab.resize, 'function');
+
+try {
+ result = ab.resize(0);
+} catch (_) {
+ caught = true;
+}
+
+try {
+ ab.slice();
+} catch (_) {
+ throw new Test262Error('The ArrayBuffer under test was detached');
+}
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation and conforms to the
+// invarient regarding [[ArrayBufferByteLength]]
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method updates [[ArrayBufferByteLength]]
+//
+// The final two conditions are indistinguishable.
+assert(caught || ab.byteLength === 0, 'byteLength');
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation, and the `resize`
+// method returns early
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method executes its final steps
+//
+// All three conditions have the same effect on the value of `result`.
+assert.sameValue(result, undefined, 'normal completion value');
+
+// The contents of the ArrayBuffer are not guaranteed by the host-defined
+// abstract operation, so they are not asserted in this test.
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js
new file mode 100644
index 0000000000..cd78beba50
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js
@@ -0,0 +1,81 @@
+// |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.resize
+description: >
+ Behavior when attempting to reset the size of a resizable array buffer to zero explicitly
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ 7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
+ [...]
+
+ HostResizeArrayBuffer ( buffer, newByteLength )
+
+ The implementation of HostResizeArrayBuffer must conform to the following
+ requirements:
+
+ - The abstract operation does not detach buffer.
+ - The abstract operation may complete normally or abruptly.
+ - If the abstract operation completes normally with handled,
+ buffer.[[ArrayBufferByteLength]] is newByteLength.
+ - The return value is either handled or unhandled.
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(0, {maxByteLength: 0});
+var caught = false;
+var result;
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ab.resize, 'function');
+
+try {
+ result = ab.resize();
+} catch (_) {
+ caught = true;
+}
+
+try {
+ ab.slice();
+} catch (_) {
+ throw new Test262Error('The ArrayBuffer under test was detached');
+}
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation and conforms to the
+// invarient regarding [[ArrayBufferByteLength]]
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method updates [[ArrayBufferByteLength]]
+//
+// The final two conditions are indistinguishable.
+assert(caught || ab.byteLength === 0, 'byteLength');
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation, and the `resize`
+// method returns early
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method executes its final steps
+//
+// All three conditions have the same effect on the value of `result`.
+assert.sameValue(result, undefined, 'normal completion value');
+
+// The contents of the ArrayBuffer are not guaranteed by the host-defined
+// abstract operation, so they are not asserted in this test.
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size.js
new file mode 100644
index 0000000000..8e9dbf37ff
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size.js
@@ -0,0 +1,81 @@
+// |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.resize
+description: >
+ Behavior when attempting to reset the size of a resizable array buffer
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ 7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
+ [...]
+
+ HostResizeArrayBuffer ( buffer, newByteLength )
+
+ The implementation of HostResizeArrayBuffer must conform to the following
+ requirements:
+
+ - The abstract operation does not detach buffer.
+ - The abstract operation may complete normally or abruptly.
+ - If the abstract operation completes normally with handled,
+ buffer.[[ArrayBufferByteLength]] is newByteLength.
+ - The return value is either handled or unhandled.
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(4, {maxByteLength: 4});
+var caught = false;
+var result;
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ab.resize, 'function');
+
+try {
+ result = ab.resize(4);
+} catch (_) {
+ caught = true;
+}
+
+try {
+ ab.slice();
+} catch (_) {
+ throw new Test262Error('The ArrayBuffer under test was detached');
+}
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation and conforms to the
+// invarient regarding [[ArrayBufferByteLength]]
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method updates [[ArrayBufferByteLength]]
+//
+// The final two conditions are indistinguishable.
+assert(caught || ab.byteLength === 4, 'byteLength');
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation, and the `resize`
+// method returns early
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method executes its final steps
+//
+// All three conditions have the same effect on the value of `result`.
+assert.sameValue(result, undefined, 'normal completion value');
+
+// The contents of the ArrayBuffer are not guaranteed by the host-defined
+// abstract operation, so they are not asserted in this test.
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-explicit.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-explicit.js
new file mode 100644
index 0000000000..59f41980c8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-explicit.js
@@ -0,0 +1,80 @@
+// |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.resize
+description: Behavior when attempting to shrink a resizable array buffer to zero explicitly
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ 7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
+ [...]
+
+ HostResizeArrayBuffer ( buffer, newByteLength )
+
+ The implementation of HostResizeArrayBuffer must conform to the following
+ requirements:
+
+ - The abstract operation does not detach buffer.
+ - The abstract operation may complete normally or abruptly.
+ - If the abstract operation completes normally with handled,
+ buffer.[[ArrayBufferByteLength]] is newByteLength.
+ - The return value is either handled or unhandled.
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(4, {maxByteLength: 4});
+var caught = false;
+var result;
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ab.resize, 'function');
+
+try {
+ result = ab.resize(0);
+} catch (_) {
+ caught = true;
+}
+
+try {
+ ab.slice();
+} catch (_) {
+ throw new Test262Error('The ArrayBuffer under test was detached');
+}
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation and conforms to the
+// invarient regarding [[ArrayBufferByteLength]]
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method updates [[ArrayBufferByteLength]]
+//
+// The final two conditions are indistinguishable.
+assert(caught || ab.byteLength === 0, 'byteLength');
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation, and the `resize`
+// method returns early
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method executes its final steps
+//
+// All three conditions have the same effect on the value of `result`.
+assert.sameValue(result, undefined, 'normal completion value');
+
+// The contents of the ArrayBuffer are not guaranteed by the host-defined
+// abstract operation, so they are not asserted in this test.
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-implicit.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-implicit.js
new file mode 100644
index 0000000000..c1b72f35fe
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-implicit.js
@@ -0,0 +1,80 @@
+// |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.resize
+description: Behavior when attempting to shrink a resizable array buffer to zero implicitly
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ 7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
+ [...]
+
+ HostResizeArrayBuffer ( buffer, newByteLength )
+
+ The implementation of HostResizeArrayBuffer must conform to the following
+ requirements:
+
+ - The abstract operation does not detach buffer.
+ - The abstract operation may complete normally or abruptly.
+ - If the abstract operation completes normally with handled,
+ buffer.[[ArrayBufferByteLength]] is newByteLength.
+ - The return value is either handled or unhandled.
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(4, {maxByteLength: 4});
+var caught = false;
+var result;
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ab.resize, 'function');
+
+try {
+ result = ab.resize();
+} catch (_) {
+ caught = true;
+}
+
+try {
+ ab.slice();
+} catch (_) {
+ throw new Test262Error('The ArrayBuffer under test was detached');
+}
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation and conforms to the
+// invarient regarding [[ArrayBufferByteLength]]
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method updates [[ArrayBufferByteLength]]
+//
+// The final two conditions are indistinguishable.
+assert(caught || ab.byteLength === 0, 'byteLength');
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation, and the `resize`
+// method returns early
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method executes its final steps
+//
+// All three conditions have the same effect on the value of `result`.
+assert.sameValue(result, undefined, 'normal completion value');
+
+// The contents of the ArrayBuffer are not guaranteed by the host-defined
+// abstract operation, so they are not asserted in this test.
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink.js
new file mode 100644
index 0000000000..5b9973934f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink.js
@@ -0,0 +1,80 @@
+// |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.resize
+description: Behavior when attempting to shrink a resizable array buffer
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ 5. Let newByteLength be ? ToIntegerOrInfinity(newLength).
+ 6. If newByteLength < 0 or newByteLength > O.[[ArrayBufferMaxByteLength]],
+ throw a RangeError exception.
+ 7. Let hostHandled be ? HostResizeArrayBuffer(O, newByteLength).
+ [...]
+
+ HostResizeArrayBuffer ( buffer, newByteLength )
+
+ The implementation of HostResizeArrayBuffer must conform to the following
+ requirements:
+
+ - The abstract operation does not detach buffer.
+ - The abstract operation may complete normally or abruptly.
+ - If the abstract operation completes normally with handled,
+ buffer.[[ArrayBufferByteLength]] is newByteLength.
+ - The return value is either handled or unhandled.
+features: [resizable-arraybuffer]
+---*/
+
+var ab = new ArrayBuffer(4, {maxByteLength: 4});
+var caught = false;
+var result;
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ab.resize, 'function');
+
+try {
+ result = ab.resize(3);
+} catch (_) {
+ caught = true;
+}
+
+try {
+ ab.slice();
+} catch (_) {
+ throw new Test262Error('The ArrayBuffer under test was detached');
+}
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation and conforms to the
+// invarient regarding [[ArrayBufferByteLength]]
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method updates [[ArrayBufferByteLength]]
+//
+// The final two conditions are indistinguishable.
+assert(caught || ab.byteLength === 3, 'byteLength');
+
+// One of the following three conditions must be met:
+//
+// - HostResizeArrayBuffer returns an abrupt completion
+// - HostResizeArrayBuffer handles the resize operation, and the `resize`
+// method returns early
+// - HostResizeArrayBuffer does not handle the resize operation, and the
+// `resize` method executes its final steps
+//
+// All three conditions have the same effect on the value of `result`.
+assert.sameValue(result, undefined, 'normal completion value');
+
+// The contents of the ArrayBuffer are not guaranteed by the host-defined
+// abstract operation, so they are not asserted in this test.
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/shell.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/shell.js
new file mode 100644
index 0000000000..06f65290b8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/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/resize/this-is-detached.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-detached.js
new file mode 100644
index 0000000000..c58f1d4217
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-detached.js
@@ -0,0 +1,30 @@
+// |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.resize
+description: >
+ Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ 4. If IsDetachedBuffer(O) is true, throw a TypeError exception.
+ [...]
+includes: [detachArrayBuffer.js]
+features: [resizable-arraybuffer]
+---*/
+
+assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
+
+var ab = new ArrayBuffer(1);
+
+$DETACHBUFFER(ab);
+
+assert.throws(TypeError, function() {
+ ab.resize();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-arraybuffer-object.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-arraybuffer-object.js
new file mode 100644
index 0000000000..473e8c7d99
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-arraybuffer-object.js
@@ -0,0 +1,31 @@
+// |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.resize
+description: >
+ Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot.
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ [...]
+features: [resizable-arraybuffer]
+---*/
+
+assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize();
+}, '`this` value is the ArrayBuffer prototype');
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call({});
+}, '`this` value is an object');
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call([]);
+}, '`this` value is an array');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-object.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-object.js
new file mode 100644
index 0000000000..28ceccfa4d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-object.js
@@ -0,0 +1,47 @@
+// |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.resize
+description: Throws a TypeError if `this` valueis not an object.
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ [...]
+features: [resizable-arraybuffer, Symbol, BigInt]
+---*/
+
+assert.sameValue(typeof ArrayBuffer.prototype.resize, "function");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call(undefined);
+}, "`this` value is undefined");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call(null);
+}, "`this` value is null");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call(true);
+}, "`this` value is Boolean");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call("");
+}, "`this` value is String");
+
+var symbol = Symbol();
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call(symbol);
+}, "`this` value is Symbol");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call(1);
+}, "`this` value is Number");
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call(1n);
+}, "`this` value is bigint");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-resizable-arraybuffer-object.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-resizable-arraybuffer-object.js
new file mode 100644
index 0000000000..586ad2aec3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-resizable-arraybuffer-object.js
@@ -0,0 +1,41 @@
+// |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.resize
+description: >
+ Throws a TypeError if `this` does not have an [[ArrayBufferMaxByteLength]] internal slot.
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ [...]
+features: [resizable-arraybuffer]
+---*/
+
+var ab;
+
+assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
+
+ab = new ArrayBuffer(4);
+assert.throws(TypeError, function() {
+ ab.resize(0);
+}, 'zero byte length');
+
+ab = new ArrayBuffer(4);
+assert.throws(TypeError, function() {
+ ab.resize(3);
+}, 'smaller byte length');
+
+ab = new ArrayBuffer(4);
+assert.throws(TypeError, function() {
+ ab.resize(4);
+}, 'same byte length');
+
+ab = new ArrayBuffer(4);
+assert.throws(TypeError, function() {
+ ab.resize(5);
+}, 'larger byte length');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-sharedarraybuffer.js b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-sharedarraybuffer.js
new file mode 100644
index 0000000000..48cb404b63
--- /dev/null
+++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-sharedarraybuffer.js
@@ -0,0 +1,23 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!this.hasOwnProperty('SharedArrayBuffer')||!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- SharedArrayBuffer,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.resize
+description: Throws a TypeError if `this` value is a SharedArrayBuffer
+info: |
+ ArrayBuffer.prototype.resize ( newLength )
+
+ 1. Let O be the this value.
+ 2. Perform ? RequireInternalSlot(O, [[ArrayBufferMaxByteLength]]).
+ 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception.
+ [...]
+features: [SharedArrayBuffer, resizable-arraybuffer]
+---*/
+
+var sab = new SharedArrayBuffer(0);
+
+assert.throws(TypeError, function() {
+ ArrayBuffer.prototype.resize.call(sab);
+}, '`this` value cannot be a SharedArrayBuffer');
+
+reportCompare(0, 0);