-
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
Normative: only coerce once in BigInt constructor #2812
Conversation
haha oh no |
@bakkot So
|
@apaprocki The Date constructor has a similar pattern but is currently specified correctly: it does (That second line does want a |
Ah, my brain read what you wrote (without seeing the 1-line diff) and thought this was to fix behavior to match the spec as opposed to the other way around. Thanks! |
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.
Wow thanks for the fix 😳
Tests: tc39/test262#3631 |
0374d6a
to
f512200
Compare
(This was raised on the discourse.)
Consider
Per spec this should print
called
twice and complete normally - step 3 of the BigInt constructor will observe that the first call toToPrimitive
returns a value which is not a number and then step 4 will invokeToBigInt
on the original, pre-coercion value, which will invokeSymbol.toPrimitive
again.In V8, SpiderMonkey, JavaScriptCore, and XS, this code will in fact only print
called
once and then throw aTypeError
because the initial'string'
can't be coerced to a BigInt - i.e., in step 4 they use the post-coercion value, not the pre-coercion value. That's the behavior proposed in this PR.GraalJS and Engine262 implement the spec faithfully.