Skip to content

Commit 3ec2047

Browse files
committed
Normative: iterator-producing helpers close receiver on argument validation failure
1 parent 4c44bbe commit 3ec2047

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

spec.html

+35-14
Original file line numberDiff line numberDiff line change
@@ -46759,11 +46759,17 @@ <h1>Iterator.prototype.drop ( _limit_ )</h1>
4675946759
<emu-alg>
4676046760
1. Let _O_ be the *this* value.
4676146761
1. If _O_ is not an Object, throw a *TypeError* exception.
46762-
1. Let _numLimit_ be ? ToNumber(_limit_).
46763-
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
46762+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
46763+
1. Let _numLimit_ be Completion(ToNumber(_limit_)).
46764+
1. IfAbruptCloseIterator(_numLimit_, _iterated_).
46765+
1. If _numLimit_ is *NaN*, then
46766+
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
46767+
1. Return ? IteratorClose(_iterated_, _error_).
4676446768
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
46765-
1. If _integerLimit_ &lt; 0, throw a *RangeError* exception.
46766-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
46769+
1. If _integerLimit_ &lt; 0, then
46770+
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
46771+
1. Return ? IteratorClose(_iterated_, _error_).
46772+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4676746773
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called:
4676846774
1. Let _remaining_ be _integerLimit_.
4676946775
1. Repeat, while _remaining_ > 0,
@@ -46807,8 +46813,11 @@ <h1>Iterator.prototype.filter ( _predicate_ )</h1>
4680746813
<emu-alg>
4680846814
1. Let _O_ be the *this* value.
4680946815
1. If _O_ is not an Object, throw a *TypeError* exception.
46810-
1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception.
46811-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
46816+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
46817+
1. If IsCallable(_predicate_) is *false*, then
46818+
1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
46819+
1. Return ? IteratorClose(_iterated_, _error_).
46820+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4681246821
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _predicate_ and performs the following steps when called:
4681346822
1. Let _counter_ be 0.
4681446823
1. Repeat,
@@ -46851,8 +46860,11 @@ <h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
4685146860
<emu-alg>
4685246861
1. Let _O_ be the *this* value.
4685346862
1. If _O_ is not an Object, throw a *TypeError* exception.
46854-
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
46855-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
46863+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
46864+
1. If IsCallable(_mapper_) is *false*, then
46865+
1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
46866+
1. Return ? IteratorClose(_iterated_, _error_).
46867+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4685646868
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
4685746869
1. Let _counter_ be 0.
4685846870
1. Repeat,
@@ -46905,8 +46917,11 @@ <h1>Iterator.prototype.map ( _mapper_ )</h1>
4690546917
<emu-alg>
4690646918
1. Let _O_ be the *this* value.
4690746919
1. If _O_ is not an Object, throw a *TypeError* exception.
46908-
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
46909-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
46920+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
46921+
1. If IsCallable(_mapper_) is *false*, then
46922+
1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
46923+
1. Return ? IteratorClose(_iterated_, _error_).
46924+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4691046925
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
4691146926
1. Let _counter_ be 0.
4691246927
1. Repeat,
@@ -46973,11 +46988,17 @@ <h1>Iterator.prototype.take ( _limit_ )</h1>
4697346988
<emu-alg>
4697446989
1. Let _O_ be the *this* value.
4697546990
1. If _O_ is not an Object, throw a *TypeError* exception.
46976-
1. Let _numLimit_ be ? ToNumber(_limit_).
46977-
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
46991+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
46992+
1. Let _numLimit_ be Completion(ToNumber(_limit_)).
46993+
1. IfAbruptCloseIterator(_numLimit_, _iterated_).
46994+
1. If _numLimit_ is *NaN*, then
46995+
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
46996+
1. Return ? IteratorClose(_iterated_, _error_).
4697846997
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
46979-
1. If _integerLimit_ &lt; 0, throw a *RangeError* exception.
46980-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
46998+
1. If _integerLimit_ &lt; 0, then
46999+
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
47000+
1. Return ? IteratorClose(_iterated_, _error_).
47001+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4698147002
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called:
4698247003
1. Let _remaining_ be _integerLimit_.
4698347004
1. Repeat,

0 commit comments

Comments
 (0)