From 3ec20470c547f36f71fe2ec6e7c1ea98eea41840 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Sun, 3 Nov 2024 15:03:44 -0800 Subject: [PATCH 1/2] Normative: iterator-producing helpers close receiver on argument validation failure --- spec.html | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/spec.html b/spec.html index 652ddce78b..48ebc5fe3a 100644 --- a/spec.html +++ b/spec.html @@ -46759,11 +46759,17 @@

Iterator.prototype.drop ( _limit_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. Let _numLimit_ be ? ToNumber(_limit_). - 1. If _numLimit_ is *NaN*, throw a *RangeError* exception. + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. Let _numLimit_ be Completion(ToNumber(_limit_)). + 1. IfAbruptCloseIterator(_numLimit_, _iterated_). + 1. If _numLimit_ is *NaN*, then + 1. Let _error_ be ThrowCompletion(a newly created *RangeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). 1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_). - 1. If _integerLimit_ < 0, throw a *RangeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. If _integerLimit_ < 0, then + 1. Let _error_ be ThrowCompletion(a newly created *RangeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called: 1. Let _remaining_ be _integerLimit_. 1. Repeat, while _remaining_ > 0, @@ -46807,8 +46813,11 @@

Iterator.prototype.filter ( _predicate_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. If IsCallable(_predicate_) is *false*, then + 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _predicate_ and performs the following steps when called: 1. Let _counter_ be 0. 1. Repeat, @@ -46851,8 +46860,11 @@

Iterator.prototype.flatMap ( _mapper_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. If IsCallable(_mapper_) is *false*, then + 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 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, @@ -46905,8 +46917,11 @@

Iterator.prototype.map ( _mapper_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If IsCallable(_mapper_) is *false*, throw a *TypeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. If IsCallable(_mapper_) is *false*, then + 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 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, @@ -46973,11 +46988,17 @@

Iterator.prototype.take ( _limit_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. Let _numLimit_ be ? ToNumber(_limit_). - 1. If _numLimit_ is *NaN*, throw a *RangeError* exception. + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. Let _numLimit_ be Completion(ToNumber(_limit_)). + 1. IfAbruptCloseIterator(_numLimit_, _iterated_). + 1. If _numLimit_ is *NaN*, then + 1. Let _error_ be ThrowCompletion(a newly created *RangeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). 1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_). - 1. If _integerLimit_ < 0, throw a *RangeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. If _integerLimit_ < 0, then + 1. Let _error_ be ThrowCompletion(a newly created *RangeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 1. Let _closure_ be a new Abstract Closure with no parameters that captures _iterated_ and _integerLimit_ and performs the following steps when called: 1. Let _remaining_ be _integerLimit_. 1. Repeat, From c4ab60c62db7a92e05c3a41c9f80302488203475 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Sun, 3 Nov 2024 15:05:44 -0800 Subject: [PATCH 2/2] Normative: consuming helpers close receiver on argument validation failure --- spec.html | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/spec.html b/spec.html index 48ebc5fe3a..382726d939 100644 --- a/spec.html +++ b/spec.html @@ -46794,8 +46794,11 @@

Iterator.prototype.every ( _predicate_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. If IsCallable(_predicate_) is *false*, then + 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 1. Let _counter_ be 0. 1. Repeat, 1. Let _value_ be ? IteratorStepValue(_iterated_). @@ -46841,8 +46844,11 @@

Iterator.prototype.find ( _predicate_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. If IsCallable(_predicate_) is *false*, then + 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 1. Let _counter_ be 0. 1. Repeat, 1. Let _value_ be ? IteratorStepValue(_iterated_). @@ -46899,8 +46905,11 @@

Iterator.prototype.forEach ( _procedure_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If IsCallable(_procedure_) is *false*, throw a *TypeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. If IsCallable(_procedure_) is *false*, then + 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 1. Let _counter_ be 0. 1. Repeat, 1. Let _value_ be ? IteratorStepValue(_iterated_). @@ -46944,8 +46953,11 @@

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

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If IsCallable(_reducer_) is *false*, throw a *TypeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. If IsCallable(_reducer_) is *false*, then + 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 1. If _initialValue_ is not present, then 1. Let _accumulator_ be ? IteratorStepValue(_iterated_). 1. If _accumulator_ is ~done~, throw a *TypeError* exception. @@ -46969,8 +46981,11 @@

Iterator.prototype.some ( _predicate_ )

1. Let _O_ be the *this* value. 1. If _O_ is not an Object, throw a *TypeError* exception. - 1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception. - 1. Let _iterated_ be ? GetIteratorDirect(_O_). + 1. Let _iterated_ be the Iterator Record { [[Iterator]]: _O_, [[NextMethod]]: *undefined*, [[Done]]: *false* }. + 1. If IsCallable(_predicate_) is *false*, then + 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). + 1. Return ? IteratorClose(_iterated_, _error_). + 1. Set _iterated_ to ? GetIteratorDirect(_O_). 1. Let _counter_ be 0. 1. Repeat, 1. Let _value_ be ? IteratorStepValue(_iterated_).