Repository navigation
propagate toJSON lookup exceptions in simd JSON.stringify - #1317
Merged
saulecabrera merged 1 commit intoOct 23, 2026
Merged
saulecabrera merged 1 commit into
saulecabrera merged 1 commit into
Conversation
jeffcharles
approved these changes
Oct 19, 2026
Collaborator
|
FYI it looks like there are merge conflicts with this PR |
nabeel-dev21
force-pushed
the
json-stringify-tojson-exception
branch
from
October 23, 2026 07:19
e94d3a9 to
4edeb4e
Compare
Contributor
Author
|
Rebased onto main. The conflicts were with #1311 landing in the same changelog section and at the end of tests/misc.rs, so I folded the entry into the existing Fixed list and kept both tests. No change to the fix itself, and the misc tests still pass natively and on wasip1. |
saulecabrera
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the change
get_to_jsonin the simdJSON.stringifypath looks up the top-level value'stoJSONproperty through a rawJS_GetPropertycall and wraps the result withValue::from_rawwithout checking forJS_EXCEPTION. When the lookup throws, from an accessor like{ get toJSON() { throw e } }or a Proxygettrap, the exception tag is simply "not a function", so stringify carries on serialising the object and returns{}or{"a":1}while the thrown error stays pending on the context. NativeJSON.stringifypropagates the throw.The lookup now goes through rquickjs'
Object::getwithPredefinedAtom::ToJSON, which runs the same property access and returnsErr(Exception)on a throw, andcall_json_stringifypropagates that with?, the path already taken whentoJSONitself throws. That also drops the twounsafeblocks. Added a regression test driven fromtests/misc.rscovering the accessor and proxy cases; it fails on the unpatched tree and passes with the fix. The nestedtoJSON/valueOf/toStringlookups inside rquickjs-serde have the same shape, but that lives in a separate crate.Why am I making this change?
A builtin should not silently discard a thrown exception, and leaving it pending on the runtime is a latent source of confusing errors for whatever next reads the context's exception. Fixing it inside the builtin keeps the SIMD implementation matching the native one, which the fuzz target compares against. Lookups that do not throw behave exactly as before. Verified with
cargo test -p javy --target=wasm32-wasip1on thejsonand--all-featuressets, plus clippy with-D warningson wasip1 and wasip2 for the lib and misc test targets.Checklist
javy-plugin-apiif the QuickJS bytecode has changed.javy-cli,javy-plugin, andjavy-plugin-processingdo not require updating CHANGELOG files.