This repository was archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathiterator-operations.html
42 lines (41 loc) · 2.77 KB
/
iterator-operations.html
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
42
<emu-clause id="sec-getiterator" aoid="GetIterator">
<h1>GetIterator ( _obj_ <ins>[ , _hint_ ]</ins>[ , _method_ ] )</h1>
<emu-note type="editor">
<p>This abstract operation has been modified to accept an optional parameter _hint_ which indicates whether we should attempt to find an async iterator for the object. Existing call sites which use the optional _method_ parameter (`Array.from` and IterableToArrayLike) must be updated to pass the ~normal~ hint.</p>
</emu-note>
<p>The abstract operation GetIterator with argument _obj_ and optional arguments _hint_ and _method_ performs the following steps:</p>
<emu-alg>
1. <ins>If _hint_ was not passed, let _hint_ be ~normal~.</ins>
1. If _method_ is not present, then
1. <del>Set _method_ to ? GetMethod(_obj_, @@iterator).</del>
1. <ins>If _hint_ is ~async~,</ins>
1. <ins>Set _method_ to ? GetMethod(_obj_, @@asyncIterator).</ins>
1. <ins>If _method_ is *undefined*,
1. <ins>Let _syncMethod_ be ? GetMethod(_obj_, @@iterator).</ins>
1. <ins>Let _syncIteratorRecord_ be ? GetIterator(_obj_, ~normal~, _syncMethod_).</ins>
1. <ins>Return ? CreateAsyncFromSyncIterator(_syncIteratorRecord_).</ins>
1. <ins>Otherwise, set _method_ to ? GetMethod(_obj_, @@iterator).</ins>
1. Let _iterator_ be ? Call(_method_, _obj_).
1. If Type(_iterator_) is not Object, throw a *TypeError* exception.
1. Let _nextMethod_ be ? GetV(_iterator_, `"next"`).
1. Let _iteratorRecord_ be Record {[[Iterator]]: _iterator_, [[NextMethod]]: _nextMethod_, [[Done]]: *false*}.
1. Return _iteratorRecord_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorclose" aoid="AsyncIteratorClose">
<h1><ins>AsyncIteratorClose ( _iteratorRecord_, _completion_ )</ins></h1>
<p>The abstract operation AsyncIteratorClose with arguments _iteratorRecord_ and _completion_ is used to notify an async iterator that it should perform any actions it would normally perform when it has reached its completed state:</p>
<emu-alg>
1. Assert: Type(_iteratorRecord_.[[Iterator]]) is Object.
1. Assert: _completion_ is a Completion Record.
1. Let _iterator_ be _iteratorRecord_.[[Iterator]].
1. Let _return_ be ? GetMethod(_iterator_, `"return"`).
1. If _return_ is *undefined*, return Completion(_completion_).
1. Let _innerResult_ be Call(_return_, _iterator_, « »).
1. If _innerResult_.[[Type]] is ~normal~, set _innerResult_ to Await(_innerResult_.[[Value]]).
1. If _completion_.[[Type]] is ~throw~, return Completion(_completion_).
1. If _innerResult_.[[Type]] is ~throw~, return Completion(_innerResult_).
1. If Type(_innerResult_.[[Value]]) is not Object, throw a *TypeError* exception.
1. Return Completion(_completion_).
</emu-alg>
</emu-clause>