Skip to content

Commit aee1733

Browse files
committed
Normative: Introduce ArrayBuffer.prototype.sliceToImmutable
Fixes tc39#9
1 parent 6c60bf0 commit aee1733

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

spec.emu

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,34 @@ contributors: Mark S. Miller, Richard Gibson
688688
</emu-clause>
689689

690690
<ins class="block">
691+
692+
<emu-clause id="sec-arraybuffer.prototype.slicetoimmutable">
693+
<h1>ArrayBuffer.prototype.sliceToImmutable ( _start_, _end_ )</h1>
694+
<p>This method performs the following steps when called:</p>
695+
<emu-alg>
696+
1. Let _O_ be the *this* value.
697+
1. Perform ? RequireInternalSlot(_O_, [[ArrayBufferData]]).
698+
1. If IsSharedArrayBuffer(_O_) is *true*, throw a *TypeError* exception.
699+
1. TODO: Confirm inclusion of this redundant check.
700+
1. If IsDetachedBuffer(_O_) is *true*, throw a *TypeError* exception.
701+
1. Let _len_ be _O_.[[ArrayBufferByteLength]].
702+
1. Let _bounds_ be ? ResolveBounds(_len_, _start_, _end_).
703+
1. Let _first_ be _bounds_.[[From]].
704+
1. Let _final_ be _bounds_.[[To]].
705+
1. TODO: Confirm this strictness vs. the conventional `max(_final_ - _first_, 0)`.
706+
1. Let _newLen_ be _final_ - _first_.
707+
1. If _newLen_ &lt; 0, throw a *RangeError* exception.
708+
1. Let _copyLen_ be min(_newLen_, _len_).
709+
1. NOTE: Side-effects of the above steps may have detached or resized _O_. This algorithm proceeds only when _O_ is not detached, even if _newLen_ is 0.
710+
1. If IsDetachedBuffer(_O_) is *true*, throw a *TypeError* exception.
711+
1. Let _newBuffer_ be ? AllocateImmutableArrayBuffer(%ArrayBuffer%, _newLen_, _O_.[[ArrayBufferData]], _first_, _copyLen_).
712+
1. Return _newBuffer_.
713+
</emu-alg>
714+
</emu-clause>
715+
</ins>
716+
717+
<ins class="block">
718+
691719
<emu-clause id="sec-arraybuffer.prototype.transfertoimmutable">
692720
<h1>ArrayBuffer.prototype.transferToImmutable ( [ _newLength_ ] )</h1>
693721
<p>This method performs the following steps when called:</p>

0 commit comments

Comments
 (0)