-
-
Notifications
You must be signed in to change notification settings - Fork 407
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 cyclic JSON.stringify / primitive conversion stack overflows #777
Conversation
These tests currently fail by overflowing the stack. Value comparisons are drawn from what Chrome and Firefox do, which doesn't appear to be in the spec?
This test is likely to be broken by the next change
We can use the existing RecursionLimiter type used by GcObject's Debug impl for this purpose. We just need to refactor it to allow both liveness and visitation tracking, using a HashMap of ptrs to states instead of a HashSet of ptrs.
Use the newly refactored RecursionLimiter to check for recursion, and limit it. Throw a TypeError as mandated by the spec.
Use the new RecursionLimiter type to prevent overflows from conversions in ordinary_to_primitive. The spec doesn't say what to do here, so we follow v8 / SpiderMonkey in returning a default value for the type hint -- either 0. or "". More details in the method documentation.
Someone added `as_gc_object` right as I added `add_gcobject`. What are the chances? Switched to the new method.
Codecov Report
@@ Coverage Diff @@
## master #777 +/- ##
==========================================
+ Coverage 59.21% 59.54% +0.33%
==========================================
Files 155 155
Lines 9908 9943 +35
==========================================
+ Hits 5867 5921 +54
+ Misses 4041 4022 -19
Continue to review full report at Codecov.
|
One thing I think we could also change is the signature of |
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 ready to merge, just some small changes :)
Yes. I would say its better if we move it to GcObject as |
Looks like you accidentaly broke a lot of tests @vgel. Not sure what you did wrong, but you broke a lot of stuf. |
I'm not sure -- the tests seemed to run fine until I merged master. Will look into it. |
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!
This Pull Request fixes/closes #545
It changes the following:
The biggest change is probably
ordinary_to_primitive
. Since the spec doesn't mention what to do, I went and looked at what v8 and SpiderMonkey do. They return a default value based on the type hint: either0.
or""
. (See example here: https://repl.it/repls/IvoryCircularCertification#index.js) So, I did the same thing. We could alternatively throw a TypeError, but that would both diverge from the spec (which doesn't mention anything) and existing implementations.