Skip to content

Commit ddb3863

Browse files
committed
Editorial: Introduce AllocateImmutableArrayBuffer
1 parent 04b49a7 commit ddb3863

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

spec.emu

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,33 @@ contributors: Mark S. Miller, Richard Gibson
430430
</emu-alg>
431431
</emu-clause>
432432

433+
<ins class="block">
434+
435+
<emu-clause id="sec-allocateimmutablearraybuffer" type="abstract operation">
436+
<h1>
437+
AllocateImmutableArrayBuffer (
438+
_constructor_: a constructor,
439+
_byteLength_: a non-negative integer,
440+
_fromBlock_: a Data Block,
441+
_fromIndex_: a non-negative integer,
442+
_count_: a non-negative integer,
443+
): either a normal completion containing an ArrayBuffer or a throw completion
444+
</h1>
445+
<dl class="header">
446+
<dt>description</dt>
447+
<dd>It is used to create an immutable ArrayBuffer (i.e., an ArrayBuffer with a an [[ArrayBufferIsImmutable]] slot) with contents from _fromBlock_.</dd>
448+
</dl>
449+
<emu-alg>
450+
1. Assert: _constructor_ is %ArrayBuffer%.
451+
1. Assert: _count_ ≤ _byteLength_.
452+
1. Let _newBuffer_ be ? <emu-meta suppress-effects="user-code">AllocateArrayBuffer(_constructor_, _byteLength_, ~immutable~)</emu-meta>.
453+
1. Let _toBlock_ be _newBuffer_.[[ArrayBufferData]].
454+
1. Perform CopyDataBlockBytes(_toBlock_, 0, _fromBlock_, 0, _count_).
455+
1. Return _newBuffer_.
456+
</emu-alg>
457+
</emu-clause>
458+
</ins>
459+
433460
<emu-clause id="sec-arraybuffercopyanddetach" type="abstract operation" number="3">
434461
<h1>
435462
ArrayBufferCopyAndDetach (
@@ -449,15 +476,16 @@ contributors: Mark S. Miller, Richard Gibson
449476
1. Let _newByteLength_ be ? ToIndex(_newLength_).
450477
1. If IsDetachedBuffer(_arrayBuffer_) is *true*, throw a *TypeError* exception.
451478
1. <ins>If IsImmutableBuffer(_arrayBuffer_) is *true*, throw a *TypeError* exception.</ins>
479+
1. <ins>Let _copyLength_ be min(_newByteLength_, _arrayBuffer_.[[ArrayBufferByteLength]]).</ins>
480+
1. <ins>If _preserveResizability_ is ~immutable~, then</ins>
481+
1. <ins>Return ? AllocateImmutableArrayBuffer(%ArrayBuffer%, _newByteLength_, _arrayBuffer_.[[ArrayBufferData]], 0, _copyLength_).</ins>
452482
1. If _preserveResizability_ is ~preserve-resizability~ and IsFixedLengthArrayBuffer(_arrayBuffer_) is *false*, then
453483
1. Let _newMaxByteLength_ be _arrayBuffer_.[[ArrayBufferMaxByteLength]].
454-
1. <ins>Else if _preserveResizability_ is ~immutable~, then</ins>
455-
1. <ins>Let _newMaxByteLength_ be ~immutable~.</ins>
456484
1. Else,
457485
1. Let _newMaxByteLength_ be ~empty~.
458486
1. If _arrayBuffer_.[[ArrayBufferDetachKey]] is not *undefined*, throw a *TypeError* exception.
459487
1. Let _newBuffer_ be ? <emu-meta suppress-effects="user-code">AllocateArrayBuffer(%ArrayBuffer%, _newByteLength_, _newMaxByteLength_)</emu-meta>.
460-
1. Let _copyLength_ be min(_newByteLength_, _arrayBuffer_.[[ArrayBufferByteLength]]).
488+
1. <del>Let _copyLength_ be min(_newByteLength_, _arrayBuffer_.[[ArrayBufferByteLength]]).</del>
461489
1. Let _fromBlock_ be _arrayBuffer_.[[ArrayBufferData]].
462490
1. Let _toBlock_ be _newBuffer_.[[ArrayBufferData]].
463491
1. <ins>NOTE: This is the only step that can write into the Data Block of an immutable ArrayBuffer.</ins>
@@ -636,7 +664,6 @@ contributors: Mark S. Miller, Richard Gibson
636664
</emu-clause>
637665

638666
<ins class="block">
639-
640667
<emu-clause id="sec-arraybuffer.prototype.transfertoimmutable">
641668
<h1>ArrayBuffer.prototype.transferToImmutable ( [ _newLength_ ] )</h1>
642669
<p>This method performs the following steps when called:</p>

0 commit comments

Comments
 (0)