-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Implement the optional space
parameter in JSON.stringify
#961
Conversation
Codecov Report
@@ Coverage Diff @@
## master #961 +/- ##
==========================================
+ Coverage 59.40% 59.49% +0.09%
==========================================
Files 166 166
Lines 10717 10752 +35
==========================================
+ Hits 6366 6397 +31
- Misses 4351 4355 +4
Continue to review full report at Codecov.
|
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, but needs a fix:
JSON.stringify({a: "b", b: "c"}, undefined, 4)
will return {"a":"b","b":"c"}
when it should not.
The code relative to replacer
needs to not return immediately, the implementation doesn't follow the spec closely, so I'm not sure as to how we should aproach, but it's a test case to add (I'd say to change your tests with {}
as the replacer to use undefined
instead).
#919 implements ToIntegerOrInfinity
, which could be used to more closely follow the spec, but I don't think it's a big problem.
Thanks for your review and comments. Let's wait for #919 to be merged, so that |
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.
Sorry to bother, but I do think we should use undefined
in all of these cases, the spec only uses the 2nd argument when it is a function or array, I'd rather we leave it as undefined
to be clear that it is not used.
Co-authored-by: João Borges <[email protected]>
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, we'll just wait for #919 to use ToIntegerOrInfinity
I have run the test space-string-object.js. It passes on this branch but it also passes on cargo run --release --bin boa_tester -- run -s test/built-ins/JSON/stringify/space-string-object.js -vv It is probably a dumb question, and I might have missed something, but why is it pass on |
That test only checks if pairs of invocations return the same result, it never checks if the results follow the spec. So we get: >> JSON.stringify(obj, null, 'xxx')
"{"a1":{"b1":[1,2,3,4],"b2":{"c1":1,"c2":2}},"a2":"a2"}"
>> JSON.stringify(obj, null, new String('xxx'))
"{"a1":{"b1":[1,2,3,4],"b2":{"c1":1,"c2":2}},"a2":"a2"}" Being equal and we pass the test. edit: space-number.js is an example that should failt in |
Thanks for the explanation. I have run space-number.js and also space-string.js on |
My bad for not reading the test carefully, just like the other one, it only checks if the results match, since we never use the arguments it passes the test. |
It is right for space-number.js, but space-string.js makes an actual comparison with the expected indented string in the second assert. It should probably be failed on |
I finally found why the tests are passed on In boa/boa/src/syntax/lexer/cursor.rs Lines 222 to 230 in 0c068cb
But the tokenizer for single line comments expects a LF to end a comment, and not a CR. boa/boa/src/syntax/lexer/comment.rs Lines 33 to 40 in 0c068cb
As I work on Windows, and the test262 repository is cloned with CRLF endings on Windows, so all tests starting with single line comments are passed, as they are considered empty. Fixing |
I have merged the PR, so a rebase should fix that. Test262 conformance changes:
|
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 good to me, It seems it follows the spec correctly, even though it's not following it step by step exactly. Still, I think it makes sense to do it this way, since the result is the same and it might be a bit more optimized.
One less panic, 3 new extra tests passing, seems nice :)
In fact, using |
I don't think that would be the case @tofpie the spec only enters step 6. if the type is |
Thanks for the clarification. I understand now. Sorry I did not get it earlier. |
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.
LGTM, I'll let @Razican have a final look at the code
Looks good to me :) thanks! |
This Pull Request fixes/closes #346 .
It changes the following:
JSON.stringify()
now supportsspace
parameter