-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't recurse in typed array constructor #269
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30961,7 +30961,7 @@ <h1>%TypedArray%()</h1> | |
1. Let _super_ be ? _here_.[[GetPrototypeOf]](). | ||
1. If IsConstructor (_super_) is *false*, throw a *TypeError* exception. | ||
1. Let _argumentsList_ be the _argumentsList_ argument of the [[Construct]] internal method that invoked the active function. | ||
1. Return Construct(_super_, _argumentsList_, NewTarget). | ||
1. Return ? Construct(_super_, _argumentsList_, NewTarget). | ||
</emu-alg> | ||
</emu-clause> | ||
</emu-clause> | ||
|
@@ -30980,25 +30980,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(_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_, «_len_»). | ||
1. Let _k_ be 0. | ||
1. Repeat, while _k_ < _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_, « _kValue_, _k_ »). | ||
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( _constructor_, _items_, _mapfn_, _thisArg_ )</h1> | ||
<p>When the TypedArrayFrom abstract operation is called with arguments _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. 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_). | ||
|
@@ -31009,33 +31014,9 @@ <h1>Runtime Semantics: TypedArrayFrom( _constructor_, _items_, _mapfn_, _thisArg | |
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. Let _targetObj_ be ? TypedArrayCreate(_C_, «_len_»). | ||
1. Let _k_ be 0. | ||
1. Repeat, while _k_ < _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_, « _kValue_, _k_ »). | ||
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. Let _targetObj_ be ? TypedArrayCreate(_C_, «_len_»). | ||
1. Let _k_ be 0. | ||
1. Repeat, while _k_ < _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_, « _kValue_, _k_ »). | ||
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_). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth factoring this out into another TypedArrayCreate-like AO. |
||
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> | ||
|
@@ -31545,7 +31526,7 @@ <h1>%TypedArray%.prototype.subarray( [ _begin_ [ , _end_ ] ] )</h1> | |
1. Let _srcByteOffset_ be the value of _O_'s [[ByteOffset]] internal slot. | ||
1. Let _beginByteOffset_ be _srcByteOffset_ + _beginIndex_ × _elementSize_. | ||
1. Let _argumentsList_ be «_buffer_, _beginByteOffset_, _newLength_». | ||
1. Return TypedArraySpeciesCreate(_O_, _argumentsList_). | ||
1. Return ? TypedArraySpeciesCreate(_O_, _argumentsList_). | ||
</emu-alg> | ||
<p>The `length` property of the `subarray` method is 2.</p> | ||
<p>This function is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.</p> | ||
|
@@ -31615,7 +31596,7 @@ <h1>_TypedArray_ ( )</h1> | |
<p>This description applies only if the _TypedArray_ function is called with no arguments.</p> | ||
<emu-alg> | ||
1. If NewTarget is *undefined*, throw a *TypeError* exception. | ||
1. Return AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, %<var>TypedArray</var>Prototype%, 0). | ||
1. Return ? AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, <code>"%<var>TypedArray</var>Prototype%"</code>, 0). | ||
</emu-alg> | ||
</emu-clause> | ||
|
||
|
@@ -31631,15 +31612,15 @@ <h1>_TypedArray_ ( _length_ )</h1> | |
1. Let _numberLength_ be ToNumber(_length_). | ||
1. Let _elementLength_ be ? ToLength(_numberLength_). | ||
1. If SameValueZero(_numberLength_, _elementLength_) is *false*, throw a *RangeError* exception. | ||
1. Return AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, %<var>TypedArray</var>Prototype%, _elementLength_). | ||
1. Return ? AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, <code>"%<var>TypedArray</var>Prototype%"</code>, _elementLength_). | ||
</emu-alg> | ||
|
||
<!-- es6num="22.2.1.2.1" --> | ||
<emu-clause id="sec-allocatetypedarray" aoid="AllocateTypedArray"> | ||
<h1>Runtime Semantics: AllocateTypedArray (_constructorName_, _newTarget_, _defaultProto_, _length_ )</h1> | ||
<p>The abstract operation AllocateTypedArray with arguments _constructorName_, _newTarget_, _defaultProto_ and optional argument _length_ is used to validate and create an instance of a TypedArray constructor. _constructorName_ is required to be the name of a TypedArray in <emu-xref href="#table-49"></emu-xref>. If the _length_ argument is passed an ArrayBuffer of that length is also allocated and associated with the new TypedArray instance. AllocateTypedArray provides common semantics that is used by all of the _TypeArray_ overloads and other methods. AllocateTypedArray performs the following steps:</p> | ||
<p>The abstract operation AllocateTypedArray with arguments _constructorName_, _newTarget_, _defaultProto_ and optional argument _length_ is used to validate and create an instance of a TypedArray constructor. _constructorName_ is required to be the name of a TypedArray constructor in <emu-xref href="#table-49"></emu-xref>. If the _length_ argument is passed an ArrayBuffer of that length is also allocated and associated with the new TypedArray instance. AllocateTypedArray provides common semantics that is used by all of the _TypedArray_ overloads. AllocateTypedArray performs the following steps:</p> | ||
<emu-alg> | ||
1. Let _proto_ be GetPrototypeFromConstructor(_newTarget_, _defaultProto_). | ||
1. Let _proto_ be ? GetPrototypeFromConstructor(_newTarget_, _defaultProto_). | ||
1. Let _obj_ be IntegerIndexedObjectCreate (_proto_, «[[ViewedArrayBuffer]], [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). | ||
1. Assert: The [[ViewedArrayBuffer]] internal slot of _obj_ is *undefined*. | ||
1. Set _obj_'s [[TypedArrayName]] internal slot to _constructorName_. | ||
|
@@ -31648,16 +31629,29 @@ <h1>Runtime Semantics: AllocateTypedArray (_constructorName_, _newTarget_, _defa | |
1. Set _obj_'s [[ByteOffset]] internal slot to 0. | ||
1. Set _obj_'s [[ArrayLength]] internal slot to 0. | ||
1. Else, | ||
1. Let _elementSize_ be the Element Size value in <emu-xref href="#table-49"></emu-xref> for _constructorName_. | ||
1. Let _byteLength_ be _elementSize_ × _length_. | ||
1. Let _data_ be ? AllocateArrayBuffer(%ArrayBuffer%, _byteLength_). | ||
1. Set _obj_'s [[ViewedArrayBuffer]] internal slot to _data_. | ||
1. Set _obj_'s [[ByteLength]] internal slot to _byteLength_. | ||
1. Set _obj_'s [[ByteOffset]] internal slot to 0. | ||
1. Set _obj_'s [[ArrayLength]] internal slot to _length_. | ||
1. Perform ? AllocateTypedArrayBuffer(_obj_, _length_). | ||
1. Return _obj_. | ||
</emu-alg> | ||
</emu-clause> | ||
|
||
<emu-clause id="sec-allocatetypedarraybuffer" aoid="AllocateTypedArrayBuffer"> | ||
<h1>Runtime Semantics: AllocateTypedArrayBuffer ( _O_, _length_ )</h1> | ||
<p>The abstract operation AllocateTypedArrayBuffer with arguments _O_ and _length_ allocates and associates an ArrayBuffer with the TypedArray instance _O_. It performs the following steps:</p> | ||
<emu-alg> | ||
1. Assert: _O_ is an Object that has a [[ViewedArrayBuffer]] internal slot. | ||
1. Assert: The [[ViewedArrayBuffer]] internal slot of _O_ is *undefined*. | ||
1. Assert: _length_ ≥ 0. | ||
1. Let _constructorName_ be the String value of _O_'s [[TypedArrayName]] internal slot. | ||
1. Let _elementSize_ be the Element Size value in <emu-xref href="#table-49"></emu-xref> for _constructorName_. | ||
1. Let _byteLength_ be _elementSize_ × _length_. | ||
1. Let _data_ be ? AllocateArrayBuffer(%ArrayBuffer%, _byteLength_). | ||
1. Set _O_'s [[ViewedArrayBuffer]] internal slot to _data_. | ||
1. Set _O_'s [[ByteLength]] internal slot to _byteLength_. | ||
1. Set _O_'s [[ByteOffset]] internal slot to 0. | ||
1. Set _O_'s [[ArrayLength]] internal slot to _length_. | ||
1. Return _O_. | ||
</emu-alg> | ||
</emu-clause> | ||
</emu-clause> | ||
|
||
<!-- es6num="22.2.1.3" --> | ||
|
@@ -31668,7 +31662,7 @@ <h1>_TypedArray_ ( _typedArray_ )</h1> | |
<emu-alg> | ||
1. Assert: Type(_typedArray_) is Object and _typedArray_ has a [[TypedArrayName]] internal slot. | ||
1. If NewTarget is *undefined*, throw a *TypeError* exception. | ||
1. Let _O_ be ? AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, %<var>TypedArray</var>Prototype%). | ||
1. Let _O_ be ? AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, <code>"%<var>TypedArray</var>Prototype%"</code>). | ||
1. Let _srcArray_ be _typedArray_. | ||
1. Let _srcData_ be the value of _srcArray_'s [[ViewedArrayBuffer]] internal slot. | ||
1. If IsDetachedBuffer(_srcData_) is *true*, throw a *TypeError* exception. | ||
|
@@ -31712,7 +31706,17 @@ <h1>_TypedArray_ ( _object_ )</h1> | |
<emu-alg> | ||
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. Return TypedArrayFrom(NewTarget, _object_, *undefined*, *undefined*). | ||
1. Let _O_ be ? AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, <code>"%<var>TypedArray</var>Prototype%"</code>). | ||
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_ < _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> | ||
|
||
|
@@ -31724,7 +31728,7 @@ <h1>_TypedArray_ ( _buffer_ [ , _byteOffset_ [ , _length_ ] ] )</h1> | |
<emu-alg> | ||
1. Assert: Type(_buffer_) is Object and _buffer_ has an [[ArrayBufferData]] internal slot. | ||
1. If NewTarget is *undefined*, throw a *TypeError* exception. | ||
1. Let _O_ be ? AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, %<var>TypedArray</var>Prototype%). | ||
1. Let _O_ be ? AllocateTypedArray(_TypedArray_.[[TypedArrayConstructorName]], NewTarget, <code>"%<var>TypedArray</var>Prototype%"</code>). | ||
1. Let _constructorName_ be the String value of _O_'s [[TypedArrayName]] internal slot. | ||
1. Let _elementSize_ be the Number value of the Element Size value in <emu-xref href="#table-49"></emu-xref> for _constructorName_. | ||
1. Let _offset_ be ? ToInteger(_byteOffset_). | ||
|
@@ -31749,8 +31753,9 @@ <h1>_TypedArray_ ( _buffer_ [ , _byteOffset_ [ , _length_ ] ] )</h1> | |
</emu-alg> | ||
</emu-clause> | ||
|
||
<emu-clause id="typedarray-create"> | ||
<emu-clause id="typedarray-create" aoid="TypedArrayCreate"> | ||
<h1>TypedArrayCreate( _constructor_, _argumentList_ )</h1> | ||
<p>The abstract operation TypedArrayCreate with arguments _constructor_ and _argumentList_ is used to specify the creation of a new TypedArray object using a constructor function. It performs the following steps:</p> | ||
<emu-alg> | ||
1. Let _newTypedArray_ be ? Construct(_constructor_, _argumentList_). | ||
1. Perform ? ValidateTypedArray(_newTypedArray_). | ||
|
@@ -31760,10 +31765,11 @@ <h1>TypedArrayCreate( _constructor_, _argumentList_ )</h1> | |
</emu-alg> | ||
</emu-clause> | ||
|
||
<emu-clause id="typedarray-species-create"> | ||
<emu-clause id="typedarray-species-create" aoid="TypedArraySpeciesCreate"> | ||
<h1>TypedArraySpeciesCreate( _exemplar_, _argumentList_ )</h1> | ||
<p>The abstract operation TypedArraySpeciesCreate with arguments _exemplar_ and _argumentList_ is used to specify the creation of a new TypedArray object using a constructor function that is derived from _exemplar_. It performs the following steps:</p> | ||
<emu-alg> | ||
1. Assert: _exemplar_ has a [[TypedArrayName]] internal slot. | ||
1. Assert: _exemplar_ is an Object that has a [[TypedArrayName]] internal slot. | ||
1. Let _defaultConstructor_ be the intrinsic object listed in column one of <emu-xref href="#table-49"></emu-xref> for the value of _exemplar_'s [[TypedArrayName]] internal slot. | ||
1. Let _constructor_ be ? SpeciesConstructor(_exemplar_, _defaultConstructor_). | ||
1. Return ? TypedArrayCreate(_constructor_, _argumentList_). | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature of this AO is a bit strange now, since you either pass the first argument or the second. Is there some refactoring that needs to be done to clean this up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just reintroduced the strangeness. 😛
(A similar signature was present in ES6 rev24-rev30, except the O and constructor parameters are switched now.)
Let me think about this a bit, maybe it can be improved...