Skip to content

Commit f6835b9

Browse files
committed
Normative: Fix ArrayBufferCopyAndDetach
Ref tc39#31 * Always respect [[ArrayBufferDetachKey]]. * Always detach.
1 parent 7285e6a commit f6835b9

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

spec.emu

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -454,20 +454,22 @@ contributors: Mark S. Miller, Richard Gibson
454454
1. Let _newByteLength_ be ? ToIndex(_newLength_).
455455
1. If IsDetachedBuffer(_arrayBuffer_) is *true*, throw a *TypeError* exception.
456456
1. <ins>If IsImmutableBuffer(_arrayBuffer_) is *true*, throw a *TypeError* exception.</ins>
457+
1. <ins>If _arrayBuffer_.[[ArrayBufferDetachKey]] is not *undefined*, throw a *TypeError* exception.</ins>
457458
1. <ins>Let _copyLength_ be min(_newByteLength_, _arrayBuffer_.[[ArrayBufferByteLength]]).</ins>
458459
1. <ins>If _preserveResizability_ is ~immutable~, then</ins>
459-
1. <ins>Return ? AllocateImmutableArrayBuffer(%ArrayBuffer%, _newByteLength_, _arrayBuffer_.[[ArrayBufferData]], 0, _copyLength_).</ins>
460-
1. If _preserveResizability_ is ~preserve-resizability~ and IsFixedLengthArrayBuffer(_arrayBuffer_) is *false*, then
461-
1. Let _newMaxByteLength_ be _arrayBuffer_.[[ArrayBufferMaxByteLength]].
462-
1. Else,
463-
1. Let _newMaxByteLength_ be ~empty~.
464-
1. If _arrayBuffer_.[[ArrayBufferDetachKey]] is not *undefined*, throw a *TypeError* exception.
465-
1. Let _newBuffer_ be ? <emu-meta suppress-effects="user-code">AllocateArrayBuffer(%ArrayBuffer%, _newByteLength_, _newMaxByteLength_)</emu-meta>.
466-
1. <del>Let _copyLength_ be min(_newByteLength_, _arrayBuffer_.[[ArrayBufferByteLength]]).</del>
467-
1. Let _fromBlock_ be _arrayBuffer_.[[ArrayBufferData]].
468-
1. Let _toBlock_ be _newBuffer_.[[ArrayBufferData]].
469-
1. Perform CopyDataBlockBytes(_toBlock_, 0, _fromBlock_, 0, _copyLength_).
470-
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`.
460+
1. <ins>Let _newBuffer_ be ? <emu-meta suppress-effects="user-code">AllocateImmutableArrayBuffer(%ArrayBuffer%, _newByteLength_, _arrayBuffer_.[[ArrayBufferData]], 0, _copyLength_)</emu-meta>.</ins>
461+
1. <ins>Else,</ins>
462+
1. If _preserveResizability_ is ~preserve-resizability~ and IsFixedLengthArrayBuffer(_arrayBuffer_) is *false*, then
463+
1. Let _newMaxByteLength_ be _arrayBuffer_.[[ArrayBufferMaxByteLength]].
464+
1. Else,
465+
1. Let _newMaxByteLength_ be ~empty~.
466+
1. <del>If _arrayBuffer_.[[ArrayBufferDetachKey]] is not *undefined*, throw a *TypeError* exception.</del>
467+
1. Let _newBuffer_ be ? <emu-meta suppress-effects="user-code">AllocateArrayBuffer(%ArrayBuffer%, _newByteLength_, _newMaxByteLength_)</emu-meta>.
468+
1. <del>Let _copyLength_ be min(_newByteLength_, _arrayBuffer_.[[ArrayBufferByteLength]]).</del>
469+
1. Let _fromBlock_ be _arrayBuffer_.[[ArrayBufferData]].
470+
1. Let _toBlock_ be _newBuffer_.[[ArrayBufferData]].
471+
1. Perform CopyDataBlockBytes(_toBlock_, 0, _fromBlock_, 0, _copyLength_).
472+
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`.
471473
1. Perform ! DetachArrayBuffer(_arrayBuffer_).
472474
1. Return _newBuffer_.
473475
</emu-alg>

0 commit comments

Comments
 (0)