Skip to content

Commit

Permalink
Normative: add ArrayBuffer.prototype.{detached,transfer,transferToFix…
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 3, 2023
1 parent 82c99bb commit 69a35bc
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -42663,6 +42663,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 @@ -42685,6 +42719,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 @@ -43107,6 +43143,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 @@ -43194,6 +43241,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

0 comments on commit 69a35bc

Please sign in to comment.