-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Fix zero argument panic in JSON.parse() #785
Fix zero argument panic in JSON.parse() #785
Conversation
Codecov Report
@@ Coverage Diff @@
## master #785 +/- ##
==========================================
+ Coverage 59.13% 59.15% +0.01%
==========================================
Files 155 155
Lines 9838 9837 -1
==========================================
+ Hits 5818 5819 +1
+ Misses 4020 4018 -2
Continue to review full report at Codecov.
|
@JohnDoneth Two things:
So something like this might be better,
The Test-262 spec just asserts that SyntaxError is thrown, so I guess we are fine either way. https://github.com/tc39/test262/blob/main/test/built-ins/JSON/parse/text-non-string-primitive.js |
New output with changes made:
|
This matches more with what other engines are doing, and what the spec says :) |
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.
Looks good to me! :)
@JohnDoneth Thanks. Perhaps not related to the task (but a general error), but in Firefox it shows:
and in Chrome
It would be nice to have the error class and message in the output. I actually don't know if the correct error type is thrown in current implementation. |
I don't know if all errors in JSON::parse should be syntax errors (I'd appreciate if someone else can look into it), but for the Value that gets thrown to be an actual Error with a message this line: https://github.com/JohnDoneth/boa/blob/cfe64ae60065ca36e9bc45a7e7d46a29282abbfb/boa/src/builtins/json/mod.rs#L82 |
Good catch! @RageKnify, Yep. https://tc39.es/ecma262/#sec-json.parse step 2. |
There we go!
Thanks for spotting that @RageKnify |
Also we should have a test for that :D |
Although don't know what is the policy for the tests, now that we have Test-262 test suite, because this test will be a duplicate of https://github.com/tc39/test262/blob/main/test/built-ins/JSON/parse/text-non-string-primitive.js I even think tests might be a loss of time now. |
Yes some tests are duplicates but that is fine the rust tests catch the bigger bugs but the test262 catch all bugs and is not practical to run the test262 tests for when you want rough idea of what is broken since takes like 10m for them to finish, compared to |
This Pull Request closes #784.
It changes the following:
Instead of panicking when an argument is not provided to
JSON.parse()
, a syntax error is raised like other JavaScript implementations.