Skip to content

Commit da858bc

Browse files
committed
Normative: Account for TypedArraySpeciesCreate species lookup
Fixes #46
1 parent bad00ba commit da858bc

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

spec.emu

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,58 @@ contributors: Mark S. Miller, Richard Gibson
262262
</emu-alg>
263263
</emu-clause>
264264

265+
<emu-clause id="sec-%typedarray%.prototype.filter" number="10">
266+
<h1>%TypedArray%.prototype.filter ( _callback_ [ , _thisArg_ ] )</h1>
267+
<p>The interpretation and use of the arguments of this method are the same as for `Array.prototype.filter` as defined in <emu-xref href="#sec-array.prototype.filter"></emu-xref>.</p>
268+
<p>This method performs the following steps when called:</p>
269+
<emu-alg>
270+
1. Let _O_ be the *this* value.
271+
1. Let _taRecord_ be ? ValidateTypedArray(_O_, ~seq-cst~).
272+
1. Let _len_ be TypedArrayLength(_taRecord_).
273+
1. If IsCallable(_callback_) is *false*, throw a *TypeError* exception.
274+
1. Let _kept_ be a new empty List.
275+
1. Let _captured_ be 0.
276+
1. Let _k_ be 0.
277+
1. Repeat, while _k_ &lt; _len_,
278+
1. Let _Pk_ be ! ToString(𝔽(_k_)).
279+
1. Let _kValue_ be ! Get(_O_, _Pk_).
280+
1. Let _selected_ be ToBoolean(? Call(_callback_, _thisArg_, « _kValue_, 𝔽(_k_), _O_ »)).
281+
1. If _selected_ is *true*, then
282+
1. Append _kValue_ to _kept_.
283+
1. Set _captured_ to _captured_ + 1.
284+
1. Set _k_ to _k_ + 1.
285+
1. Let _A_ be ? TypedArraySpeciesCreate(_O_, « 𝔽(_captured_) »<ins>, ~write~</ins>).
286+
1. Let _n_ be 0.
287+
1. For each element _e_ of _kept_, do
288+
1. Perform <del>!</del><ins>?</ins> Set(_A_, ! ToString(𝔽(_n_)), _e_, *true*).
289+
1. Set _n_ to _n_ + 1.
290+
1. Return _A_.
291+
</emu-alg>
292+
<p>This method is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.</p>
293+
</emu-clause>
294+
295+
<emu-clause id="sec-%typedarray%.prototype.map" number="22">
296+
<h1>%TypedArray%.prototype.map ( _callback_ [ , _thisArg_ ] )</h1>
297+
<p>The interpretation and use of the arguments of this method are the same as for `Array.prototype.map` as defined in <emu-xref href="#sec-array.prototype.map"></emu-xref>.</p>
298+
<p>This method performs the following steps when called:</p>
299+
<emu-alg>
300+
1. Let _O_ be the *this* value.
301+
1. Let _taRecord_ be ? ValidateTypedArray(_O_, ~seq-cst~).
302+
1. Let _len_ be TypedArrayLength(_taRecord_).
303+
1. If IsCallable(_callback_) is *false*, throw a *TypeError* exception.
304+
1. Let _A_ be ? TypedArraySpeciesCreate(_O_, « 𝔽(_len_) »<ins>, ~write~</ins>).
305+
1. Let _k_ be 0.
306+
1. Repeat, while _k_ &lt; _len_,
307+
1. Let _Pk_ be ! ToString(𝔽(_k_)).
308+
1. Let _kValue_ be ! Get(_O_, _Pk_).
309+
1. Let _mappedValue_ be ? Call(_callback_, _thisArg_, « _kValue_, 𝔽(_k_), _O_ »).
310+
1. Perform ? Set(_A_, _Pk_, _mappedValue_, *true*).
311+
1. Set _k_ to _k_ + 1.
312+
1. Return _A_.
313+
</emu-alg>
314+
<p>This method is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.</p>
315+
</emu-clause>
316+
265317
<emu-clause id="sec-%typedarray%.prototype.reverse" number="25">
266318
<h1>%TypedArray%.prototype.reverse ( )</h1>
267319
<p>The interpretation and use of the arguments of this method are the same as for `Array.prototype.reverse` as defined in <emu-xref href="#sec-array.prototype.reverse"></emu-xref>.</p>
@@ -307,6 +359,59 @@ contributors: Mark S. Miller, Richard Gibson
307359
<p>This method is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.</p>
308360
</emu-clause>
309361

362+
<emu-clause id="sec-%typedarray%.prototype.slice" number="27">
363+
<h1>%TypedArray%.prototype.slice ( _start_, _end_ )</h1>
364+
<p>The interpretation and use of the arguments of this method are the same as for `Array.prototype.slice` as defined in <emu-xref href="#sec-array.prototype.slice"></emu-xref>.</p>
365+
<p>This method performs the following steps when called:</p>
366+
<emu-alg>
367+
1. Let _O_ be the *this* value.
368+
1. Let _taRecord_ be ? ValidateTypedArray(_O_, ~seq-cst~).
369+
1. Let _srcArrayLength_ be TypedArrayLength(_taRecord_).
370+
1. Let _relativeStart_ be ? ToIntegerOrInfinity(_start_).
371+
1. If _relativeStart_ = -∞, let _startIndex_ be 0.
372+
1. Else if _relativeStart_ &lt; 0, let _startIndex_ be max(_srcArrayLength_ + _relativeStart_, 0).
373+
1. Else, let _startIndex_ be min(_relativeStart_, _srcArrayLength_).
374+
1. If _end_ is *undefined*, let _relativeEnd_ be _srcArrayLength_; else let _relativeEnd_ be ? ToIntegerOrInfinity(_end_).
375+
1. If _relativeEnd_ = -∞, let _endIndex_ be 0.
376+
1. Else if _relativeEnd_ &lt; 0, let _endIndex_ be max(_srcArrayLength_ + _relativeEnd_, 0).
377+
1. Else, let _endIndex_ be min(_relativeEnd_, _srcArrayLength_).
378+
1. Let _countBytes_ be max(_endIndex_ - _startIndex_, 0).
379+
1. Let _A_ be ? TypedArraySpeciesCreate(_O_, « 𝔽(_countBytes_) »<ins>, ~write~</ins>).
380+
1. If _countBytes_ > 0, then
381+
1. Set _taRecord_ to MakeTypedArrayWithBufferWitnessRecord(_O_, ~seq-cst~).
382+
1. If IsTypedArrayOutOfBounds(_taRecord_) is *true*, throw a *TypeError* exception.
383+
1. Set _endIndex_ to min(_endIndex_, TypedArrayLength(_taRecord_)).
384+
1. Set _countBytes_ to max(_endIndex_ - _startIndex_, 0).
385+
1. Let _srcType_ be TypedArrayElementType(_O_).
386+
1. Let _targetType_ be TypedArrayElementType(_A_).
387+
1. If _srcType_ is _targetType_, then
388+
1. NOTE: The transfer must be performed in a manner that preserves the bit-level encoding of the source data.
389+
1. Let _srcBuffer_ be _O_.[[ViewedArrayBuffer]].
390+
1. Let _targetBuffer_ be _A_.[[ViewedArrayBuffer]].
391+
1. Let _elementSize_ be TypedArrayElementSize(_O_).
392+
1. Let _srcByteOffset_ be _O_.[[ByteOffset]].
393+
1. Let _srcByteIndex_ be (_startIndex_ × _elementSize_) + _srcByteOffset_.
394+
1. Let _targetByteIndex_ be _A_.[[ByteOffset]].
395+
1. Let _endByteIndex_ be _targetByteIndex_ + (_countBytes_ × _elementSize_).
396+
1. Repeat, while _targetByteIndex_ &lt; _endByteIndex_,
397+
1. Let _value_ be GetValueFromBuffer(_srcBuffer_, _srcByteIndex_, ~uint8~, *true*, ~unordered~).
398+
1. Perform SetValueInBuffer(_targetBuffer_, _targetByteIndex_, ~uint8~, _value_, *true*, ~unordered~).
399+
1. Set _srcByteIndex_ to _srcByteIndex_ + 1.
400+
1. Set _targetByteIndex_ to _targetByteIndex_ + 1.
401+
1. Else,
402+
1. Let _n_ be 0.
403+
1. Let _k_ be _startIndex_.
404+
1. Repeat, while _k_ &lt; _endIndex_,
405+
1. Let _Pk_ be ! ToString(𝔽(_k_)).
406+
1. Let _kValue_ be ! Get(_O_, _Pk_).
407+
1. Perform <del>!</del><ins>?</ins> Set(_A_, ! ToString(𝔽(_n_)), _kValue_, *true*).
408+
1. Set _k_ to _k_ + 1.
409+
1. Set _n_ to _n_ + 1.
410+
1. Return _A_.
411+
</emu-alg>
412+
<p>This method is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.</p>
413+
</emu-clause>
414+
310415
<emu-clause id="sec-%typedarray%.prototype.sort" oldids="sec-typedarraysortcompare" number="29">
311416
<h1>%TypedArray%.prototype.sort ( _comparator_ )</h1>
312417
<p>This is a distinct method that, except as described below, implements the same requirements as those of `Array.prototype.sort` as defined in <emu-xref href="#sec-array.prototype.sort"></emu-xref>. The implementation of this method may be optimized with the knowledge that the *this* value is an object that has a fixed length and whose integer-indexed properties are not sparse.</p>
@@ -336,6 +441,31 @@ contributors: Mark S. Miller, Richard Gibson
336441
<emu-clause id="sec-abstract-operations-for-typedarray-objects" number="4">
337442
<h1>Abstract Operations for TypedArray Objects</h1>
338443

444+
<emu-clause id="typedarray-species-create" type="abstract operation" number="1">
445+
<h1>
446+
TypedArraySpeciesCreate (
447+
_exemplar_: a TypedArray,
448+
_argumentList_: a List of ECMAScript language values,
449+
<ins>optional _accessMode_: ~read~ or ~write~,</ins>
450+
): either a normal completion containing a TypedArray or a throw completion
451+
</h1>
452+
<dl class="header">
453+
<dt>description</dt>
454+
<dd>It is used to specify the creation of a new TypedArray using a constructor function that is derived from _exemplar_. Unlike ArraySpeciesCreate, which can create non-Array objects through the use of %Symbol.species%, this operation enforces that the constructor function creates an actual TypedArray.</dd>
455+
</dl>
456+
<emu-alg>
457+
1. <ins>If _accessMode_ is not present, set _accessMode_ to ~read~.</ins>
458+
1. Let _defaultConstructor_ be the intrinsic object associated with the constructor name _exemplar_.[[TypedArrayName]] in <emu-xref href="#table-the-typedarray-constructors"></emu-xref>.
459+
1. Let _constructor_ be ? SpeciesConstructor(_exemplar_, _defaultConstructor_).
460+
1. Let _result_ be ? TypedArrayCreateFromConstructor(_constructor_, _argumentList_).
461+
1. <del>Assert: _result_ has [[TypedArrayName]] and [[ContentType]] internal slots.</del>
462+
1. <ins>Assert: _result_ has all of the internal slots of a <var>TypedArray</var> instance (<emu-xref href="#sec-properties-of-typedarray-instances"></emu-xref>).</ins>
463+
1. If _result_.[[ContentType]] is not _exemplar_.[[ContentType]], throw a *TypeError* exception.
464+
1. <ins>If _accessMode_ is ~write~ and IsImmutableBuffer(_result_.[[ViewedArrayBuffer]]) is *true*, throw a *TypeError* exception.</ins>
465+
1. Return _result_.
466+
</emu-alg>
467+
</emu-clause>
468+
339469
<emu-clause id="sec-validatetypedarray" type="abstract operation" number="4">
340470
<h1>
341471
ValidateTypedArray (

0 commit comments

Comments
 (0)