Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit 7b5e897

Browse files
fixes #207: add a counter parameter to Array analogues that have them
1 parent 3e24c09 commit 7b5e897

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

spec.html

+50-18
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,16 @@ <h1>Iterator.prototype.map ( _mapper_ )</h1>
441441
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
442442
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
443443
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.
444445
1. Repeat,
445446
1. Let _next_ be ? IteratorStep(_iterated_).
446447
1. If _next_ is *false*, return *undefined*.
447448
1. Let _value_ be ? IteratorValue(_next_).
448-
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, &laquo; _value_ &raquo;)).
449+
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
449450
1. IfAbruptCloseIterator(_mapped_, _iterated_).
450451
1. Let _completion_ be Completion(Yield(_mapped_)).
451452
1. IfAbruptCloseIterator(_completion_, _iterated_).
453+
1. Set _counter_ to _counter_ + 1.
452454
1. Return CreateIteratorFromClosure(_closure_, ~Iterator Helper~, %IteratorHelperPrototype%).
453455
</emu-alg>
454456
</emu-clause>
@@ -459,15 +461,17 @@ <h1>Iterator.prototype.filter ( _filterer_ )</h1>
459461
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
460462
1. If IsCallable(_filterer_) is *false*, throw a *TypeError* exception.
461463
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.
462465
1. Repeat,
463466
1. Let _next_ be ? IteratorStep(_iterated_).
464467
1. If _next_ is *false*, return *undefined*.
465468
1. Let _value_ be ? IteratorValue(_next_).
466-
1. Let _selected_ be Completion(Call(_filterer_, *undefined*, &laquo; _value_ &raquo;)).
469+
1. Let _selected_ be Completion(Call(_filterer_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
467470
1. IfAbruptCloseIterator(_selected_, _iterated_).
468471
1. If ToBoolean(_selected_) is *true*, then
469472
1. Let _completion_ be Completion(Yield(_value_)).
470473
1. IfAbruptCloseIterator(_completion_, _iterated_).
474+
1. Set _counter_ to _counter_ + 1.
471475
1. Return CreateIteratorFromClosure(_closure_, ~Iterator Helper~, %IteratorHelperPrototype%).
472476
</emu-alg>
473477
</emu-clause>
@@ -530,9 +534,9 @@ <h1>Iterator.prototype.indexed ( )</h1>
530534
1. If _next_ is *false*, return *undefined*.
531535
1. Let _value_ be ? IteratorValue(_next_).
532536
1. Let _pair_ be CreateArrayFromList(&laquo; 𝔽(_index_), _value_ &raquo;).
533-
1. Set _index_ to _index_ + 1.
534537
1. Let _completion_ be Completion(Yield(_pair_)).
535538
1. IfAbruptCloseIterator(_completion_, _iterated_).
539+
1. Set _index_ to _index_ + 1.
536540
1. Return CreateIteratorFromClosure(_closure_, ~Iterator Helper~, %IteratorHelperPrototype%).
537541
</emu-alg>
538542
</emu-clause>
@@ -543,11 +547,12 @@ <h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
543547
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
544548
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
545549
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.
546551
1. Repeat,
547552
1. Let _next_ be ? IteratorStep(_iterated_).
548553
1. If _next_ is *false*, return *undefined*.
549554
1. Let _value_ be ? IteratorValue(_next_).
550-
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, &laquo; _value_ &raquo;)).
555+
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
551556
1. IfAbruptCloseIterator(_mapped_, _iterated_).
552557
1. Let _innerIterator_ be Completion(GetIterator(_mapped_, ~sync~)).
553558
1. IfAbruptCloseIterator(_innerIterator_, _iterated_).
@@ -565,6 +570,7 @@ <h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
565570
1. Let _backupCompletion_ be Completion(IteratorClose(_innerIterator_, _completion_)).
566571
1. IfAbruptCloseIterator(_backupCompletion_, _iterated_).
567572
1. Return ? IteratorClose(_completion_, _iterated_).
573+
1. Set _counter_ to _counter_ + 1.
568574
1. Return CreateIteratorFromClosure(_closure_, ~Iterator Helper~, %IteratorHelperPrototype%).
569575
</emu-alg>
570576
</emu-clause>
@@ -580,13 +586,15 @@ <h1>Iterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )</h1>
580586
1. Let _accumulator_ be ? IteratorValue(_next_).
581587
1. Else,
582588
1. Let _accumulator_ be _initialValue_.
589+
1. Let _counter_ be 0.
583590
1. Repeat,
584591
1. Let _next_ be ? IteratorStep(_iterated_).
585592
1. If _next_ is *false*, return _accumulator_.
586593
1. Let _value_ be ? IteratorValue(_next_).
587-
1. Let _result_ be Completion(Call(_reducer_, *undefined*, &laquo; _accumulator_, _value_ &raquo;)).
594+
1. Let _result_ be Completion(Call(_reducer_, *undefined*, &laquo; _accumulator_, _value_, 𝔽(_counter_) &raquo;)).
588595
1. IfAbruptCloseIterator(_result_, _iterated_).
589596
1. Set _accumulator_ to _result_.[[Value]].
597+
1. Set _counter_ to _counter_ + 1.
590598
</emu-alg>
591599
</emu-clause>
592600

@@ -619,12 +627,14 @@ <h1>Iterator.prototype.forEach ( _fn_ )</h1>
619627
<emu-alg>
620628
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
621629
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
630+
1. Let _counter_ be 0.
622631
1. Repeat,
623632
1. Let _next_ be ? IteratorStep(_iterated_).
624633
1. If _next_ is *false*, return *undefined*.
625634
1. Let _value_ be ? IteratorValue(_next_).
626-
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_ &raquo;)).
635+
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
627636
1. IfAbruptCloseIterator(_result_, _iterated_).
637+
1. Set _counter_ to _counter_ + 1.
628638
</emu-alg>
629639
</emu-clause>
630640

@@ -633,13 +643,15 @@ <h1>Iterator.prototype.some ( _fn_ )</h1>
633643
<emu-alg>
634644
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
635645
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
646+
1. Let _counter_ be 0.
636647
1. Repeat,
637648
1. Let _next_ be ? IteratorStep(_iterated_).
638649
1. If _next_ is *false*, return *false*.
639650
1. Let _value_ be ? IteratorValue(_next_).
640-
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_ &raquo;)).
651+
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
641652
1. IfAbruptCloseIterator(_result_, _iterated_).
642653
1. If ToBoolean(_result_) is *true*, return ? IteratorClose(_iterated_, NormalCompletion(*true*)).
654+
1. Set _counter_ to _counter_ + 1.
643655
</emu-alg>
644656
</emu-clause>
645657

@@ -648,13 +660,15 @@ <h1>Iterator.prototype.every ( _fn_ )</h1>
648660
<emu-alg>
649661
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
650662
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
663+
1. Let _counter_ be 0.
651664
1. Repeat,
652665
1. Let _next_ be ? IteratorStep(_iterated_).
653666
1. If _next_ is *false*, return *true*.
654667
1. Let _value_ be ? IteratorValue(_next_).
655-
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_ &raquo;)).
668+
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
656669
1. IfAbruptCloseIterator(_result_, _iterated_).
657670
1. If ToBoolean(_result_) is *false*, return ? IteratorClose(_iterated_, NormalCompletion(*false*)).
671+
1. Set _counter_ to _counter_ + 1.
658672
</emu-alg>
659673
</emu-clause>
660674

@@ -663,13 +677,15 @@ <h1>Iterator.prototype.find ( _fn_ )</h1>
663677
<emu-alg>
664678
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
665679
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
680+
1. Let _counter_ be 0.
666681
1. Repeat,
667682
1. Let _next_ be ? IteratorStep(_iterated_).
668683
1. If _next_ is *false*, return *undefined*.
669684
1. Let _value_ be ? IteratorValue(_next_).
670-
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_ &raquo;)).
685+
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
671686
1. IfAbruptCloseIterator(_result_, _iterated_).
672687
1. If ToBoolean(_result_) is *true*, return ? IteratorClose(_iterated_, NormalCompletion(_value_)).
688+
1. Set _counter_ to _counter_ + 1.
673689
</emu-alg>
674690
</emu-clause>
675691

@@ -700,16 +716,18 @@ <h1>AsyncIterator.prototype.map ( _mapper_ )</h1>
700716
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
701717
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
702718
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.
703720
1. Repeat,
704721
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
705722
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
706723
1. Let _value_ be ? IteratorValue(_next_).
707-
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, &laquo; _value_ &raquo;)).
724+
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
708725
1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_).
709726
1. Set _mapped_ to Completion(Await(_mapped_)).
710727
1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_).
711728
1. Let _completion_ be Completion(Yield(_mapped_)).
712729
1. IfAbruptCloseAsyncIterator(_completion_, _iterated_).
730+
1. Set _counter_ to _counter_ + 1.
713731
1. Return CreateAsyncIteratorFromClosure(_closure_, ~Async Iterator Helper~, %AsyncIteratorHelperPrototype%).
714732
</emu-alg>
715733
</emu-clause>
@@ -720,17 +738,19 @@ <h1>AsyncIterator.prototype.filter ( _filterer_ )</h1>
720738
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
721739
1. If IsCallable(_filterer_) is *false*, throw a *TypeError* exception.
722740
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.
723742
1. Repeat,
724743
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
725744
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
726745
1. Let _value_ be ? IteratorValue(_next_).
727-
1. Let _selected_ be Completion(Call(_filterer_, *undefined*, &laquo; _value_ &raquo;)).
746+
1. Let _selected_ be Completion(Call(_filterer_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
728747
1. IfAbruptCloseAsyncIterator(_selected_, _iterated_).
729748
1. Set _selected_ to Completion(Await(_selected_)).
730749
1. IfAbruptCloseAsyncIterator(_selected_, _iterated_).
731750
1. If ToBoolean(_selected_) is *true*, then
732751
1. Let _completion_ be Completion(Yield(_value_)).
733752
1. IfAbruptCloseAsyncIterator(_completion_, _iterated_).
753+
1. Set _counter_ to _counter_ + 1.
734754
1. Return CreateAsyncIteratorFromClosure(_closure_, ~Async Iterator Helper~, %AsyncIteratorHelperPrototype%).
735755
</emu-alg>
736756
</emu-clause>
@@ -793,9 +813,9 @@ <h1>AsyncIterator.prototype.indexed ( )</h1>
793813
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
794814
1. Let _value_ be ? IteratorValue(_next_).
795815
1. Let _pair_ be CreateArrayFromList(&laquo; _index_, _value_ &raquo;).
796-
1. Set _index_ to _index_ + 1.
797816
1. Let _completion_ be Completion(Yield(_pair_)).
798817
1. IfAbruptCloseAsyncIterator(_completion_, _iterated_).
818+
1. Set _index_ to _index_ + 1.
799819
1. Return CreateAsyncIteratorFromClosure(_closure_, ~Async Iterator Helper~, %AsyncIteratorHelperPrototype%).
800820
</emu-alg>
801821
</emu-clause>
@@ -807,11 +827,12 @@ <h1>AsyncIterator.prototype.flatMap ( _mapper_ )</h1>
807827
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
808828
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
809829
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.
810831
1. Repeat,
811832
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
812833
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
813834
1. Let _value_ be ? IteratorValue(_next_).
814-
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, &laquo; _value_ &raquo;)).
835+
1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
815836
1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_).
816837
1. Set _mapped_ to Completion(Await(_mapped_)).
817838
1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_).
@@ -838,6 +859,7 @@ <h1>AsyncIterator.prototype.flatMap ( _mapper_ )</h1>
838859
1. Else if _completion_ is a throw completion, then
839860
1. Assert: Awaiting _innerValue_ during the Yield on step <emu-xref href="#step-async-iterator-flatmap-yield"></emu-xref> threw.
840861
1. Return ? IteratorClose(_completion_, _iterated_).
862+
1. Set _counter_ to _counter_ + 1.
841863
1. Return CreateAsyncIteratorFromClosure(_closure_, ~Async Iterator Helper~, %AsyncIteratorHelperPrototype%).
842864
</emu-alg>
843865
</emu-clause>
@@ -853,15 +875,17 @@ <h1>AsyncIterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )</h1>
853875
1. Let _accumulator_ be ? IteratorValue(_next_).
854876
1. Else,
855877
1. Let _accumulator_ be _initialValue_.
878+
1. Let _counter_ be 0.
856879
1. Repeat,
857880
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
858881
1. If ? IteratorComplete(_next_) is *true*, return _accumulator_.
859882
1. Let _value_ be ? IteratorValue(_next_).
860-
1. Let _result_ be Completion(Call(_reducer_, *undefined*, &laquo; _accumulator_, _value_ &raquo;)).
883+
1. Let _result_ be Completion(Call(_reducer_, *undefined*, &laquo; _accumulator_, _value_, 𝔽(_counter_) &raquo;)).
861884
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
862885
1. Set _result_ to Await(_result_).
863886
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
864887
1. Set _accumulator_ to _result_.
888+
1. Set _counter_ to _counter_ + 1.
865889
</emu-alg>
866890
</emu-clause>
867891

@@ -885,14 +909,16 @@ <h1>AsyncIterator.prototype.forEach ( _fn_ )</h1>
885909
<emu-alg>
886910
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
887911
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
912+
1. Let _counter_ be 0.
888913
1. Repeat,
889914
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
890915
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
891916
1. Let _value_ be ? IteratorValue(_next_).
892-
1. Let _r_ be Completion(Call(_fn_, *undefined*, &laquo; _value_ &raquo;)).
917+
1. Let _r_ be Completion(Call(_fn_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
893918
1. IfAbruptCloseAsyncIterator(_r_, _iterated_).
894919
1. Set _r_ to Await(r).
895920
1. IfAbruptCloseAsyncIterator(_r_, _iterated_).
921+
1. Set _counter_ to _counter_ + 1.
896922
</emu-alg>
897923
</emu-clause>
898924

@@ -902,15 +928,17 @@ <h1>AsyncIterator.prototype.some ( _fn_ )</h1>
902928
<emu-alg>
903929
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
904930
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
931+
1. Let _counter_ be 0.
905932
1. Repeat,
906933
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
907934
1. If ? IteratorComplete(_next_) is *true*, return *false*.
908935
1. Let _value_ be ? IteratorValue(_next_).
909-
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_ &raquo;)).
936+
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
910937
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
911938
1. Set _result_ to Await(_result_).
912939
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
913940
1. If ToBoolean(_result_) is *true*, return ? AsyncIteratorClose(_iterated_, NormalCompletion(*true*)).
941+
1. Set _counter_ to _counter_ + 1.
914942
</emu-alg>
915943
</emu-clause>
916944

@@ -920,15 +948,17 @@ <h1>AsyncIterator.prototype.every ( _fn_ )</h1>
920948
<emu-alg>
921949
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
922950
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
951+
1. Let _counter_ be 0.
923952
1. Repeat,
924953
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
925954
1. If ? IteratorComplete(_next_) is *true*, return *true*.
926955
1. Let _value_ be ? IteratorValue(_next_).
927-
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_ &raquo;)).
956+
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
928957
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
929958
1. Set _result_ to Await(_result_).
930959
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
931960
1. If ToBoolean(_result_) is *false*, return ? AsyncIteratorClose(_iterated_, NormalCompletion(*false*)).
961+
1. Set _counter_ to _counter_ + 1.
932962
</emu-alg>
933963
</emu-clause>
934964

@@ -938,15 +968,17 @@ <h1>AsyncIterator.prototype.find ( _fn_ )</h1>
938968
<emu-alg>
939969
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
940970
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
971+
1. Let _counter_ be 0.
941972
1. Repeat,
942973
1. Let _next_ be ? Await(? IteratorNext(_iterated_)).
943974
1. If ? IteratorComplete(_next_) is *true*, return *undefined*.
944975
1. Let _value_ be ? IteratorValue(_next_).
945-
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_ &raquo;)).
976+
1. Let _result_ be Completion(Call(_fn_, *undefined*, &laquo; _value_, 𝔽(_counter_) &raquo;)).
946977
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
947978
1. Set _result_ to Await(_result_).
948979
1. IfAbruptCloseAsyncIterator(_result_, _iterated_).
949980
1. If ToBoolean(_result_) is *true*, return ? AsyncIteratorClose(_iterated_, NormalCompletion(_value_)).
981+
1. Set _counter_ to _counter_ + 1.
950982
</emu-alg>
951983
</emu-clause>
952984

0 commit comments

Comments
 (0)