Skip to content
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

Editorial: Clarify GetIterator #3021

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 52 additions & 44 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -6797,26 +6797,16 @@ <h1>Iterator Records</h1>
</emu-table>
</emu-clause>

<emu-clause id="sec-getiterator" type="abstract operation">
<emu-clause id="sec-getiteratorfrommethod" type="abstract operation">
<h1>
GetIterator (
GetIteratorFromMethod (
_obj_: an ECMAScript language value,
optional _hint_: ~sync~ or ~async~,
optional _method_: a function object,
_method_: a function object,
): either a normal completion containing an Iterator Record or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _hint_ is not present, set _hint_ to ~sync~.
1. If _method_ is not present, then
1. If _hint_ is ~async~, then
1. Set _method_ to ? GetMethod(_obj_, @@asyncIterator).
1. If _method_ is *undefined*, then
1. Let _syncMethod_ be ? GetMethod(_obj_, @@iterator).
1. Let _syncIteratorRecord_ be ? GetIterator(_obj_, ~sync~, _syncMethod_).
1. Return CreateAsyncFromSyncIterator(_syncIteratorRecord_).
1. Otherwise, set _method_ to ? GetMethod(_obj_, @@iterator).
1. Let _iterator_ be ? Call(_method_, _obj_).
1. If _iterator_ is not an Object, throw a *TypeError* exception.
1. Let _nextMethod_ be ? GetV(_iterator_, *"next"*).
Expand All @@ -6825,6 +6815,29 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-getiterator" type="abstract operation">
<h1>
GetIterator (
_obj_: an ECMAScript language value,
_kind_: ~sync~ or ~async~,
): either a normal completion containing an Iterator Record or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _kind_ is ~async~, then
1. Let _method_ be ? GetMethod(_obj_, @@asyncIterator).
1. If _method_ is *undefined*, then
1. Let _syncMethod_ be ? GetMethod(_obj_, @@iterator).
1. If _syncMethod_ is *undefined*, throw a *TypeError* exception.
1. Let _syncIteratorRecord_ be ? GetIteratorFromMethod(_obj_, _syncMethod_).
1. Return CreateAsyncFromSyncIterator(_syncIteratorRecord_).
1. Otherwise, let _method_ be ? GetMethod(_obj_, @@iterator).
1. If _method_ is *undefined*, throw a *TypeError* exception.
1. Return ? GetIteratorFromMethod(_obj_, _method_).
</emu-alg>
</emu-clause>

<emu-clause id="sec-iteratornext" type="abstract operation">
<h1>
IteratorNext (
Expand Down Expand Up @@ -6997,20 +7010,15 @@ <h1>
</emu-note>
</emu-clause>

<emu-clause id="sec-iterabletolist" type="abstract operation">
<emu-clause id="sec-iteratortolist" oldids="sec-iterabletolist" type="abstract operation">
syg marked this conversation as resolved.
Show resolved Hide resolved
<h1>
IterableToList (
_items_: an ECMAScript language value,
optional _method_: a function object,
IteratorToList (
_iteratorRecord_: an Iterator Record,
): either a normal completion containing a List of ECMAScript language values or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _method_ is present, then
1. Let _iteratorRecord_ be ? GetIterator(_items_, ~sync~, _method_).
1. Else,
1. Let _iteratorRecord_ be ? GetIterator(_items_, ~sync~).
1. Let _values_ be a new empty List.
1. Let _next_ be *true*.
1. Repeat, while _next_ is not *false*,
Expand Down Expand Up @@ -9351,7 +9359,7 @@ <h1>
</emu-alg>
<emu-grammar>BindingPattern : ArrayBindingPattern</emu-grammar>
<emu-alg>
1. Let _iteratorRecord_ be ? GetIterator(_value_).
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
1. Let _result_ be Completion(IteratorBindingInitialization of |ArrayBindingPattern| with arguments _iteratorRecord_ and _environment_).
1. If _iteratorRecord_.[[Done]] is *false*, return ? IteratorClose(_iteratorRecord_, _result_).
1. Return ? _result_.
Expand Down Expand Up @@ -18046,7 +18054,7 @@ <h1>
<emu-alg>
1. Let _spreadRef_ be ? Evaluation of |AssignmentExpression|.
1. Let _spreadObj_ be ? GetValue(_spreadRef_).
1. Let _iteratorRecord_ be ? GetIterator(_spreadObj_).
1. Let _iteratorRecord_ be ? GetIterator(_spreadObj_, ~sync~).
1. Repeat,
1. Let _next_ be ? IteratorStep(_iteratorRecord_).
1. If _next_ is *false*, return _nextIndex_.
Expand Down Expand Up @@ -19087,7 +19095,7 @@ <h1>Runtime Semantics: ArgumentListEvaluation ( ): either a normal completion co
1. Let _list_ be a new empty List.
1. Let _spreadRef_ be ? Evaluation of |AssignmentExpression|.
1. Let _spreadObj_ be ? GetValue(_spreadRef_).
1. Let _iteratorRecord_ be ? GetIterator(_spreadObj_).
1. Let _iteratorRecord_ be ? GetIterator(_spreadObj_, ~sync~).
1. Repeat,
1. Let _next_ be ? IteratorStep(_iteratorRecord_).
1. If _next_ is *false*, return _list_.
Expand All @@ -19105,7 +19113,7 @@ <h1>Runtime Semantics: ArgumentListEvaluation ( ): either a normal completion co
<emu-alg>
1. Let _precedingArgs_ be ? ArgumentListEvaluation of |ArgumentList|.
1. Let _spreadRef_ be ? Evaluation of |AssignmentExpression|.
1. Let _iteratorRecord_ be ? GetIterator(? GetValue(_spreadRef_)).
1. Let _iteratorRecord_ be ? GetIterator(? GetValue(_spreadRef_), ~sync~).
1. Repeat,
1. Let _next_ be ? IteratorStep(_iteratorRecord_).
1. If _next_ is *false*, return _precedingArgs_.
Expand Down Expand Up @@ -20529,19 +20537,19 @@ <h1>
</emu-alg>
<emu-grammar>ArrayAssignmentPattern : `[` `]`</emu-grammar>
<emu-alg>
1. Let _iteratorRecord_ be ? GetIterator(_value_).
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
1. Return ? IteratorClose(_iteratorRecord_, NormalCompletion(~unused~)).
</emu-alg>
<emu-grammar>ArrayAssignmentPattern : `[` Elision `]`</emu-grammar>
<emu-alg>
1. Let _iteratorRecord_ be ? GetIterator(_value_).
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
1. Let _result_ be Completion(IteratorDestructuringAssignmentEvaluation of |Elision| with argument _iteratorRecord_).
1. If _iteratorRecord_.[[Done]] is *false*, return ? IteratorClose(_iteratorRecord_, _result_).
1. Return _result_.
</emu-alg>
<emu-grammar>ArrayAssignmentPattern : `[` Elision? AssignmentRestElement `]`</emu-grammar>
<emu-alg>
1. Let _iteratorRecord_ be ? GetIterator(_value_).
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
1. If |Elision| is present, then
1. Let _status_ be Completion(IteratorDestructuringAssignmentEvaluation of |Elision| with argument _iteratorRecord_).
1. If _status_ is an abrupt completion, then
Expand All @@ -20553,14 +20561,14 @@ <h1>
</emu-alg>
<emu-grammar>ArrayAssignmentPattern : `[` AssignmentElementList `]`</emu-grammar>
<emu-alg>
1. Let _iteratorRecord_ be ? GetIterator(_value_).
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
1. Let _result_ be Completion(IteratorDestructuringAssignmentEvaluation of |AssignmentElementList| with argument _iteratorRecord_).
1. If _iteratorRecord_.[[Done]] is *false*, return ? IteratorClose(_iteratorRecord_, _result_).
1. Return _result_.
</emu-alg>
<emu-grammar>ArrayAssignmentPattern : `[` AssignmentElementList `,` Elision? AssignmentRestElement? `]`</emu-grammar>
<emu-alg>
1. Let _iteratorRecord_ be ? GetIterator(_value_).
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
1. Let _status_ be Completion(IteratorDestructuringAssignmentEvaluation of |AssignmentElementList| with argument _iteratorRecord_).
1. If _status_ is an abrupt completion, then
1. If _iteratorRecord_.[[Done]] is *false*, return ? IteratorClose(_iteratorRecord_, _status_).
Expand Down Expand Up @@ -21891,9 +21899,9 @@ <h1>
1. Return the Iterator Record { [[Iterator]]: _iterator_, [[NextMethod]]: _nextMethod_, [[Done]]: *false* }.
1. Else,
1. Assert: _iterationKind_ is either ~iterate~ or ~async-iterate~.
1. If _iterationKind_ is ~async-iterate~, let _iteratorHint_ be ~async~.
1. Else, let _iteratorHint_ be ~sync~.
1. Return ? GetIterator(_exprValue_, _iteratorHint_).
1. If _iterationKind_ is ~async-iterate~, let _iteratorKind_ be ~async~.
1. Else, let _iteratorKind_ be ~sync~.
1. Return ? GetIterator(_exprValue_, _iteratorKind_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -30778,7 +30786,7 @@ <h1>AggregateError ( _errors_, _message_ [ , _options_ ] )</h1>
1. Let _msg_ be ? ToString(_message_).
1. Perform CreateNonEnumerableDataPropertyOrThrow(_O_, *"message"*, _msg_).
1. Perform ? InstallErrorCause(_O_, _options_).
1. Let _errorsList_ be ? IterableToList(_errors_).
1. Let _errorsList_ be ? IteratorToList(? GetIterator(_errors_, ~sync~)).
1. Perform ! DefinePropertyOrThrow(_O_, *"errors"*, PropertyDescriptor { [[Configurable]]: *true*, [[Enumerable]]: *false*, [[Writable]]: *true*, [[Value]]: CreateArrayFromList(_errorsList_) }).
1. Return _O_.
</emu-alg>
Expand Down Expand Up @@ -37258,7 +37266,7 @@ <h1>Array.from ( _items_ [ , _mapfn_ [ , _thisArg_ ] ] )</h1>
1. Let _A_ be ? Construct(_C_).
1. Else,
1. Let _A_ be ! ArrayCreate(0).
1. Let _iteratorRecord_ be ? GetIterator(_items_, ~sync~, _usingIterator_).
1. Let _iteratorRecord_ be ? GetIteratorFromMethod(_items_, _usingIterator_).
1. Let _k_ be 0.
1. Repeat,
1. If _k_ ≥ 2<sup>53</sup> - 1, then
Expand Down Expand Up @@ -39011,7 +39019,7 @@ <h1>%TypedArray%.from ( _source_ [ , _mapfn_ [ , _thisArg_ ] ] )</h1>
1. Let _mapping_ be *true*.
1. Let _usingIterator_ be ? GetMethod(_source_, @@iterator).
1. If _usingIterator_ is not *undefined*, then
1. Let _values_ be ? IterableToList(_source_, _usingIterator_).
1. Let _values_ be ? IteratorToList(? GetIteratorFromMethod(_source_, _usingIterator_)).
1. Let _len_ be the number of elements in _values_.
1. Let _targetObj_ be ? TypedArrayCreate(_C_, « 𝔽(_len_) »).
1. Let _k_ be 0.
Expand Down Expand Up @@ -40102,7 +40110,7 @@ <h1>_TypedArray_ ( ..._args_ )</h1>
1. Assert: _firstArgument_ is an Object and _firstArgument_ does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] internal slot.
1. Let _usingIterator_ be ? GetMethod(_firstArgument_, @@iterator).
1. If _usingIterator_ is not *undefined*, then
1. Let _values_ be ? IterableToList(_firstArgument_, _usingIterator_).
1. Let _values_ be ? IteratorToList(? GetIteratorFromMethod(_firstArgument_, _usingIterator_)).
1. Perform ? InitializeTypedArrayFromList(_O_, _values_).
1. Else,
1. NOTE: _firstArgument_ is not an Iterable so assume it is already an array-like object.
Expand Down Expand Up @@ -40390,7 +40398,7 @@ <h1>
<dd>_adder_ will be invoked, with _target_ as the receiver.</dd>
</dl>
<emu-alg>
1. Let _iteratorRecord_ be ? GetIterator(_iterable_).
1. Let _iteratorRecord_ be ? GetIterator(_iterable_, ~sync~).
1. Repeat,
1. Let _next_ be ? IteratorStep(_iteratorRecord_).
1. If _next_ is *false*, return _target_.
Expand Down Expand Up @@ -40702,7 +40710,7 @@ <h1>Set ( [ _iterable_ ] )</h1>
1. If _iterable_ is either *undefined* or *null*, return _set_.
1. Let _adder_ be ? Get(_set_, *"add"*).
1. If IsCallable(_adder_) is *false*, throw a *TypeError* exception.
1. Let _iteratorRecord_ be ? GetIterator(_iterable_).
1. Let _iteratorRecord_ be ? GetIterator(_iterable_, ~sync~).
1. Repeat,
1. Let _next_ be ? IteratorStep(_iteratorRecord_).
1. If _next_ is *false*, return _set_.
Expand Down Expand Up @@ -41141,7 +41149,7 @@ <h1>WeakSet ( [ _iterable_ ] )</h1>
1. If _iterable_ is either *undefined* or *null*, return _set_.
1. Let _adder_ be ? Get(_set_, *"add"*).
1. If IsCallable(_adder_) is *false*, throw a *TypeError* exception.
1. Let _iteratorRecord_ be ? GetIterator(_iterable_).
1. Let _iteratorRecord_ be ? GetIterator(_iterable_, ~sync~).
1. Repeat,
1. Let _next_ be ? IteratorStep(_iteratorRecord_).
1. If _next_ is *false*, return _set_.
Expand Down Expand Up @@ -44493,7 +44501,7 @@ <h1>Promise.all ( _iterable_ )</h1>
1. Let _promiseCapability_ be ? NewPromiseCapability(_C_).
1. Let _promiseResolve_ be Completion(GetPromiseResolve(_C_)).
1. IfAbruptRejectPromise(_promiseResolve_, _promiseCapability_).
1. Let _iteratorRecord_ be Completion(GetIterator(_iterable_)).
1. Let _iteratorRecord_ be Completion(GetIterator(_iterable_, ~sync~)).
1. IfAbruptRejectPromise(_iteratorRecord_, _promiseCapability_).
1. Let _result_ be Completion(PerformPromiseAll(_iteratorRecord_, _C_, _promiseCapability_, _promiseResolve_)).
1. If _result_ is an abrupt completion, then
Expand Down Expand Up @@ -44596,7 +44604,7 @@ <h1>Promise.allSettled ( _iterable_ )</h1>
1. Let _promiseCapability_ be ? NewPromiseCapability(_C_).
1. Let _promiseResolve_ be Completion(GetPromiseResolve(_C_)).
1. IfAbruptRejectPromise(_promiseResolve_, _promiseCapability_).
1. Let _iteratorRecord_ be Completion(GetIterator(_iterable_)).
1. Let _iteratorRecord_ be Completion(GetIterator(_iterable_, ~sync~)).
1. IfAbruptRejectPromise(_iteratorRecord_, _promiseCapability_).
1. Let _result_ be Completion(PerformPromiseAllSettled(_iteratorRecord_, _C_, _promiseCapability_, _promiseResolve_)).
1. If _result_ is an abrupt completion, then
Expand Down Expand Up @@ -44723,7 +44731,7 @@ <h1>Promise.any ( _iterable_ )</h1>
1. Let _promiseCapability_ be ? NewPromiseCapability(_C_).
1. Let _promiseResolve_ be Completion(GetPromiseResolve(_C_)).
1. IfAbruptRejectPromise(_promiseResolve_, _promiseCapability_).
1. Let _iteratorRecord_ be Completion(GetIterator(_iterable_)).
1. Let _iteratorRecord_ be Completion(GetIterator(_iterable_, ~sync~)).
1. IfAbruptRejectPromise(_iteratorRecord_, _promiseCapability_).
1. Let _result_ be Completion(PerformPromiseAny(_iteratorRecord_, _C_, _promiseCapability_, _promiseResolve_)).
1. If _result_ is an abrupt completion, then
Expand Down Expand Up @@ -44819,7 +44827,7 @@ <h1>Promise.race ( _iterable_ )</h1>
1. Let _promiseCapability_ be ? NewPromiseCapability(_C_).
1. Let _promiseResolve_ be Completion(GetPromiseResolve(_C_)).
1. IfAbruptRejectPromise(_promiseResolve_, _promiseCapability_).
1. Let _iteratorRecord_ be Completion(GetIterator(_iterable_)).
1. Let _iteratorRecord_ be Completion(GetIterator(_iterable_, ~sync~)).
1. IfAbruptRejectPromise(_iteratorRecord_, _promiseCapability_).
1. Let _result_ be Completion(PerformPromiseRace(_iteratorRecord_, _C_, _promiseCapability_, _promiseResolve_)).
1. If _result_ is an abrupt completion, then
Expand Down