-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Editorial: Early return & throw in Number.prototype.to* methods #1938
Editorial: Early return & throw in Number.prototype.to* methods #1938
Conversation
With this change, it is easier to spot a discrepancy in handling of non-finite 0..toExponential(-1) // RangeError
0..toFixed(-1) // RangeError
0..toPrecision(-1) // RangeError
NaN.toExponential(-1) // => "NaN"
NaN.toFixed(-1) // RangeError
NaN.toPrecision(-1) // => "NaN" Would you consider a normative PR to align it? We can either a) move range check after finiteness check in a) is most certainly web-compatible, and it makes sense to perform all checks on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks observably equivalent.
@shvaikalesh regarding #1938 (comment), it seems like you're suggesting either a) making The latter seems unlikely to be web compatible, and the former does not seem desirable. Can you elaborate? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like handling special cases as early as possible and this does appear to be equivalent.
My only argument for the normative change is consistency, but it doesn't justify adding undesirable behavior. While all built-in methods check |
d838104
to
1ac5c6e
Compare
PR tc39#1938 (among other things) modified the steps of Number.prototype.toExponential, but didn't update the step-reference in the following Note.
PR tc39#1938 (among other things) modified the steps of Number.prototype.toExponential, but didn't update the step-reference in the following Note.
PR tc39#1938 (among other things) modified the steps of Number.prototype.toExponential, but didn't update the step-reference in the following Note.
This change makes handling of non-finite
this
values more concise (by usingNumber::toString
) and moves it earlier in steps, as well as argument range checks. This makes observable steps grouped and order of observable steps easier to read (especially if a runtime uses something likestd::isfinite
as JSC does).