- <emu-alg><ol><li>Let <var>iterables</var> be a new empty <emu-xref href="#sec-list-and-record-specification-type"><a href="https://tc39.es/ecma262/#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>For each element <var>item</var> of <var>items</var>, do<ol><li>If <var>item</var> <emu-xref href="#sec-object-type"><a href="https://tc39.es/ecma262/#sec-object-type">is not an Object</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>method</var> be ? <emu-xref aoid="GetMethod"><a href="https://tc39.es/ecma262/#sec-getmethod" class="e-user-code">GetMethod</a></emu-xref>(<var>item</var>, <emu-xref href="#sec-well-known-symbols"><a href="https://tc39.es/ecma262/#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref>).</li><li>If <var>method</var> is <emu-val>undefined</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Append the <emu-xref href="#sec-list-and-record-specification-type"><a href="https://tc39.es/ecma262/#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[OpenMethod]]</var>: <var>method</var>, <var class="field">[[Iterable]]</var>: <var>item</var> } to <var>iterables</var>.</li></ol></li><li>Let <var>closure</var> be a new <emu-xref href="#sec-abstract-closure"><a href="https://tc39.es/ecma262/#sec-abstract-closure">Abstract Closure</a></emu-xref> with no parameters that captures <var>iterables</var> and performs the following steps when called:<ol><li>For each <emu-xref href="#sec-list-and-record-specification-type"><a href="https://tc39.es/ecma262/#sec-list-and-record-specification-type">Record</a></emu-xref> <var>iterable</var> of <var>iterables</var>, do<ol><li>Let <var>iter</var> be ? <emu-xref aoid="Call"><a href="https://tc39.es/ecma262/#sec-call" class="e-user-code">Call</a></emu-xref>(<var>iterable</var>.<var class="field">[[OpenMethod]]</var>, <var>iterable</var>.<var class="field">[[Iterable]]</var>).</li><li>If <var>iter</var> <emu-xref href="#sec-object-type"><a href="https://tc39.es/ecma262/#sec-object-type">is not an Object</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>iteratorRecord</var> be ? <emu-xref aoid="GetIteratorDirect"><a href="https://tc39.es/proposal-iterator-helpers#sec-getiteratordirect" class="e-user-code">GetIteratorDirect</a></emu-xref>(<var>iter</var>).</li><li>Let <var>innerAlive</var> be <emu-val>true</emu-val>.</li><li>Repeat, while <var>innerAlive</var> is <emu-val>true</emu-val>,<ol><li>Let <var>iteratorResult</var> be ? <emu-xref aoid="IteratorNext"><a href="https://tc39.es/ecma262/#sec-iteratornext" class="e-user-code">IteratorNext</a></emu-xref>(<var>iteratorRecord</var>).</li><li>Let <var>done</var> be <emu-xref aoid="Completion"><a href="https://tc39.es/ecma262/#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="IteratorComplete"><a href="https://tc39.es/ecma262/#sec-iteratorcomplete" class="e-user-code">IteratorComplete</a></emu-xref>(<var>iteratorResult</var>)).</li><li>If <var>done</var> is a <emu-xref href="#sec-completion-record-specification-type"><a href="https://tc39.es/ecma262/#sec-completion-record-specification-type">throw completion</a></emu-xref>, then<ol><li>Set <var>iteratorRecord</var>.<var class="field">[[Done]]</var> to <emu-val>true</emu-val>.</li><li>Return ? <var>done</var>.</li></ol></li><li>Set <var>done</var> to ! <var>done</var>.</li><li>If <var>done</var> is <emu-val>true</emu-val>, then<ol><li>Set <var>iteratorRecord</var>.<var class="field">[[Done]]</var> to <emu-val>true</emu-val>.</li><li>Perform ? <emu-xref aoid="IteratorValue"><a href="https://tc39.es/ecma262/#sec-iteratorvalue" class="e-user-code">IteratorValue</a></emu-xref>(<var>iteratorResult</var>).</li><li>Set <var>innerAlive</var> to <emu-val>false</emu-val>.</li></ol></li><li>Else,<ol><li>Let <var>completion</var> be <emu-xref aoid="Completion"><a href="https://tc39.es/ecma262/#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="GeneratorYield"><a href="https://tc39.es/ecma262/#sec-generatoryield">GeneratorYield</a></emu-xref>(<var>iteratorResult</var>)).</li><li>If <var>completion</var> is an <emu-xref href="#sec-completion-record-specification-type"><a href="https://tc39.es/ecma262/#sec-completion-record-specification-type">abrupt completion</a></emu-xref>, then<ol><li>Return ? <emu-xref aoid="IteratorClose"><a href="https://tc39.es/ecma262/#sec-iteratorclose" class="e-user-code">IteratorClose</a></emu-xref>(<var>iteratorRecord</var>, <var>completion</var>).</li></ol></li></ol></li></ol></li></ol></li><li>Return <emu-xref aoid="ReturnCompletion"><a href="https://tc39.es/ecma262/#sec-returncompletion">ReturnCompletion</a></emu-xref>(<emu-val>undefined</emu-val>).</li></ol></li><li>Let <var>gen</var> be <emu-xref aoid="CreateIteratorFromClosure"><a href="https://tc39.es/proposal-iterator-helpers#sec-createiteratorfromclosure">CreateIteratorFromClosure</a></emu-xref>(<var>closure</var>, <emu-val>"Iterator Helper"</emu-val>, <emu-xref href="#sec-%iteratorhelperprototype%-object"><a href="https://tc39.es/proposal-iterator-helpers#sec-%iteratorhelperprototype%-object">%IteratorHelperPrototype%</a></emu-xref>, « <var class="field">[[UnderlyingIterators]]</var> »).</li><li>Set <var>gen</var>.<var class="field">[[UnderlyingIterators]]</var> to a new empty <emu-xref href="#sec-list-and-record-specification-type"><a href="https://tc39.es/ecma262/#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>Return <var>gen</var>.</li></ol></emu-alg>
0 commit comments