diff options
Diffstat (limited to '')
22 files changed, 983 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..76ae6201dc --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/descriptor.js @@ -0,0 +1,25 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..da365b0a45 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/extensible.js @@ -0,0 +1,18 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..b499ce86fe --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/length.js @@ -0,0 +1,33 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..e08be0eb78 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/name.js @@ -0,0 +1,30 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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, + wrtiable: 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..0f900f2cfb --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-excessive.js @@ -0,0 +1,28 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..af9e04698c --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-negative.js @@ -0,0 +1,28 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..6f71b83a4a --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/new-length-non-number.js @@ -0,0 +1,40 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..b86b4e7dec --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/nonconstructor.js @@ -0,0 +1,28 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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. +features: [resizable-arraybuffer] +---*/ + +assert.sameValue( + Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.resize, 'prototype'), + false +); + +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..1c13e70454 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-grow.js @@ -0,0 +1,80 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..044007f7ba --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-explicit.js @@ -0,0 +1,81 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..796da99188 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js @@ -0,0 +1,81 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..7d7d19115a --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size.js @@ -0,0 +1,81 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..3b76fd8dd0 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-explicit.js @@ -0,0 +1,80 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..8ee12b549e --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink-zero-implicit.js @@ -0,0 +1,80 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..22ac4373be --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-shrink.js @@ -0,0 +1,80 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..2b8363035e --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-detached.js @@ -0,0 +1,30 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..0a6a68a73a --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-arraybuffer-object.js @@ -0,0 +1,31 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..00e3672875 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-object.js @@ -0,0 +1,47 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..49714023fe --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-not-resizable-arraybuffer-object.js @@ -0,0 +1,41 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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..f1c7b2fe09 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/this-is-sharedarraybuffer.js @@ -0,0 +1,23 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-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); |