diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js')
-rw-r--r-- | js/src/tests/test262/built-ins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js | 81 |
1 files changed, 81 insertions, 0 deletions
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); |