Skip to content

Normative: add ArrayBuffer.prototype.{detached,transfer,transferToFixedLength} #3175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -42748,6 +42748,40 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-arraybuffercopyanddetach" type="abstract operation">
<h1>
ArrayBufferCopyAndDetach (
_arrayBuffer_: an ECMAScript language value,
_newLength_: an ECMAScript language value,
_preserveResizability_: ~preserve-resizability~ or ~fixed-length~,
): either a normal completion containing an ArrayBuffer or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Perform ? RequireInternalSlot(_arrayBuffer_, [[ArrayBufferData]]).
1. If IsSharedArrayBuffer(_arrayBuffer_) is *true*, throw a *TypeError* exception.
1. If _newLength_ is *undefined*, then
1. Let _newByteLength_ be _arrayBuffer_.[[ArrayBufferByteLength]].
1. Else,
1. Let _newByteLength_ be ? ToIndex(_newLength_).
1. If IsDetachedBuffer(_arrayBuffer_) is *true*, throw a *TypeError* exception.
1. If _preserveResizability_ is ~preserve-resizability~ and IsFixedLengthArrayBuffer(_arrayBuffer_) is *false*, then
1. Let _newMaxByteLength_ be _arrayBuffer_.[[ArrayBufferMaxByteLength]].
1. Else,
1. Let _newMaxByteLength_ be ~empty~.
1. If _arrayBuffer_.[[ArrayBufferDetachKey]] is not *undefined*, throw a *TypeError* exception.
1. Let _newBuffer_ be ? <emu-meta suppress-effects="user-code">AllocateArrayBuffer(%ArrayBuffer%, _newByteLength_, _newMaxByteLength_)</emu-meta>.
1. Let _copyLength_ be min(_newByteLength_, _arrayBuffer_.[[ArrayBufferByteLength]]).
1. Let _fromBlock_ be _arrayBuffer_.[[ArrayBufferData]].
1. Let _toBlock_ be _newBuffer_.[[ArrayBufferData]].
1. Perform CopyDataBlockBytes(_toBlock_, 0, _fromBlock_, 0, _copyLength_).
1. NOTE: Neither creation of the new Data Block nor copying from the old Data Block are observable. Implementations may implement this method as a zero-copy move or a `realloc`.
1. Perform ! DetachArrayBuffer(_arrayBuffer_).
1. Return _newBuffer_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-isdetachedbuffer" type="abstract operation">
<h1>
IsDetachedBuffer (
Expand All @@ -42770,6 +42804,8 @@ <h1>
): either a normal completion containing ~unused~ or a throw completion
</h1>
<dl class="header">
<dt>skip global checks</dt>
<dd>true</dd>
</dl>
<emu-alg>
1. Assert: IsSharedArrayBuffer(_arrayBuffer_) is *false*.
Expand Down Expand Up @@ -43192,6 +43228,17 @@ <h1>ArrayBuffer.prototype.constructor</h1>
<p>The initial value of `ArrayBuffer.prototype.constructor` is %ArrayBuffer%.</p>
</emu-clause>

<emu-clause id="sec-get-arraybuffer.prototype.detached">
<h1>get ArrayBuffer.prototype.detached</h1>
<p>`ArrayBuffer.prototype.detached` is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps when called:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Perform ? RequireInternalSlot(_O_, [[ArrayBufferData]]).
1. If IsSharedArrayBuffer(_O_) is *true*, throw a *TypeError* exception.
1. Return IsDetachedBuffer(_O_).
</emu-alg>
</emu-clause>

<emu-clause id="sec-get-arraybuffer.prototype.maxbytelength">
<h1>get ArrayBuffer.prototype.maxByteLength</h1>
<p>`ArrayBuffer.prototype.maxByteLength` is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps when called:</p>
Expand Down Expand Up @@ -43279,6 +43326,24 @@ <h1>ArrayBuffer.prototype.slice ( _start_, _end_ )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-arraybuffer.prototype.transfer">
<h1>ArrayBuffer.prototype.transfer ( [ _newLength_ ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Return ? ArrayBufferCopyAndDetach(_O_, _newLength_, ~preserve-resizability~).
</emu-alg>
</emu-clause>

<emu-clause id="sec-arraybuffer.prototype.transfertofixedlength">
<h1>ArrayBuffer.prototype.transferToFixedLength ( [ _newLength_ ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Return ? ArrayBufferCopyAndDetach(_O_, _newLength_, ~fixed-length~).
</emu-alg>
</emu-clause>

<emu-clause id="sec-arraybuffer.prototype-@@tostringtag">
<h1>ArrayBuffer.prototype [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value *"ArrayBuffer"*.</p>
Expand Down