@@ -441,14 +441,16 @@ <h1>Iterator.prototype.map ( _mapper_ )</h1>
441
441
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
442
442
1. If IsCallable(_mapper_ ) is *false* , throw a *TypeError* exception.
443
443
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
444
+ 1. Let _counter_ be 0.
444
445
1. Repeat,
445
446
1. Let _next_ be ? IteratorStep(_iterated_ ).
446
447
1. If _next_ is *false* , return *undefined* .
447
448
1. Let _value_ be ? IteratorValue(_next_ ).
448
- 1. Let _mapped_ be Completion(Call(_mapper_ , *undefined* , « ; _value_ » ; )).
449
+ 1. Let _mapped_ be Completion(Call(_mapper_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
449
450
1. IfAbruptCloseIterator(_mapped_ , _iterated_ ).
450
451
1. Let _completion_ be Completion(Yield(_mapped_ )).
451
452
1. IfAbruptCloseIterator(_completion_ , _iterated_ ).
453
+ 1. Set _counter_ to _counter_ + 1.
452
454
1. Return CreateIteratorFromClosure(_closure_ , ~Iterator Helper~ , %IteratorHelperPrototype%).
453
455
</emu-alg >
454
456
</emu-clause >
@@ -459,15 +461,17 @@ <h1>Iterator.prototype.filter ( _filterer_ )</h1>
459
461
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
460
462
1. If IsCallable(_filterer_ ) is *false* , throw a *TypeError* exception.
461
463
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _filterer_ and performs the following steps when called:
464
+ 1. Let _counter_ be 0.
462
465
1. Repeat,
463
466
1. Let _next_ be ? IteratorStep(_iterated_ ).
464
467
1. If _next_ is *false* , return *undefined* .
465
468
1. Let _value_ be ? IteratorValue(_next_ ).
466
- 1. Let _selected_ be Completion(Call(_filterer_ , *undefined* , « ; _value_ » ; )).
469
+ 1. Let _selected_ be Completion(Call(_filterer_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
467
470
1. IfAbruptCloseIterator(_selected_ , _iterated_ ).
468
471
1. If ToBoolean(_selected_ ) is *true* , then
469
472
1. Let _completion_ be Completion(Yield(_value_ )).
470
473
1. IfAbruptCloseIterator(_completion_ , _iterated_ ).
474
+ 1. Set _counter_ to _counter_ + 1.
471
475
1. Return CreateIteratorFromClosure(_closure_ , ~Iterator Helper~ , %IteratorHelperPrototype%).
472
476
</emu-alg >
473
477
</emu-clause >
@@ -530,9 +534,9 @@ <h1>Iterator.prototype.indexed ( )</h1>
530
534
1. If _next_ is *false* , return *undefined* .
531
535
1. Let _value_ be ? IteratorValue(_next_ ).
532
536
1. Let _pair_ be CreateArrayFromList(« ; 𝔽(_index_ ), _value_ » ; ).
533
- 1. Set _index_ to _index_ + 1.
534
537
1. Let _completion_ be Completion(Yield(_pair_ )).
535
538
1. IfAbruptCloseIterator(_completion_ , _iterated_ ).
539
+ 1. Set _index_ to _index_ + 1.
536
540
1. Return CreateIteratorFromClosure(_closure_ , ~Iterator Helper~ , %IteratorHelperPrototype%).
537
541
</emu-alg >
538
542
</emu-clause >
@@ -543,11 +547,12 @@ <h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
543
547
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
544
548
1. If IsCallable(_mapper_ ) is *false* , throw a *TypeError* exception.
545
549
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
550
+ 1. Let _counter_ be 0.
546
551
1. Repeat,
547
552
1. Let _next_ be ? IteratorStep(_iterated_ ).
548
553
1. If _next_ is *false* , return *undefined* .
549
554
1. Let _value_ be ? IteratorValue(_next_ ).
550
- 1. Let _mapped_ be Completion(Call(_mapper_ , *undefined* , « ; _value_ » ; )).
555
+ 1. Let _mapped_ be Completion(Call(_mapper_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
551
556
1. IfAbruptCloseIterator(_mapped_ , _iterated_ ).
552
557
1. Let _innerIterator_ be Completion(GetIterator(_mapped_ , ~sync~ )).
553
558
1. IfAbruptCloseIterator(_innerIterator_ , _iterated_ ).
@@ -565,6 +570,7 @@ <h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
565
570
1. Let _backupCompletion_ be Completion(IteratorClose(_innerIterator_ , _completion_ )).
566
571
1. IfAbruptCloseIterator(_backupCompletion_ , _iterated_ ).
567
572
1. Return ? IteratorClose(_completion_ , _iterated_ ).
573
+ 1. Set _counter_ to _counter_ + 1.
568
574
1. Return CreateIteratorFromClosure(_closure_ , ~Iterator Helper~ , %IteratorHelperPrototype%).
569
575
</emu-alg >
570
576
</emu-clause >
@@ -580,13 +586,15 @@ <h1>Iterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )</h1>
580
586
1. Let _accumulator_ be ? IteratorValue(_next_ ).
581
587
1. Else,
582
588
1. Let _accumulator_ be _initialValue_ .
589
+ 1. Let _counter_ be 0.
583
590
1. Repeat,
584
591
1. Let _next_ be ? IteratorStep(_iterated_ ).
585
592
1. If _next_ is *false* , return _accumulator_ .
586
593
1. Let _value_ be ? IteratorValue(_next_ ).
587
- 1. Let _result_ be Completion(Call(_reducer_ , *undefined* , « ; _accumulator_ , _value_ » ; )).
594
+ 1. Let _result_ be Completion(Call(_reducer_ , *undefined* , « ; _accumulator_ , _value_ , 𝔽( _counter_ ) » ; )).
588
595
1. IfAbruptCloseIterator(_result_ , _iterated_ ).
589
596
1. Set _accumulator_ to _result_ .[[Value]].
597
+ 1. Set _counter_ to _counter_ + 1.
590
598
</emu-alg >
591
599
</emu-clause >
592
600
@@ -619,12 +627,14 @@ <h1>Iterator.prototype.forEach ( _fn_ )</h1>
619
627
<emu-alg >
620
628
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
621
629
1. If IsCallable(_fn_ ) is *false* , throw a *TypeError* exception.
630
+ 1. Let _counter_ be 0.
622
631
1. Repeat,
623
632
1. Let _next_ be ? IteratorStep(_iterated_ ).
624
633
1. If _next_ is *false* , return *undefined* .
625
634
1. Let _value_ be ? IteratorValue(_next_ ).
626
- 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ » ; )).
635
+ 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
627
636
1. IfAbruptCloseIterator(_result_ , _iterated_ ).
637
+ 1. Set _counter_ to _counter_ + 1.
628
638
</emu-alg >
629
639
</emu-clause >
630
640
@@ -633,13 +643,15 @@ <h1>Iterator.prototype.some ( _fn_ )</h1>
633
643
<emu-alg >
634
644
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
635
645
1. If IsCallable(_fn_ ) is *false* , throw a *TypeError* exception.
646
+ 1. Let _counter_ be 0.
636
647
1. Repeat,
637
648
1. Let _next_ be ? IteratorStep(_iterated_ ).
638
649
1. If _next_ is *false* , return *false* .
639
650
1. Let _value_ be ? IteratorValue(_next_ ).
640
- 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ » ; )).
651
+ 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
641
652
1. IfAbruptCloseIterator(_result_ , _iterated_ ).
642
653
1. If ToBoolean(_result_ ) is *true* , return ? IteratorClose(_iterated_ , NormalCompletion(*true* )).
654
+ 1. Set _counter_ to _counter_ + 1.
643
655
</emu-alg >
644
656
</emu-clause >
645
657
@@ -648,13 +660,15 @@ <h1>Iterator.prototype.every ( _fn_ )</h1>
648
660
<emu-alg >
649
661
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
650
662
1. If IsCallable(_fn_ ) is *false* , throw a *TypeError* exception.
663
+ 1. Let _counter_ be 0.
651
664
1. Repeat,
652
665
1. Let _next_ be ? IteratorStep(_iterated_ ).
653
666
1. If _next_ is *false* , return *true* .
654
667
1. Let _value_ be ? IteratorValue(_next_ ).
655
- 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ » ; )).
668
+ 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
656
669
1. IfAbruptCloseIterator(_result_ , _iterated_ ).
657
670
1. If ToBoolean(_result_ ) is *false* , return ? IteratorClose(_iterated_ , NormalCompletion(*false* )).
671
+ 1. Set _counter_ to _counter_ + 1.
658
672
</emu-alg >
659
673
</emu-clause >
660
674
@@ -663,13 +677,15 @@ <h1>Iterator.prototype.find ( _fn_ )</h1>
663
677
<emu-alg >
664
678
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
665
679
1. If IsCallable(_fn_ ) is *false* , throw a *TypeError* exception.
680
+ 1. Let _counter_ be 0.
666
681
1. Repeat,
667
682
1. Let _next_ be ? IteratorStep(_iterated_ ).
668
683
1. If _next_ is *false* , return *undefined* .
669
684
1. Let _value_ be ? IteratorValue(_next_ ).
670
- 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ » ; )).
685
+ 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
671
686
1. IfAbruptCloseIterator(_result_ , _iterated_ ).
672
687
1. If ToBoolean(_result_ ) is *true* , return ? IteratorClose(_iterated_ , NormalCompletion(_value_ )).
688
+ 1. Set _counter_ to _counter_ + 1.
673
689
</emu-alg >
674
690
</emu-clause >
675
691
@@ -700,16 +716,18 @@ <h1>AsyncIterator.prototype.map ( _mapper_ )</h1>
700
716
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
701
717
1. If IsCallable(_mapper_ ) is *false* , throw a *TypeError* exception.
702
718
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
719
+ 1. Let _counter_ be 0.
703
720
1. Repeat,
704
721
1. Let _next_ be ? Await(? IteratorNext(_iterated_ )).
705
722
1. If ? IteratorComplete(_next_ ) is *true* , return *undefined* .
706
723
1. Let _value_ be ? IteratorValue(_next_ ).
707
- 1. Let _mapped_ be Completion(Call(_mapper_ , *undefined* , « ; _value_ » ; )).
724
+ 1. Let _mapped_ be Completion(Call(_mapper_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
708
725
1. IfAbruptCloseAsyncIterator(_mapped_ , _iterated_ ).
709
726
1. Set _mapped_ to Completion(Await(_mapped_ )).
710
727
1. IfAbruptCloseAsyncIterator(_mapped_ , _iterated_ ).
711
728
1. Let _completion_ be Completion(Yield(_mapped_ )).
712
729
1. IfAbruptCloseAsyncIterator(_completion_ , _iterated_ ).
730
+ 1. Set _counter_ to _counter_ + 1.
713
731
1. Return CreateAsyncIteratorFromClosure(_closure_ , ~Async Iterator Helper~ , %AsyncIteratorHelperPrototype%).
714
732
</emu-alg >
715
733
</emu-clause >
@@ -720,17 +738,19 @@ <h1>AsyncIterator.prototype.filter ( _filterer_ )</h1>
720
738
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
721
739
1. If IsCallable(_filterer_ ) is *false* , throw a *TypeError* exception.
722
740
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _filterer_ and performs the following steps when called:
741
+ 1. Let _counter_ be 0.
723
742
1. Repeat,
724
743
1. Let _next_ be ? Await(? IteratorNext(_iterated_ )).
725
744
1. If ? IteratorComplete(_next_ ) is *true* , return *undefined* .
726
745
1. Let _value_ be ? IteratorValue(_next_ ).
727
- 1. Let _selected_ be Completion(Call(_filterer_ , *undefined* , « ; _value_ » ; )).
746
+ 1. Let _selected_ be Completion(Call(_filterer_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
728
747
1. IfAbruptCloseAsyncIterator(_selected_ , _iterated_ ).
729
748
1. Set _selected_ to Completion(Await(_selected_ )).
730
749
1. IfAbruptCloseAsyncIterator(_selected_ , _iterated_ ).
731
750
1. If ToBoolean(_selected_ ) is *true* , then
732
751
1. Let _completion_ be Completion(Yield(_value_ )).
733
752
1. IfAbruptCloseAsyncIterator(_completion_ , _iterated_ ).
753
+ 1. Set _counter_ to _counter_ + 1.
734
754
1. Return CreateAsyncIteratorFromClosure(_closure_ , ~Async Iterator Helper~ , %AsyncIteratorHelperPrototype%).
735
755
</emu-alg >
736
756
</emu-clause >
@@ -793,9 +813,9 @@ <h1>AsyncIterator.prototype.indexed ( )</h1>
793
813
1. If ? IteratorComplete(_next_ ) is *true* , return *undefined* .
794
814
1. Let _value_ be ? IteratorValue(_next_ ).
795
815
1. Let _pair_ be CreateArrayFromList(« ; _index_ , _value_ » ; ).
796
- 1. Set _index_ to _index_ + 1.
797
816
1. Let _completion_ be Completion(Yield(_pair_ )).
798
817
1. IfAbruptCloseAsyncIterator(_completion_ , _iterated_ ).
818
+ 1. Set _index_ to _index_ + 1.
799
819
1. Return CreateAsyncIteratorFromClosure(_closure_ , ~Async Iterator Helper~ , %AsyncIteratorHelperPrototype%).
800
820
</emu-alg >
801
821
</emu-clause >
@@ -807,11 +827,12 @@ <h1>AsyncIterator.prototype.flatMap ( _mapper_ )</h1>
807
827
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
808
828
1. If IsCallable(_mapper_ ) is *false* , throw a *TypeError* exception.
809
829
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
830
+ 1. Let _counter_ be 0.
810
831
1. Repeat,
811
832
1. Let _next_ be ? Await(? IteratorNext(_iterated_ )).
812
833
1. If ? IteratorComplete(_next_ ) is *true* , return *undefined* .
813
834
1. Let _value_ be ? IteratorValue(_next_ ).
814
- 1. Let _mapped_ be Completion(Call(_mapper_ , *undefined* , « ; _value_ » ; )).
835
+ 1. Let _mapped_ be Completion(Call(_mapper_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
815
836
1. IfAbruptCloseAsyncIterator(_mapped_ , _iterated_ ).
816
837
1. Set _mapped_ to Completion(Await(_mapped_ )).
817
838
1. IfAbruptCloseAsyncIterator(_mapped_ , _iterated_ ).
@@ -838,6 +859,7 @@ <h1>AsyncIterator.prototype.flatMap ( _mapper_ )</h1>
838
859
1. Else if _completion_ is a throw completion, then
839
860
1. Assert: Awaiting _innerValue_ during the Yield on step <emu-xref href =" #step-async-iterator-flatmap-yield" ></emu-xref > threw.
840
861
1. Return ? IteratorClose(_completion_ , _iterated_ ).
862
+ 1. Set _counter_ to _counter_ + 1.
841
863
1. Return CreateAsyncIteratorFromClosure(_closure_ , ~Async Iterator Helper~ , %AsyncIteratorHelperPrototype%).
842
864
</emu-alg >
843
865
</emu-clause >
@@ -853,15 +875,17 @@ <h1>AsyncIterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )</h1>
853
875
1. Let _accumulator_ be ? IteratorValue(_next_ ).
854
876
1. Else,
855
877
1. Let _accumulator_ be _initialValue_ .
878
+ 1. Let _counter_ be 0.
856
879
1. Repeat,
857
880
1. Let _next_ be ? Await(? IteratorNext(_iterated_ )).
858
881
1. If ? IteratorComplete(_next_ ) is *true* , return _accumulator_ .
859
882
1. Let _value_ be ? IteratorValue(_next_ ).
860
- 1. Let _result_ be Completion(Call(_reducer_ , *undefined* , « ; _accumulator_ , _value_ » ; )).
883
+ 1. Let _result_ be Completion(Call(_reducer_ , *undefined* , « ; _accumulator_ , _value_ , 𝔽( _counter_ ) » ; )).
861
884
1. IfAbruptCloseAsyncIterator(_result_ , _iterated_ ).
862
885
1. Set _result_ to Await(_result_ ).
863
886
1. IfAbruptCloseAsyncIterator(_result_ , _iterated_ ).
864
887
1. Set _accumulator_ to _result_ .
888
+ 1. Set _counter_ to _counter_ + 1.
865
889
</emu-alg >
866
890
</emu-clause >
867
891
@@ -885,14 +909,16 @@ <h1>AsyncIterator.prototype.forEach ( _fn_ )</h1>
885
909
<emu-alg >
886
910
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
887
911
1. If IsCallable(_fn_ ) is *false* , throw a *TypeError* exception.
912
+ 1. Let _counter_ be 0.
888
913
1. Repeat,
889
914
1. Let _next_ be ? Await(? IteratorNext(_iterated_ )).
890
915
1. If ? IteratorComplete(_next_ ) is *true* , return *undefined* .
891
916
1. Let _value_ be ? IteratorValue(_next_ ).
892
- 1. Let _r_ be Completion(Call(_fn_ , *undefined* , « ; _value_ » ; )).
917
+ 1. Let _r_ be Completion(Call(_fn_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
893
918
1. IfAbruptCloseAsyncIterator(_r_ , _iterated_ ).
894
919
1. Set _r_ to Await(r).
895
920
1. IfAbruptCloseAsyncIterator(_r_ , _iterated_ ).
921
+ 1. Set _counter_ to _counter_ + 1.
896
922
</emu-alg >
897
923
</emu-clause >
898
924
@@ -902,15 +928,17 @@ <h1>AsyncIterator.prototype.some ( _fn_ )</h1>
902
928
<emu-alg >
903
929
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
904
930
1. If IsCallable(_fn_ ) is *false* , throw a *TypeError* exception.
931
+ 1. Let _counter_ be 0.
905
932
1. Repeat,
906
933
1. Let _next_ be ? Await(? IteratorNext(_iterated_ )).
907
934
1. If ? IteratorComplete(_next_ ) is *true* , return *false* .
908
935
1. Let _value_ be ? IteratorValue(_next_ ).
909
- 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ » ; )).
936
+ 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
910
937
1. IfAbruptCloseAsyncIterator(_result_ , _iterated_ ).
911
938
1. Set _result_ to Await(_result_ ).
912
939
1. IfAbruptCloseAsyncIterator(_result_ , _iterated_ ).
913
940
1. If ToBoolean(_result_ ) is *true* , return ? AsyncIteratorClose(_iterated_ , NormalCompletion(*true* )).
941
+ 1. Set _counter_ to _counter_ + 1.
914
942
</emu-alg >
915
943
</emu-clause >
916
944
@@ -920,15 +948,17 @@ <h1>AsyncIterator.prototype.every ( _fn_ )</h1>
920
948
<emu-alg >
921
949
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
922
950
1. If IsCallable(_fn_ ) is *false* , throw a *TypeError* exception.
951
+ 1. Let _counter_ be 0.
923
952
1. Repeat,
924
953
1. Let _next_ be ? Await(? IteratorNext(_iterated_ )).
925
954
1. If ? IteratorComplete(_next_ ) is *true* , return *true* .
926
955
1. Let _value_ be ? IteratorValue(_next_ ).
927
- 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ » ; )).
956
+ 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
928
957
1. IfAbruptCloseAsyncIterator(_result_ , _iterated_ ).
929
958
1. Set _result_ to Await(_result_ ).
930
959
1. IfAbruptCloseAsyncIterator(_result_ , _iterated_ ).
931
960
1. If ToBoolean(_result_ ) is *false* , return ? AsyncIteratorClose(_iterated_ , NormalCompletion(*false* )).
961
+ 1. Set _counter_ to _counter_ + 1.
932
962
</emu-alg >
933
963
</emu-clause >
934
964
@@ -938,15 +968,17 @@ <h1>AsyncIterator.prototype.find ( _fn_ )</h1>
938
968
<emu-alg >
939
969
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
940
970
1. If IsCallable(_fn_ ) is *false* , throw a *TypeError* exception.
971
+ 1. Let _counter_ be 0.
941
972
1. Repeat,
942
973
1. Let _next_ be ? Await(? IteratorNext(_iterated_ )).
943
974
1. If ? IteratorComplete(_next_ ) is *true* , return *undefined* .
944
975
1. Let _value_ be ? IteratorValue(_next_ ).
945
- 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ » ; )).
976
+ 1. Let _result_ be Completion(Call(_fn_ , *undefined* , « ; _value_ , 𝔽( _counter_ ) » ; )).
946
977
1. IfAbruptCloseAsyncIterator(_result_ , _iterated_ ).
947
978
1. Set _result_ to Await(_result_ ).
948
979
1. IfAbruptCloseAsyncIterator(_result_ , _iterated_ ).
949
980
1. If ToBoolean(_result_ ) is *true* , return ? AsyncIteratorClose(_iterated_ , NormalCompletion(_value_ )).
981
+ 1. Set _counter_ to _counter_ + 1.
950
982
</emu-alg >
951
983
</emu-clause >
952
984
0 commit comments