Skip to content

feat(clone): add structuredClone support for Error objects and relate… - #5280

Open
akshatnathani wants to merge 2 commits into
boa-dev:mainfrom
akshatnathani:fix/structured-clone-error-support
Open

feat(clone): add structuredClone support for Error objects and relate…#5280
akshatnathani wants to merge 2 commits into
boa-dev:mainfrom
akshatnathani:fix/structured-clone-error-support

Conversation

@akshatnathani

Copy link
Copy Markdown

This Pull Request fixes/closes #5279.

It changes the following:

  • Added Error object support in the JsValueStore serialization path so structuredClone(new Error("boom")) and postMessage(new Error("boom")) no longer fail during cloning.
  • Implemented Error object reconstruction in the deserialization path using stored error metadata (kind, name, message, and related fields), instead of returning Not yet implemented.
  • Added regression tests for both clone paths:
    • clone::tests::clones_error_objects
    • message::tests::basic_error_message
  • Removed the stale #[expect(unused)] on the ValueStoreInner::Error variant, since it is now actively used.
  • Verified consistency with project standards and checks:
    • cargo fmt --all -- --check
    • cargo clippy -p boa_runtime --tests -- -D warnings
    • cargo test -p boa_runtime clones_error_objects -- --nocapture
    • cargo test -p boa_runtime basic_error_message -- --nocapture

@akshatnathani
akshatnathani requested a review from a team as a code owner March 28, 2026 17:14
@github-actions github-actions Bot added C-Tests Issues and PRs related to the tests. C-Runtime Issues and PRs related to Boa's runtime features Waiting On Review Waiting on reviews from the maintainers labels Mar 28, 2026
@github-actions github-actions Bot added this to the v1.0.0 milestone Mar 28, 2026
Comment thread core/runtime/src/store/from.rs Outdated
Comment thread core/runtime/src/store/to.rs
@akshatnathani
akshatnathani force-pushed the fix/structured-clone-error-support branch from 0f3a392 to 98a2ce6 Compare March 29, 2026 23:30

@jedel1043 jedel1043 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I just have a couple of suggestions to improve the code.

Comment on lines +192 to +194
let native = JsError::from_opaque(JsValue::from(original.clone()))
.try_native(context)
.map_err(|_| unsupported_type())?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be infallible, since we know original is already an Error type.
What we should do here is to add a conversion from JsObject<Error> to JsNativeError directly, and pass JsObject<Error> as our original object.

Comment on lines +18 to +24
type ErrorStoreFields<'a> = (
&'a ErrorKind,
&'a StringStore,
&'a StringStore,
&'a StringStore,
&'a StringStore,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks kinda unmaintainable; you cannot easily distinguish which field is the name, the message, the stack or the cause at first glance. A proper struct would be better to make it harder to pass the incorrect field.

@jedel1043 jedel1043 added Waiting On Author Waiting on PR changes from the author and removed Waiting On Review Waiting on reviews from the maintainers labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests. Waiting On Author Waiting on PR changes from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

structuredClone and postMessage reject Error objects

3 participants