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

Weird behavior with JSON builtin #269

Closed
zebp opened this issue Mar 8, 2020 · 2 comments
Closed

Weird behavior with JSON builtin #269

zebp opened this issue Mar 8, 2020 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@zebp
Copy link

zebp commented Mar 8, 2020

The JSON built in currently has a few issues that are thankfully easy to fix.Currently the JSON.stringify and JSON.parse are undefined and expect you to specify the JSON builtin's prototype.

The second issue is that the function JSON.stringify (accessed through JSON.prototype.stringify) returns unexpected output.

Example:

JSON.prototype.stringify({ number: 1 }) // Currently evaluates to "{ "extensible": true }"

This issue seems to be caused by this line using the internal_slots instead of the object's properties.

If you want I could submit a PR to fix these issues.

@jasonwilliams
Copy link
Member

jasonwilliams commented Mar 8, 2020

Yes please @vlakreeh i don't know why its iterating through internal slots there instead of properties, seems odd. Looks like a change i made but not sure why i did that.
I think the JSON builtin needs some tests similar to the others

And yes you can just point prototype to Object.prototype

https://github.com/jasonwilliams/boa/blob/master/boa/src/builtins/json.rs#L33 can also go as its ordinary by default

@Razican Razican added the bug Something isn't working label Apr 3, 2020
@jasonwilliams jasonwilliams added this to the v0.8.0 milestone Apr 12, 2020
@Razican
Copy link
Member

Razican commented May 7, 2020

I think that #325 solved the first issue described here, and the other issue seems to be solved. If I run:

JSON.stringify({ number: 1 })

I get:

{"number":1}

And, in a more complex scenario:

let a = JSON.stringify({ number: 1 });
let b = JSON.parse(a);
b.number;

I get 1.

So I'm closing this issue.

@Razican Razican closed this as completed May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants