Skip to content

Commit 9552f29

Browse files
bakkotljharb
authored andcommitted
Normative: iterator-producing helpers close receiver on argument validation failure (#3467)
1 parent e2da759 commit 9552f29

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
@@ -47356,11 +47356,17 @@ <h1>Iterator.prototype.drop ( _limit_ )</h1>
4735647356
<emu-alg>
4735747357
1. Let _O_ be the *this* value.
4735847358
1. If _O_ is not an Object, throw a *TypeError* exception.
47359-
1. Let _numLimit_ be ? ToNumber(_limit_).
47360-
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
47359+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
47360+
1. Let _numLimit_ be Completion(ToNumber(_limit_)).
47361+
1. IfAbruptCloseIterator(_numLimit_, _iterated_).
47362+
1. If _numLimit_ is *NaN*, then
47363+
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
47364+
1. Return ? IteratorClose(_iterated_, _error_).
4736147365
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
47362-
1. If _integerLimit_ &lt; 0, throw a *RangeError* exception.
47363-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
47366+
1. If _integerLimit_ &lt; 0, then
47367+
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
47368+
1. Return ? IteratorClose(_iterated_, _error_).
47369+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4736447370
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called:
4736547371
1. Let _remaining_ be _integerLimit_.
4736647372
1. Repeat, while _remaining_ > 0,
@@ -47404,8 +47410,11 @@ <h1>Iterator.prototype.filter ( _predicate_ )</h1>
4740447410
<emu-alg>
4740547411
1. Let _O_ be the *this* value.
4740647412
1. If _O_ is not an Object, throw a *TypeError* exception.
47407-
1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception.
47408-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
47413+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
47414+
1. If IsCallable(_predicate_) is *false*, then
47415+
1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
47416+
1. Return ? IteratorClose(_iterated_, _error_).
47417+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4740947418
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _predicate_ and performs the following steps when called:
4741047419
1. Let _counter_ be 0.
4741147420
1. Repeat,
@@ -47448,8 +47457,11 @@ <h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
4744847457
<emu-alg>
4744947458
1. Let _O_ be the *this* value.
4745047459
1. If _O_ is not an Object, throw a *TypeError* exception.
47451-
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
47452-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
47460+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
47461+
1. If IsCallable(_mapper_) is *false*, then
47462+
1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
47463+
1. Return ? IteratorClose(_iterated_, _error_).
47464+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4745347465
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
4745447466
1. Let _counter_ be 0.
4745547467
1. Repeat,
@@ -47502,8 +47514,11 @@ <h1>Iterator.prototype.map ( _mapper_ )</h1>
4750247514
<emu-alg>
4750347515
1. Let _O_ be the *this* value.
4750447516
1. If _O_ is not an Object, throw a *TypeError* exception.
47505-
1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception.
47506-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
47517+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
47518+
1. If IsCallable(_mapper_) is *false*, then
47519+
1. Let _error_ be ThrowCompletion(a newly created *TypeError* object).
47520+
1. Return ? IteratorClose(_iterated_, _error_).
47521+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4750747522
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _mapper_ and performs the following steps when called:
4750847523
1. Let _counter_ be 0.
4750947524
1. Repeat,
@@ -47570,11 +47585,17 @@ <h1>Iterator.prototype.take ( _limit_ )</h1>
4757047585
<emu-alg>
4757147586
1. Let _O_ be the *this* value.
4757247587
1. If _O_ is not an Object, throw a *TypeError* exception.
47573-
1. Let _numLimit_ be ? ToNumber(_limit_).
47574-
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
47588+
1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }.
47589+
1. Let _numLimit_ be Completion(ToNumber(_limit_)).
47590+
1. IfAbruptCloseIterator(_numLimit_, _iterated_).
47591+
1. If _numLimit_ is *NaN*, then
47592+
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
47593+
1. Return ? IteratorClose(_iterated_, _error_).
4757547594
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
47576-
1. If _integerLimit_ &lt; 0, throw a *RangeError* exception.
47577-
1. Let _iterated_ be ? GetIteratorDirect(_O_).
47595+
1. If _integerLimit_ &lt; 0, then
47596+
1. Let _error_ be ThrowCompletion(a newly created *RangeError* object).
47597+
1. Return ? IteratorClose(_iterated_, _error_).
47598+
1. Set _iterated_ to ? GetIteratorDirect(_O_).
4757847599
1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called:
4757947600
1. Let _remaining_ be _integerLimit_.
4758047601
1. Repeat,

0 commit comments

Comments
 (0)