Skip to content

Commit 7103589

Browse files
committed
Editorial: Introduce AllocateImmutableArrayBuffer
1 parent c92d358 commit 7103589

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
@@ -429,6 +429,33 @@ contributors: Mark S. Miller, Richard Gibson
429429
</emu-alg>
430430
</emu-clause>
431431

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

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

0 commit comments

Comments
 (0)