- <emu-alg><ol><li>Let <var>iteratorRecords</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>iteratorRecords</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>iteratorRecords</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>desc</var> of <var>iteratorRecords</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>desc</var>.<var class="field">[[OpenMethod]]</var>, <var>desc</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>innerValue</var> be ? <emu-xref aoid="IteratorStepValue"><a href="https://tc39.es/ecma262/#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>iteratorRecord</var>).</li><li>If <var>innerValue</var> is <emu-const>done</emu-const>, then<ol><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="Yield"><a href="https://tc39.es/ecma262/#sec-yield" class="e-user-code">Yield</a></emu-xref>(<var>innerValue</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>Return <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>, « »).</li></ol></emu-alg>
0 commit comments