Skip to content

Commit

Permalink
Remove TypedArrayFrom abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
anba authored and bterlson committed Dec 28, 2015
1 parent a8cd700 commit eadbf0b
Showing 1 changed file with 34 additions and 53 deletions.
87 changes: 34 additions & 53 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -30945,28 +30945,30 @@ <h1>%TypedArray%.from ( _source_ [ , _mapfn_ [ , _thisArg_ ] ] )</h1>
<emu-alg>
1. Let _C_ be the *this* value.
1. If IsConstructor(_C_) is *false*, throw a *TypeError* exception.
1. If _mapfn_ was supplied, let _f_ be _mapfn_; otherwise let _f_ be *undefined*.
1. If _f_ is not *undefined*, then
1. If IsCallable(_f_) is *false*, throw a *TypeError* exception.
1. If _thisArg_ was supplied, let _t_ be _thisArg_; else let _t_ be *undefined*.
1. Return ? TypedArrayFrom(*undefined*, _C_, _source_, _f_, _t_).
1. If _mapfn_ was supplied and _mapfn_ is not *undefined*, then
1. If IsCallable(_mapfn_) is *false*, throw a *TypeError* exception.
1. Let _mapping_ be *true*.
1. Else, let _mapping_ be *false*.
1. If _thisArg_ was supplied, let _T_ be _thisArg_; else let _T_ be *undefined*.
1. Let _arrayLike_ be ? IterableToArrayLike(_source_).
1. Let _len_ be ? ToLength(? Get(_arrayLike_, `"length"`)).
1. Let _targetObj_ be ? TypedArrayCreate(_C_, &laquo;_len_&raquo;).
1. Let _k_ be 0.
1. Repeat, while _k_ &lt; _len_
1. Let _Pk_ be ! ToString(_k_).
1. Let _kValue_ be ? Get(_arrayLike_, _Pk_).
1. If _mapping_ is *true*, then
1. Let _mappedValue_ be ? Call(_mapfn_, _T_, &laquo; _kValue_, _k_ &raquo;).
1. Else, let _mappedValue_ be _kValue_.
1. Perform ? Set(_targetObj_, _Pk_, _mappedValue_, *true*).
1. Increase _k_ by 1.
1. Return _targetObj_.
</emu-alg>

<!-- es6num="22.2.2.1.1" -->
<emu-clause id="sec-typedarrayfrom" aoid="TypedArrayFrom">
<h1>Runtime Semantics: TypedArrayFrom( _O_, _constructor_, _items_, _mapfn_, _thisArg_ )</h1>
<p>When the TypedArrayFrom abstract operation is called with arguments _O_, _constructor_, _items_, _mapfn_, and _thisArg_, the following steps are taken:</p>
<emu-clause id="sec-iterabletoarraylike" aoid="IterableToArrayLike">
<h1>Runtime Semantics: IterableToArrayLike( _items_ )</h1>
<p>The abstract operation IterableToArrayLike performs the following steps:</p>
<emu-alg>
1. Let _C_ be _constructor_.
1. If _O_ is not *undefined*, then
1. Assert: _O_ is an Object that has a [[ViewedArrayBuffer]] internal slot.
1. Else,
1. Assert: IsConstructor(_C_) is *true*.
1. Assert: _mapfn_ is either a callable Object or *undefined*.
1. If _mapfn_ is *undefined*, let _mapping_ be *false*.
1. Else,
1. Let _T_ be _thisArg_.
1. Let _mapping_ be *true*.
1. Let _usingIterator_ be ? GetMethod(_items_, @@iterator).
1. If _usingIterator_ is not *undefined*, then
1. Let _iterator_ be ? GetIterator(_items_, _usingIterator_).
Expand All @@ -30977,39 +30979,9 @@ <h1>Runtime Semantics: TypedArrayFrom( _O_, _constructor_, _items_, _mapfn_, _th
1. If _next_ is not *false*, then
1. Let _nextValue_ be ? IteratorValue(_next_).
1. Append _nextValue_ to the end of the List _values_.
1. Let _len_ be the number of elements in _values_.
1. If _O_ is not *undefined*, then
1. Let _targetObj_ be ? AllocateTypedArrayBuffer(_O_, _len_).
1. Else,
1. Let _targetObj_ be ? TypedArrayCreate(_C_, &laquo;_len_&raquo;).
1. Let _k_ be 0.
1. Repeat, while _k_ &lt; _len_
1. Let _Pk_ be ! ToString(_k_).
1. Let _kValue_ be the first element of _values_ and remove that element from _values_.
1. If _mapping_ is *true*, then
1. Let _mappedValue_ be ? Call(_mapfn_, _T_, &laquo; _kValue_, _k_ &raquo;).
1. Else, let _mappedValue_ be _kValue_.
1. Perform ? Set(_targetObj_, _Pk_, _mappedValue_, *true*).
1. Increase _k_ by 1.
1. Assert: _values_ is now an empty List.
1. Return _targetObj_.
1. Assert: _items_ is not an Iterable so assume it is an array-like object.
1. Let _arrayLike_ be ? ToObject(_items_).
1. Let _len_ be ? ToLength(? Get(_arrayLike_, `"length"`)).
1. If _O_ is not *undefined*, then
1. Let _targetObj_ be ? AllocateTypedArrayBuffer(_O_, _len_).
1. Else,
1. Let _targetObj_ be ? TypedArrayCreate(_C_, &laquo;_len_&raquo;).
1. Let _k_ be 0.
1. Repeat, while _k_ &lt; _len_
1. Let _Pk_ be ! ToString(_k_).
1. Let _kValue_ be ? Get(_arrayLike_, _Pk_).
1. If _mapping_ is *true*, then
1. Let _mappedValue_ be ? Call(_mapfn_, _T_, &laquo; _kValue_, _k_ &raquo;).
1. Else, let _mappedValue_ be _kValue_.
1. Perform ? Set(_targetObj_, _Pk_, _mappedValue_, *true*).
1. Increase _k_ by 1.
1. Return _targetObj_.
1. Return CreateArrayFromList(_values_).
1. Assert: _items_ is not an Iterable so assume it is already an array-like object.
1. Return ? ToObject(_items_).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -31702,7 +31674,16 @@ <h1>_TypedArray_ ( _object_ )</h1>
1. Assert: Type(_object_) is Object and _object_ does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] internal slot.
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. Let _O_ be ? AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, <code>"%<var>TypedArray</var>Prototype%"</code>).
1. Return ? TypedArrayFrom(_O_, *undefined*, _object_, *undefined*, *undefined*).
1. Let _arrayLike_ be ? IterableToArrayLike(_object_).
1. Let _len_ be ? ToLength(? Get(_arrayLike_, `"length"`)).
1. Perform ? AllocateTypedArrayBuffer(_O_, _len_).
1. Let _k_ be 0.
1. Repeat, while _k_ &lt; _len_
1. Let _Pk_ be ! ToString(_k_).
1. Let _kValue_ be ? Get(_arrayLike_, _Pk_).
1. Perform ? Set(_O_, _Pk_, _kValue_, *true*).
1. Increase _k_ by 1.
1. Return _O_.
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit eadbf0b

Please sign in to comment.