From f0b1f96c2072d46cdbdf35fba69f92129202ba55 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Tue, 9 Aug 2022 09:41:34 -0600 Subject: [PATCH] fixes #207: add a counter parameter to Array analogues that have them --- spec.html | 100 ++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/spec.html b/spec.html index b527d10..72598ff 100644 --- a/spec.html +++ b/spec.html @@ -452,14 +452,16 @@

Iterator.prototype.map ( _mapper_ )

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_ »)). + 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%). @@ -470,15 +472,17 @@

Iterator.prototype.filter ( _filterer_ )

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_ »)). + 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%). @@ -530,35 +534,18 @@

Iterator.prototype.drop ( _limit_ )

- -

Iterator.prototype.indexed ( )

- - 1. Let _iterated_ be ? GetIteratorDirect(*this* value). - 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and performs the following steps when called: - 1. Let _index_ 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 _pair_ be CreateArrayFromList(« 𝔽(_index_), _value_ »). - 1. Set _index_ to _index_ + 1. - 1. Let _completion_ be Completion(Yield(_pair_)). - 1. IfAbruptCloseIterator(_completion_, _iterated_). - 1. Return CreateIteratorFromClosure(_closure_, *"Iterator Helper"*, %IteratorHelperPrototype%). - -
-

Iterator.prototype.flatMap ( _mapper_ )

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_ »)). + 1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseIterator(_mapped_, _iterated_). 1. Let _innerIterator_ be Completion(GetIterator(_mapped_, ~sync~)). 1. IfAbruptCloseIterator(_innerIterator_, _iterated_). @@ -576,6 +563,7 @@

Iterator.prototype.flatMap ( _mapper_ )

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%).
@@ -591,13 +579,15 @@

Iterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )

1. Let _accumulator_ be ? IteratorValue(_next_). 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_ »)). + 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. @@ -630,12 +620,14 @@

Iterator.prototype.forEach ( _fn_ )

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_ »)). + 1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseIterator(_result_, _iterated_). + 1. Set _counter_ to _counter_ + 1. @@ -644,13 +636,15 @@

Iterator.prototype.some ( _fn_ )

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_ »)). + 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. @@ -659,13 +653,15 @@

Iterator.prototype.every ( _fn_ )

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_ »)). + 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. @@ -674,13 +670,15 @@

Iterator.prototype.find ( _fn_ )

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_ »)). + 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. @@ -713,16 +711,18 @@

AsyncIterator.prototype.map ( _mapper_ )

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_ »)). + 1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_). 1. Set _mapped_ to Completion(Await(_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%). @@ -733,17 +733,19 @@

AsyncIterator.prototype.filter ( _filterer_ )

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_ »)). + 1. Let _selected_ be Completion(Call(_filterer_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseAsyncIterator(_selected_, _iterated_). 1. Set _selected_ to Completion(Await(_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%). @@ -795,24 +797,6 @@

AsyncIterator.prototype.drop ( _limit_ )

- -

AsyncIterator.prototype.indexed ( )

- - 1. Let _iterated_ be ? GetIteratorDirect(*this* value). - 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and performs the following steps when called: - 1. Let _index_ 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 _pair_ be CreateArrayFromList(« _index_, _value_ »). - 1. Set _index_ to _index_ + 1. - 1. Let _completion_ be Completion(Yield(_pair_)). - 1. IfAbruptCloseAsyncIterator(_completion_, _iterated_). - 1. Return CreateAsyncIteratorFromClosure(_closure_, *"Async Iterator Helper"*, %AsyncIteratorHelperPrototype%). - -
-

AsyncIterator.prototype.flatMap ( _mapper_ )

AsyncIterator.prototype.flatMap is a built-in async generator function which, when called, performs the following steps:

@@ -820,11 +804,12 @@

AsyncIterator.prototype.flatMap ( _mapper_ )

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_ »)). + 1. Let _mapped_ be Completion(Call(_mapper_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_). 1. Set _mapped_ to Completion(Await(_mapped_)). 1. IfAbruptCloseAsyncIterator(_mapped_, _iterated_). @@ -851,6 +836,7 @@

AsyncIterator.prototype.flatMap ( _mapper_ )

1. Else if _completion_ is a throw completion, then 1. Assert: Awaiting _innerValue_ during the Yield on step threw. 1. Return ? IteratorClose(_completion_, _iterated_). + 1. Set _counter_ to _counter_ + 1. 1. Return CreateAsyncIteratorFromClosure(_closure_, *"Async Iterator Helper"*, %AsyncIteratorHelperPrototype%).
@@ -866,15 +852,17 @@

AsyncIterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )

1. Let _accumulator_ be ? IteratorValue(_next_). 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_ »)). + 1. Let _result_ be Completion(Call(_reducer_, *undefined*, « _accumulator_, _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseAsyncIterator(_result_, _iterated_). 1. Set _result_ to Await(_result_). 1. IfAbruptCloseAsyncIterator(_result_, _iterated_). 1. Set _accumulator_ to _result_. + 1. Set _counter_ to _counter_ + 1. @@ -898,14 +886,16 @@

AsyncIterator.prototype.forEach ( _fn_ )

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_ »)). + 1. Let _r_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseAsyncIterator(_r_, _iterated_). 1. Set _r_ to Await(r). 1. IfAbruptCloseAsyncIterator(_r_, _iterated_). + 1. Set _counter_ to _counter_ + 1. @@ -915,15 +905,17 @@

AsyncIterator.prototype.some ( _fn_ )

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_ »)). + 1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseAsyncIterator(_result_, _iterated_). 1. Set _result_ to Await(_result_). 1. IfAbruptCloseAsyncIterator(_result_, _iterated_). 1. If ToBoolean(_result_) is *true*, return ? AsyncIteratorClose(_iterated_, NormalCompletion(*true*)). + 1. Set _counter_ to _counter_ + 1. @@ -933,15 +925,17 @@

AsyncIterator.prototype.every ( _fn_ )

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_ »)). + 1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseAsyncIterator(_result_, _iterated_). 1. Set _result_ to Await(_result_). 1. IfAbruptCloseAsyncIterator(_result_, _iterated_). 1. If ToBoolean(_result_) is *false*, return ? AsyncIteratorClose(_iterated_, NormalCompletion(*false*)). + 1. Set _counter_ to _counter_ + 1. @@ -951,15 +945,17 @@

AsyncIterator.prototype.find ( _fn_ )

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 _result_ be Completion(Call(_fn_, *undefined*, « _value_ »)). + 1. Let _result_ be Completion(Call(_fn_, *undefined*, « _value_, 𝔽(_counter_) »)). 1. IfAbruptCloseAsyncIterator(_result_, _iterated_). 1. Set _result_ to Await(_result_). 1. IfAbruptCloseAsyncIterator(_result_, _iterated_). 1. If ToBoolean(_result_) is *true*, return ? AsyncIteratorClose(_iterated_, NormalCompletion(_value_)). + 1. Set _counter_ to _counter_ + 1.