Skip to content

Commit 09a5368

Browse files
committed
Normative: Introduce ArrayBuffer.prototype.sliceToImmutable
Fixes #9
1 parent 9054759 commit 09a5368

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
@@ -697,6 +697,34 @@ contributors: Mark S. Miller, Richard Gibson
697697
</emu-clause>
698698

699699
<ins class="block">
700+
701+
<emu-clause id="sec-arraybuffer.prototype.slicetoimmutable">
702+
<h1>ArrayBuffer.prototype.sliceToImmutable ( _start_, _end_ )</h1>
703+
<p>This method performs the following steps when called:</p>
704+
<emu-alg>
705+
1. Let _O_ be the *this* value.
706+
1. Perform ? RequireInternalSlot(_O_, [[ArrayBufferData]]).
707+
1. If IsSharedArrayBuffer(_O_) is *true*, throw a *TypeError* exception.
708+
1. TODO: Confirm inclusion of this redundant check.
709+
1. If IsDetachedBuffer(_O_) is *true*, throw a *TypeError* exception.
710+
1. Let _len_ be _O_.[[ArrayBufferByteLength]].
711+
1. Let _bounds_ be ? ResolveBounds(_len_, _start_, _end_).
712+
1. Let _first_ be _bounds_.[[From]].
713+
1. Let _final_ be _bounds_.[[To]].
714+
1. TODO: Confirm this strictness vs. the conventional `max(_final_ - _first_, 0)`.
715+
1. Let _newLen_ be _final_ - _first_.
716+
1. If _newLen_ &lt; 0, throw a *RangeError* exception.
717+
1. Let _copyLen_ be min(_newLen_, _len_).
718+
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.
719+
1. If IsDetachedBuffer(_O_) is *true*, throw a *TypeError* exception.
720+
1. Let _newBuffer_ be ? AllocateImmutableArrayBuffer(%ArrayBuffer%, _newLen_, _O_.[[ArrayBufferData]], _first_, _copyLen_).
721+
1. Return _newBuffer_.
722+
</emu-alg>
723+
</emu-clause>
724+
</ins>
725+
726+
<ins class="block">
727+
700728
<emu-clause id="sec-arraybuffer.prototype.transfertoimmutable">
701729
<h1>ArrayBuffer.prototype.transferToImmutable ( [ _newLength_ ] )</h1>
702730
<p>This method performs the following steps when called:</p>

0 commit comments

Comments
 (0)