/
spec.html
1087 lines (1014 loc) · 52.4 KB
/
spec.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<meta charset="utf-8">
<pre class="metadata">
title: Iterator Helpers
status: proposal
stage: 3
location: https://tc39.es/proposal-iterator-helpers
copyright: false
contributors: Gus Caplan
</pre>
<style>
ins.block {
font-weight: bold;
font-style: italic;
}
hr {
height: 0.25em;
background: #ccc;
border: 0;
margin: 2em 0;
}
.unicode-property-table {
table-layout: fixed;
width: 100%;
font-size: 80%;
}
.unicode-property-table ul {
padding-left: 0;
list-style: none;
}
#metadata-block {
margin: 4em 0;
padding: 10px;
border: 1px solid #ee8421;
}
#metadata-block h1 {
font-size: 1.5em;
margin-top: 0;
}
#metadata-block > ul {
list-style-type: none;
margin: 0; padding: 0;
}
</style>
<div id="metadata-block">
<h1>Contributing to this Proposal</h1>
<p>This proposal is developed on GitHub with the help of the ECMAScript community. There are a number of ways to contribute to the development of this specification:</p>
<ul>
<li>GitHub Repository: <a href="https://github.com/tc39/proposal-iterator-helpers">https://github.com/tc39/proposal-iterator-helpers</a></li>
<li>Issues: <a href="https://github.com/tc39/proposal-iterator-helpers/issues">All Issues</a>, <a href="https://github.com/tc39/proposal-iterator-helpers/issues/new">File a New Issue</a></li>
<li>Pull Requests: <a href="https://github.com/tc39/proposal-iterator-helpers/pulls">All Pull Requests</a>, <a href="https://github.com/tc39/proposal-iterator-helpers/pulls/new">Create a New Pull Request</a></li>
<!-- <li>Test Suite: <a href="https://github.com/tc39/test262">Test262</a></li> -->
<li>
<p>Community:</p>
<ul>
<li>Discourse: <a href="https://es.discourse.group">https://es.discourse.group</a></li>
<li>Chat: <a href="https://github.com/tc39/how-we-work/blob/HEAD/matrix-guide.md">Matrix</a></li>
</ul>
</li>
</ul>
</div>
<emu-clause id="sec-well-known-intrinsic-objects">
<h1>Well-Known Intrinsic Objects</h1>
<emu-table id="table-7" caption="Well-Known Intrinsic Objects">
<table>
<tr>
<th>
Intrinsic Name
</th>
<th>
Global Name
</th>
<th>
ECMAScript Language Association
</th>
</tr>
<tr>
<td>
<ins>%AsyncIterator%</ins>
</td>
<td>
<ins>`AsyncIterator`</ins>
</td>
<td>
<ins>The `AsyncIterator` constructor (<emu-xref href="#sec-asynciterator-constructor"></emu-xref>)</ins>
</td>
</tr>
<tr>
<td>
%AsyncIteratorPrototype%
</td>
<td>
<ins>`AsyncIterator.prototype`</ins>
</td>
<td>
An object that all standard built-in async iterator objects indirectly inherit from
<p><ins>The initial value of the *"prototype"* data property of %AsyncIterator%; i.e., %AsyncIterator.prototype%</ins></p>
</td>
</tr>
<tr>
<td>
<ins>%Iterator%</ins>
</td>
<td>
<ins>`Iterator`</ins>
</td>
<td>
<ins>The `Iterator` constructor (<emu-xref href="#sec-iterator-constructor"></emu-xref>)</ins>
</td>
</tr>
<tr>
<td>
%IteratorPrototype%
</td>
<td>
<ins>`Iterator.prototype`</ins>
</td>
<td>
An object that all standard built-in iterator objects indirectly inherit from
<p><ins>The initial value of the *"prototype"* data property of %Iterator%; i.e., %Iterator.prototype%</ins></p>
</td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-abstract-operations">
<h1>Abstract Operations</h1>
<emu-clause id="sec-operations-on-iterator-objects">
<h1>Operations on Iterator Objects</h1>
<emu-clause id="sec-getiteratordirect" type="abstract operation">
<h1>
GetIteratorDirect (
_obj_: an ECMAScript language value,
): either a normal completion containing an Iterator Record or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _obj_ is not an Object, throw a *TypeError* exception.
1. Let _nextMethod_ be ? Get(_obj_, `"next"`).
1. If IsCallable(_nextMethod_) is *false*, throw a *TypeError* exception.
1. Let _iteratorRecord_ be Record { [[Iterator]]: _obj_, [[NextMethod]]: _nextMethod_, [[Done]]: *false* }.
1. Return _iteratorRecord_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-getiteratorflattenable" type="abstract operation">
<h1>
GetIteratorFlattenable (
_obj_: an ECMAScript language value,
_hint_: ~sync~ or ~async~,
): either a normal completion containing an Iterator Record or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _obj_ is not an Object, throw a *TypeError* exception.
1. Let _alreadyAsync_ be *false*.
1. Let _method_ be *undefined*.
1. If _hint_ is ~async~, then
1. Set _method_ to ? Get(_obj_, @@asyncIterator).
1. Set _alreadyAsync_ to *true*.
1. If IsCallable(_method_) is *false*, then
1. Set _method_ to ? Get(_obj_, @@iterator).
1. Set _alreadyAsync_ to *false*.
1. If IsCallable(_method_) is *false*, then
1. Let _iterator_ be _obj_.
1. Set _alreadyAsync_ to *true*.
1. Else,
1. Let _iterator_ be ? Call(_method_, _obj_).
1. If _iterator_ is not an Object, throw a *TypeError* exception.
1. Let _nextMethod_ be ? Get(_iterator_, *"next"*).
1. If IsCallable(_nextMethod_) is *false*, throw a *TypeError* exception.
1. Let _iteratorRecord_ be the Iterator Record { [[Iterator]]: _iterator_, [[NextMethod]]: _nextMethod_, [[Done]]: *false* }.
1. If _hint_ is ~async~ and _alreadyAsync_ is *false*, then
1. Return CreateAsyncFromSyncIterator(_iteratorRecord_).
1. Return _iteratorRecord_.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-control-abstraction-objects">
<h1>Control Abstraction Objects</h1>
<emu-clause id="sec-iteration">
<h1>Iteration</h1>
<emu-clause id="sec-iterator-abstract-operations">
<h1>Iterator Abstract Operations</h1>
<emu-clause id="sec-ifabruptcloseasynciterator" aoid="IfAbruptCloseAsyncIterator">
<h1>IfAbruptCloseAsyncIterator ( _value_, _iteratorRecord_ )</h1>
<p>IfAbruptCloseAsyncIterator is a shorthand for a sequence of algorithm steps that use an Iterator Record. An algorithm step of the form:</p>
<emu-alg>
1. IfAbruptCloseAsyncIterator(_value_, _iteratorRecord_).
</emu-alg>
<p>means the same thing as:</p>
<emu-alg>
1. If _value_ is an abrupt completion, then
1. Perform ? AsyncIteratorClose(_iteratorRecord_, _value_).
1. Return _value_.
1. Else if _value_ is a Completion Record, set _value_ to _value_.[[Value]].
</emu-alg>
</emu-clause>
<emu-clause id="sec-awaitnonprimitive" type="abstract operation">
<h1>
AwaitNonPrimitive (
_value_: an ECMAScript language value,
): either a normal completion containing an ECMAScript language value or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _value_ is an Object, return ? Await(_value_).
1. Else, return _value_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-iterator-objects">
<h1>Iterator Objects</h1>
<emu-clause id="sec-iterator-constructor">
<h1>The Iterator Constructor</h1>
<p>The <dfn>Iterator</dfn> constructor:</p>
<ul>
<li>is <dfn>%Iterator%</dfn>.</li>
<li>is the initial value of the *Iterator* property of the global object.</li>
<li>is designed to be subclassable. It may be used as the value of an *extends* clause of a class definition.</li>
</ul>
<emu-clause id="sec-iterator">
<h1>Iterator ( )</h1>
<p>When the `Iterator` function is called, the following steps are taken:</p>
<emu-alg>
1. If NewTarget is *undefined* or the active function object, throw a *TypeError* exception.
1. Return ? OrdinaryCreateFromConstructor(NewTarget, *"%Iterator.prototype%"*).
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-iterator-constructor">
<h1>Properties of the Iterator Constructor</h1>
<emu-clause id="sec-iterator.prototype">
<h1>Iterator.prototype</h1>
<p>The initial value of Iterator.prototype is %Iterator.prototype%.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.</p>
</emu-clause>
<emu-clause id="sec-iterator.from">
<h1>Iterator.from ( _O_ )</h1>
<emu-alg>
1. If _O_ is a String, set _O_ to ! ToObject(_O_).
1. Let _iteratorRecord_ be ? GetIteratorFlattenable(_O_, ~sync~).
1. Let _hasInstance_ be ? OrdinaryHasInstance(%Iterator%, _iteratorRecord_.[[Iterator]]).
1. If _hasInstance_ is *true*, then
1. Return _iteratorRecord_.[[Iterator]].
1. Let _wrapper_ be OrdinaryObjectCreate(%WrapForValidIteratorPrototype%, « [[Iterated]] »).
1. Set _wrapper_.[[Iterated]] to _iteratorRecord_.
1. Return _wrapper_.
</emu-alg>
<emu-clause id="sec-wrapforvaliditeratorprototype-object">
<h1>The %WrapForValidIteratorPrototype% Object</h1>
<p>The <dfn>%WrapForValidIteratorPrototype%</dfn> object:</p>
<ul>
<li>has a [[Prototype]] internal slot whose value is %Iterator.prototype%.</li>
</ul>
<emu-clause id="sec-wrapforvaliditeratorprototype.next">
<h1>%WrapForValidIteratorPrototype%.next ( )</h1>
<emu-alg>
1. Let _O_ be *this* value.
1. Perform ? RequireInternalSlot(_O_, [[Iterated]]).
1. Let _iteratorRecord_ be _O_.[[Iterated]].
1. Return ? Call(_iteratorRecord_.[[NextMethod]], _iteratorRecord_.[[Iterator]]).
</emu-alg>
</emu-clause>
<emu-clause id="sec-wrapforvaliditeratorprototype.return">
<h1>%WrapForValidIteratorPrototype%.return ( )</h1>
<emu-alg>
1. Let _O_ be *this* value.
1. Perform ? RequireInternalSlot(_O_, [[Iterated]]).
1. Let _iterator_ be _O_.[[Iterated]].[[Iterator]].
1. Assert: _iterator_ is an Object.
1. Let _returnMethod_ be ? GetMethod(_iterator_, *"return"*).
1. If _returnMethod_ is *undefined*, then
1. Return CreateIterResultObject(*undefined*, *true*).
1. Return ? Call(_returnMethod_, _iterator_).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-asynciterator-objects">
<h1>AsyncIterator Objects</h1>
<emu-clause id="sec-asynciterator-constructor">
<h1>The AsyncIterator Constructor</h1>
<p>The <dfn>AsyncIterator</dfn> constructor:</p>
<ul>
<li>is <dfn>%AsyncIterator%</dfn>.</li>
<li>is the initial value of the *AsyncIterator* property of the global object.</li>
<li>is designed to be subclassable. It may be used as the value of an *extends* clause of a class definition.</li>
</ul>
<emu-clause id="sec-asynciterator">
<h1>AsyncIterator ( )</h1>
<p>When the `AsyncIterator` function is called, the following steps are taken:</p>
<emu-alg>
1. If NewTarget is *undefined* or the active function object, throw a *TypeError* exception.
1. Return ? OrdinaryCreateFromConstructor(NewTarget, *"%AsyncIterator.prototype%"*).
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-asynciterator-constructor">
<h1>Properties of the AsyncIterator Constructor</h1>
<emu-clause id="sec-asynciterator.prototype">
<h1>AsyncIterator.prototype</h1>
<p>The initial value of AsyncIterator.prototype is %AsyncIterator.prototype%.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.</p>
</emu-clause>
<emu-clause id="sec-asynciterator.from">
<h1>AsyncIterator.from ( _O_ )</h1>
<emu-alg>
1. If _O_ is a String, set _O_ to ! ToObject(_O_).
1. Let _iteratorRecord_ be ? GetIteratorFlattenable(_O_, ~async~).
1. Let _hasInstance_ be ? OrdinaryHasInstance(%AsyncIterator%, _iteratorRecord_.[[Iterator]]).
1. If _hasInstance_ is *true*, then
1. Return _iteratorRecord_.[[Iterator]].
1. Let _wrapper_ be OrdinaryObjectCreate(%WrapForValidAsyncIteratorPrototype%, « [[AsyncIterated]] »).
1. Set _wrapper_.[[AsyncIterated]] to _iteratorRecord_.
1. Return _wrapper_.
</emu-alg>
<emu-clause id="sec-wrapforvalidasynciteratorprototype-object">
<h1>The %WrapForValidAsyncIteratorPrototype% Object</h1>
<p>The <dfn>%WrapForValidAsyncIteratorPrototype%</dfn> object:</p>
<ul>
<li>is an ordinary object.</li>
<li>has a [[Prototype]] internal slot whose value is %AsyncIterator.prototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-wrapforvalidasynciteratorprototype.next">
<h1>%WrapForValidAsyncIteratorPrototype%.next ( )</h1>
<emu-alg>
1. Let _O_ be *this* value.
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _check_ be Completion(RequireInternalSlot(_O_, [[AsyncIterated]])).
1. IfAbruptRejectPromise(_check_, _promiseCapability_).
1. Let _result_ be Completion(IteratorNext(_O_.[[AsyncIterated]])).
1. IfAbruptRejectPromise(_result_, _promiseCapability_).
1. Return ? PromiseResolve(%Promise%, _result_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-wrapforvalidasynciteratorprototype.return">
<h1>%WrapForValidAsyncIteratorPrototype%.return ( )</h1>
<emu-alg>
1. Let _O_ be *this* value.
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _check_ be Completion(RequireInternalSlot(_O_, [[AsyncIterated]])).
1. IfAbruptRejectPromise(_check_, _promiseCapability_).
1. Let _iterator_ be _O_.[[AsyncIterated]].[[Iterator]].
1. Assert: _iterator_ is an Object.
1. Let _returnMethod_ be Completion(GetMethod(_iterator_, *"return"*)).
1. IfAbruptRejectPromise(_returnMethod_, _promiseCapability_).
1. If _returnMethod_ is *undefined*, then
1. Return ! PromiseResolve(%Promise%, CreateIterResultObject(*undefined*, *true*)).
1. Let _result_ be Completion(Call(_returnMethod_, _iterator_)).
1. IfAbruptRejectPromise(_result_, _promiseCapability_).
1. Return ? PromiseResolve(%Promise%, _result_).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-iterator-helper-objects">
<h1>Iterator Helper Objects</h1>
<p>An Iterator Helper object is an ordinary object that represents a lazy transformation of some specific source iterator object. There is not a named constructor for Iterator Helper objects. Instead, Iterator Helper objects are created by calling certain methods of Iterator instance objects.</p>
<emu-clause id="sec-%iteratorhelperprototype%-object">
<h1>The %IteratorHelperPrototype% Object</h1>
<p>The <dfn>%IteratorHelperPrototype%</dfn> object:</p>
<ul>
<li>has properties that are inherited by all Iterator Helper Objects.</li>
<li>is an ordinary object.</li>
<li>has a [[Prototype]] internal slot whose value is %Iterator.prototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-%iteratorhelperprototype%.next">
<h1>%IteratorHelperPrototype%.next ( )</h1>
<emu-alg>
1. Return ? GeneratorResume(*this* value, *undefined*, *"Iterator Helper"*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-%iteratorhelperprototype%.return">
<h1>%IteratorHelperPrototype%.return ( )</h1>
<emu-alg>
1. Let _C_ be Completion { [[Type]]: ~return~, [[Value]]: *undefined*, [[Target]]: ~empty~ }.
1. Return ? GeneratorResumeAbrupt(*this* value, _C_, *"Iterator Helper"*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-%iteratorhelperprototype%-@@tostringtag">
<h1>%IteratorHelperPrototype% [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value *"Iterator Helper"*.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-async-iterator-helper-objects">
<h1>Async Iterator Helper Objects</h1>
<p>An Async Iterator Helper object is an ordinary object that represents a lazy transformation of some specific source async iterator object. There is not a named constructor for Async Iterator Helper objects. Instead, Async Iterator Helper objects are created by calling certain methods of AsyncIterator instance objects.</p>
<emu-clause id="sec-%asynciteratorhelperprototype%-object">
<h1>The %AsyncIteratorHelperPrototype% Object</h1>
<p>The <dfn>%AsyncIteratorHelperPrototype%</dfn> object:</p>
<ul>
<li>has properties that are inherited by all Async Iterator Helper Objects.</li>
<li>is an ordinary object.</li>
<li>has a [[Prototype]] internal slot whose value is %AsyncIterator.prototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-%asynciteratorhelperprototype%.next">
<h1>%AsyncIteratorHelperPrototype%.next ( )</h1>
<emu-alg>
1. Return AsyncGeneratorNext(*this* value, *"Async Iterator Helper"*, *undefined*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-%asynciteratorhelperprototype%.return">
<h1>%AsyncIteratorHelperPrototype%.return ( )</h1>
<emu-alg>
1. Return AsyncGeneratorReturn(*this* value, *"Async Iterator Helper"*, *undefined*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-%asynciteratorhelperprototype%-@@tostringtag">
<h1>%AsyncIteratorHelperPrototype% [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value *"Async Iterator Helper"*.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-iteratorprototype">
<h1>Iterator.prototype</h1>
<p>The <dfn>Iterator prototype object</dfn>:</p>
<ul>
<li>is <dfn>%Iterator.prototype%</dfn>.</li>
<li>has a [[Prototype]] internal slot whose value is %Object.prototype%.</li>
<li>is an ordinary object.</li>
</ul>
<emu-clause id="sec-iteratorprototype.constructor">
<h1>Iterator.prototype.constructor</h1>
<p>The initial value of %Iterator.prototype%.constructor is %Iterator%.</p>
</emu-clause>
<emu-clause id="sec-iteratorprototype.map">
<h1>Iterator.prototype.map ( _mapper_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_mapped_, _iterated_).
1. Let _completion_ be Completion(Yield(_mapped_)).
1. IfAbruptCloseIterator(_completion_, _iterated_).
1. Set _counter_ to _counter_ + 1.
1. Return CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.filter">
<h1>Iterator.prototype.filter ( _filterer_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_filterer_) is *false*, throw a *TypeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _filterer_ and performs the following steps when called:
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _selected_ be Completion(Call(_filterer_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_selected_, _iterated_).
1. If ToBoolean(_selected_) is *true*, then
1. Let _completion_ be Completion(Yield(_value_)).
1. IfAbruptCloseIterator(_completion_, _iterated_).
1. Set _counter_ to _counter_ + 1.
1. Return CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.take">
<h1>Iterator.prototype.take ( _limit_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _numLimit_ be ? ToNumber(_limit_).
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
1. If _integerLimit_ < 0, throw a *RangeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called:
1. Let _remaining_ be _integerLimit_.
1. Repeat,
1. If _remaining_ is 0, then
1. Return ? IteratorClose(_iterated_, NormalCompletion(*undefined*)).
1. If _remaining_ is not +∞, then
1. Set _remaining_ to _remaining_ - 1.
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *undefined*.
1. Let _completion_ be Completion(Yield(? IteratorValue(_next_))).
1. IfAbruptCloseIterator(_completion_, _iterated_).
1. Return CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.drop">
<h1>Iterator.prototype.drop ( _limit_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _numLimit_ be ? ToNumber(_limit_).
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
1. If _integerLimit_ < 0, throw a *RangeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called:
1. Let _remaining_ be _integerLimit_.
1. Repeat, while _remaining_ > 0,
1. If _remaining_ is not +∞, then
1. Set _remaining_ to _remaining_ - 1.
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *undefined*.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *undefined*.
1. Let _completion_ be Completion(Yield(? IteratorValue(_next_))).
1. IfAbruptCloseIterator(_completion_, _iterated_).
1. Return CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.flatmap">
<h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_mapped_, _iterated_).
1. Let _innerIterator_ be Completion(GetIteratorFlattenable(_mapped_, ~sync~)).
1. IfAbruptCloseIterator(_innerIterator_, _iterated_).
1. Let _innerAlive_ be *true*.
1. Repeat, while _innerAlive_ is *true*,
1. Let _innerNext_ be Completion(IteratorStep(_innerIterator_)).
1. IfAbruptCloseIterator(_innerNext_, _iterated_).
1. If _innerNext_ is *false*, then
1. Set _innerAlive_ to *false*.
1. Else,
1. Let _innerValue_ be Completion(IteratorValue(_innerNext_)).
1. IfAbruptCloseIterator(_innerValue_, _iterated_).
1. Let _completion_ be Completion(Yield(_innerValue_)).
1. If _completion_ is an abrupt completion, then
1. Let _backupCompletion_ be Completion(IteratorClose(_innerIterator_, _completion_)).
1. IfAbruptCloseIterator(_backupCompletion_, _iterated_).
1. Return ? IteratorClose(_completion_, _iterated_).
1. Set _counter_ to _counter_ + 1.
1. Return CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.reduce">
<h1>Iterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_reducer_) is *false*, throw a *TypeError* exception.
1. If _initialValue_ is not present, then
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, throw a *TypeError* exception.
1. Let _accumulator_ be ? IteratorValue(_next_).
1. Let _counter_ be 1.
1. Else,
1. Let _accumulator_ be _initialValue_.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return _accumulator_.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _result_ be Completion(Call(_reducer_, *undefined*, « _accumulator_, _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_result_, _iterated_).
1. Set _accumulator_ to _result_.[[Value]].
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.toarray">
<h1>Iterator.prototype.toArray ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _items_ be a new empty List.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return CreateArrayFromList(_items_).
1. Let _value_ be ? IteratorValue(_next_).
1. Append _value_ to _items_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.toasync">
<h1>Iterator.prototype.toAsync ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _syncIteratorRecord_ be ? GetIteratorDirect(*this* value).
1. Let _asyncIteratorRecord_ be CreateAsyncFromSyncIterator(_syncIteratorRecord_).
1. Let _wrapper_ be OrdinaryObjectCreate(%WrapForValidAsyncIteratorPrototype%, « [[AsyncIterated]] »).
1. Set _wrapper_.[[AsyncIterated]] to _asyncIteratorRecord_.
1. Return _wrapper_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.foreach">
<h1>Iterator.prototype.forEach ( _fn_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_result_, _iterated_).
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.some">
<h1>Iterator.prototype.some ( _fn_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *false*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_result_, _iterated_).
1. If ToBoolean(_result_) is *true*, return ? IteratorClose(_iterated_, NormalCompletion(*true*)).
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.every">
<h1>Iterator.prototype.every ( _fn_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *true*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_result_, _iterated_).
1. If ToBoolean(_result_) is *false*, return ? IteratorClose(_iterated_, NormalCompletion(*false*)).
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype.find">
<h1>Iterator.prototype.find ( _fn_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseIterator(_result_, _iterated_).
1. If ToBoolean(_result_) is *true*, return ? IteratorClose(_iterated_, NormalCompletion(_value_)).
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-iteratorprototype-@@tostringtag">
<h1>Iterator.prototype [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value "Iterator".</p>
<emu-note>
<p>Unlike the @@toStringTag on most built-in classes, for web-compatibility reasons this property must be writable.</p>
</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype">
<h1>AsyncIterator.prototype</h1>
<p>The <dfn>AsyncIterator prototype object</dfn>:</p>
<ul>
<li>is <dfn>%AsyncIterator.prototype%</dfn>.</li>
<li>has a [[Prototype]] internal slot whose value is %Object.prototype%.</li>
<li>is an ordinary object.</li>
</ul>
<emu-clause id="sec-asynciteratorprototype.constructor">
<h1>AsyncIterator.prototype.constructor</h1>
<p>The initial value of AsyncIterator.prototype.constructor is %AsyncIterator%.</p>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.map">
<h1>AsyncIterator.prototype.map ( _mapper_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_).
1. Set _mapped_ to Completion(AwaitNonPrimitive(_mapped_)).
1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_).
1. Let _completion_ be Completion(Yield(_mapped_)).
1. IfAbruptCloseAsyncIterator(_completion_, _iterated_).
1. Set _counter_ to _counter_ + 1.
1. Return CreateAsyncIteratorFromClosure(_closure_, *"Async Iterator Helper"*, %AsyncIteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.filter">
<h1>AsyncIterator.prototype.filter ( _filterer_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_filterer_) is *false*, throw a *TypeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _filterer_ and performs the following steps when called:
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _selected_ be Completion(Call(_filterer_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseAsyncIterator(_selected_, _iterated_).
1. Set _selected_ to Completion(AwaitNonPrimitive(_selected_)).
1. IfAbruptCloseAsyncIterator(_selected_, _iterated_).
1. If ToBoolean(_selected_) is *true*, then
1. Let _completion_ be Completion(Yield(_value_)).
1. IfAbruptCloseAsyncIterator(_completion_, _iterated_).
1. Set _counter_ to _counter_ + 1.
1. Return CreateAsyncIteratorFromClosure(_closure_, *"Async Iterator Helper"*, %AsyncIteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.take">
<h1>AsyncIterator.prototype.take ( _limit_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _numLimit_ be ? ToNumber(_limit_).
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
1. If _integerLimit_ < 0, throw a *RangeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called:
1. Let _remaining_ be _integerLimit_.
1. Repeat,
1. If _remaining_ is 0, then
1. Return ? AsyncIteratorClose(_iterated_, NormalCompletion(*undefined*)).
1. If _remaining_ is not +∞, then
1. Set _remaining_ to _remaining_ - 1.
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
1. Let _completion_ be Completion(Yield(? IteratorValue(_next_))).
1. IfAbruptCloseAsyncIterator(_completion_, _iterated_).
1. Return CreateAsyncIteratorFromClosure(_closure_, *"Async Iterator Helper"*, %AsyncIteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.drop">
<h1>AsyncIterator.prototype.drop ( _limit_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _numLimit_ be ? ToNumber(_limit_).
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
1. If _integerLimit_ < 0, throw a *RangeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called:
1. Let _remaining_ be _integerLimit_.
1. Repeat, while _remaining_ > 0,
1. If _remaining_ is not +∞, then
1. Set _remaining_ to _remaining_ - 1.
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
1. Let _completion_ be Completion(Yield(? IteratorValue(_next_))).
1. IfAbruptCloseAsyncIterator(_completion_, _iterated_).
1. Return CreateAsyncIteratorFromClosure(_closure_, *"Async Iterator Helper"*, %AsyncIteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.flatmap">
<h1>AsyncIterator.prototype.flatMap ( _mapper_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_).
1. Set _mapped_ to Completion(AwaitNonPrimitive(_mapped_)).
1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_).
1. Let _innerIterator_ be Completion(GetIteratorFlattenable(_mapped_, ~async~)).
1. IfAbruptCloseAsyncIterator(_innerIterator_, _iterated_).
1. Let _innerAlive_ be *true*.
1. Repeat, while _innerAlive_ is *true*,
1. Let _innerNextPromise_ be Completion(IteratorNext(_innerIterator_)).
1. IfAbruptCloseAsyncIterator(_innerNextPromise_, _iterated_).
1. Let _innerNext_ be Completion(Await(_innerNextPromise_)).
1. IfAbruptCloseAsyncIterator(_innerNext_, _iterated_).
1. Let _innerComplete_ be Completion(IteratorComplete(_innerNext_)).
1. IfAbruptCloseAsyncIterator(_innerComplete_, _iterated_).
1. If _innerComplete_ is *true*, then
1. Set _innerAlive_ to *false*.
1. Else,
1. Let _innerValue_ be Completion(IteratorValue(_innerNext_)).
1. IfAbruptCloseAsyncIterator(_innerValue_, _iterated_).
1. [id="step-async-iterator-flatmap-yield"] Let _completion_ be Completion(Yield(_innerValue_)).
1. If _completion_ is a return completion, then
1. Let _backupCompletion_ be Completion(IteratorClose(_innerIterator_, _completion_)).
1. IfAbruptCloseIterator(_backupCompletion_, _iterated_).
1. Return ? IteratorClose(_completion_, _iterated_).
1. Else if _completion_ is a throw completion, then
1. Assert: Awaiting _innerValue_ during the Yield on step <emu-xref href="#step-async-iterator-flatmap-yield"></emu-xref> threw.
1. Return ? IteratorClose(_completion_, _iterated_).
1. Set _counter_ to _counter_ + 1.
1. Return CreateAsyncIteratorFromClosure(_closure_, *"Async Iterator Helper"*, %AsyncIteratorHelperPrototype%).
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.reduce">
<h1>AsyncIterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )</h1>
<p>This async method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_reducer_) is *false*, throw a *TypeError* exception.
1. If _initialValue_ is not present, then
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, throw a *TypeError* exception.
1. Let _accumulator_ be ? IteratorValue(_next_).
1. Let _counter_ be 1.
1. Else,
1. Let _accumulator_ be _initialValue_.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return _accumulator_.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _result_ be Completion(Call(_reducer_, *undefined*, « _accumulator_, _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
1. Set _result_ to Completion(AwaitNonPrimitive(_result_)).
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
1. Set _accumulator_ to _result_.
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.toarray">
<h1>AsyncIterator.prototype.toArray ( )</h1>
<p>This async method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _items_ be a new empty List.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return CreateArrayFromList(_items_).
1. Let _value_ be ? IteratorValue(_next_).
1. Append _value_ to _items_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.foreach">
<h1>AsyncIterator.prototype.forEach ( _fn_ )</h1>
<p>This async method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _r_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseAsyncIterator(_r_, _iterated_).
1. Set _r_ to Completion(AwaitNonPrimitive(r)).
1. IfAbruptCloseAsyncIterator(_r_, _iterated_).
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.some">
<h1>AsyncIterator.prototype.some ( _fn_ )</h1>
<p>This async method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *false*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
1. Set _result_ to Completion(AwaitNonPrimitive(_result_)).
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
1. If ToBoolean(_result_) is *true*, return ? AsyncIteratorClose(_iterated_, NormalCompletion(*true*)).
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.every">
<h1>AsyncIterator.prototype.every ( _fn_ )</h1>
<p>This async method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
1. If ? IteratorComplete(_next_) is *true*, return *true*.
1. Let _value_ be ? IteratorValue(_next_).
1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)).
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
1. Set _result_ to Completion(AwaitNonPrimitive(_result_)).
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
1. If ToBoolean(_result_) is *false*, return ? AsyncIteratorClose(_iterated_, NormalCompletion(*false*)).
1. Set _counter_ to _counter_ + 1.
</emu-alg>
</emu-clause>
<emu-clause id="sec-asynciteratorprototype.find">
<h1>AsyncIterator.prototype.find ( _fn_ )</h1>
<p>This async method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).