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

fixes #169: throw a RangeError in take/drop when input is NaN-ish #181

Merged
merged 1 commit into from Jul 5, 2022
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
8 changes: 6 additions & 2 deletions spec.html
Expand Up @@ -533,7 +533,9 @@ <h1>%Iterator.prototype%.filter ( _filterer_ )</h1>
<h1>%Iterator.prototype%.take ( _limit_ )</h1>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _integerLimit_ be ? ToIntegerOrInfinity(_limit_).
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 _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_.
Expand All @@ -555,7 +557,9 @@ <h1>%Iterator.prototype%.take ( _limit_ )</h1>
<h1>%Iterator.prototype%.drop ( _limit_ )</h1>
<emu-alg>
1. Let _iterated_ be ? GetIteratorDirect(*this* value).
1. Let _integerLimit_ be ? ToIntegerOrInfinity(_limit_).
1. Let _numLimit_ be ? ToNumber(_limit_).
1. If _numLimit_ is *NaN*, throw a *RangeError* exception.
1. Let _integerLimit_ be ! ToIntegerOrInfinity(_numLimit_).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if integerLimit is not in the safe integer range?

For example, in the case of Number.MAX_SAFE_INTEGER + 2 it will never take a value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This iteration happens on mathematical values, not floats, so the max safe integer for floats doesn't come into play at all here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reasonable. It seems necessary to think about what should be used in polyfills for such cases.

Copy link
Collaborator

@bakkot bakkot Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use a BigInt, but honestly, your computer is going to run out of time/memory before it runs into this problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterator helper is one of the solutions for preventing out of memory in such cases and 2**53 is not such a big value that it can't happen for some years of a server work -) BigInt directly will not work for old env. However, I agree that there are many more priority tasks.

1. If _integerLimit_ &lt; 0, throw a *RangeError* exception.
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_.
Expand Down