Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative: validate arguments before opening iterator from this #265

Merged
merged 1 commit into from Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 34 additions & 13 deletions spec.html
Expand Up @@ -113,13 +113,12 @@ <h1>Operations on Iterator Objects</h1>
<emu-clause id="sec-getiteratordirect" type="abstract operation">
<h1>
GetIteratorDirect (
_obj_: an ECMAScript language value,
_obj_: an Object,
): either a normal completion containing an Iterator Record or a throw completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. If _obj_ is not an Object, throw a *TypeError* exception.
1. Let _nextMethod_ be ? Get(_obj_, `"next"`).
1. If IsCallable(_nextMethod_) is *false*, throw a *TypeError* exception.
1. Let _iteratorRecord_ be Record { [[Iterator]]: _obj_, [[NextMethod]]: _nextMethod_, [[Done]]: *false* }.
Expand Down Expand Up @@ -303,8 +302,10 @@ <h1>Iterator.prototype.constructor</h1>
<h1>Iterator.prototype.map ( _mapper_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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 _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,
Expand All @@ -324,8 +325,10 @@ <h1>Iterator.prototype.map ( _mapper_ )</h1>
<h1>Iterator.prototype.filter ( _predicate_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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 _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,
Expand All @@ -346,11 +349,13 @@ <h1>Iterator.prototype.filter ( _predicate_ )</h1>
<h1>Iterator.prototype.take ( _limit_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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 _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
1. If _integerLimit_ &lt; 0, throw a *RangeError* exception.
1. Let _iterated_ be ? 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,
Expand All @@ -370,11 +375,13 @@ <h1>Iterator.prototype.take ( _limit_ )</h1>
<h1>Iterator.prototype.drop ( _limit_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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 _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
1. If _integerLimit_ &lt; 0, throw a *RangeError* exception.
1. Let _iterated_ be ? 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,
Expand All @@ -395,8 +402,10 @@ <h1>Iterator.prototype.drop ( _limit_ )</h1>
<h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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 _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,
Expand Down Expand Up @@ -430,8 +439,10 @@ <h1>Iterator.prototype.flatMap ( _mapper_ )</h1>
<h1>Iterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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. If _initialValue_ is not present, then
1. Let _next_ be ? IteratorStep(_iterated_).
1. If _next_ is *false*, throw a *TypeError* exception.
Expand All @@ -455,7 +466,9 @@ <h1>Iterator.prototype.reduce ( _reducer_ [ , _initialValue_ ] )</h1>
<h1>Iterator.prototype.toArray ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _O_ be the *this* value.
1. If _O_ is not an Object, throw a *TypeError* exception.
1. Let _iterated_ be ? GetIteratorDirect(_O_).
1. Let _items_ be a new empty List.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
Expand All @@ -469,8 +482,10 @@ <h1>Iterator.prototype.toArray ( )</h1>
<h1>Iterator.prototype.forEach ( _fn_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _O_ be the *this* value.
1. If _O_ is not an Object, throw a *TypeError* exception.
1. If IsCallable(_fn_) is *false*, throw a *TypeError* exception.
1. Let _iterated_ be ? GetIteratorDirect(_O_).
1. Let _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
Expand All @@ -486,8 +501,10 @@ <h1>Iterator.prototype.forEach ( _fn_ )</h1>
<h1>Iterator.prototype.some ( _predicate_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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 _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
Expand All @@ -504,8 +521,10 @@ <h1>Iterator.prototype.some ( _predicate_ )</h1>
<h1>Iterator.prototype.every ( _predicate_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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 _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
Expand All @@ -522,8 +541,10 @@ <h1>Iterator.prototype.every ( _predicate_ )</h1>
<h1>Iterator.prototype.find ( _predicate_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
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 _counter_ be 0.
1. Repeat,
1. Let _next_ be ? IteratorStep(_iterated_).
Expand Down