-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.emu
41 lines (40 loc) · 1.91 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!doctype html>
<meta charset="utf8">
<pre class="metadata">
title: Iterator Sequencing
status: proposal
stage: 2.7
contributors: Michael Ficarra
location: https://tc39.es/proposal-iterator-sequencing/
copyright: false
</pre>
<emu-clause id="sec-iterator.concat">
<h1>Iterator.concat ( ..._items_ )</h1>
<emu-alg>
1. Let _iterables_ be a new empty List.
1. For each element _item_ of _items_, do
1. If _item_ is not an Object, throw a *TypeError* exception.
1. Let _method_ be ? GetMethod(_item_, %Symbol.iterator%).
1. If _method_ is *undefined*, throw a *TypeError* exception.
1. Append the Record { [[OpenMethod]]: _method_, [[Iterable]]: _item_ } to _iterables_.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterables_ and performs the following steps when called:
1. For each Record _iterable_ of _iterables_, do
1. Let _iter_ be ? Call(_iterable_.[[OpenMethod]], _iterable_.[[Iterable]]).
1. If _iter_ is not an Object, throw a *TypeError* exception.
1. Let _iteratorRecord_ be ? GetIteratorDirect(_iter_).
1. Let _innerAlive_ be *true*.
1. Repeat, while _innerAlive_ is *true*,
1. Let _iteratorResult_ be ? IteratorStep(_iteratorRecord_).
1. If _iteratorResult_ is ~done~, then
1. Perform ? IteratorValue(_iteratorResult_).
1. Set _innerAlive_ to *false*.
1. Else,
1. Let _completion_ be Completion(GeneratorYield(_iteratorResult_)).
1. If _completion_ is an abrupt completion, then
1. Return ? IteratorClose(_iteratorRecord_, _completion_).
1. Return ReturnCompletion(*undefined*).
1. Let _gen_ be CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%, « [[UnderlyingIterators]] »).
1. Set _gen_.[[UnderlyingIterators]] to a new empty List.
1. Return _gen_.
</emu-alg>
</emu-clause>