Skip to content

feat: support schedule_reinit() under panic=abort builds#5099

Merged
guybedford merged 3 commits into
mainfrom
panic-abort-reinit
Apr 9, 2026
Merged

feat: support schedule_reinit() under panic=abort builds#5099
guybedford merged 3 commits into
mainfrom
panic-abort-reinit

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

Summary

Previously handler::schedule_reinit() was a no-op under panic=abort. This extends it to work with both panic strategies.

Under panic=abort there's no __instance_terminated flag or wasm-level catch wrappers, so the full abort detection machinery doesn't apply. But schedule_reinit() is independent of abort detection — it just sets a JS-side flag (__wbg_reinit_scheduled) that's checked before each export call. This PR adds that minimal path.

  • Remove #[cfg(panic = "unwind")] gate on schedule_reinit() so it calls __wbindgen_reinit() in all builds
  • Add generate_reinit_guard() — emits a simple __wbg_termination_guard that only checks __wbg_reinit_scheduled (no try/catch, no __instance_terminated)
  • Refactor maybe_wrap_try_catch into maybe_wrap_export_call with separate check_aborted / check_reinit flags — exports under panic=abort get the guard prepended without try/catch wrapping
  • Fix __wbg_reset_state to reset __wbg_reinit_scheduled in all builds (not just when wrapped_js_tag is present)
  • Add reinit_panic_abort integration test: builds with -Cpanic=abort -Zbuild-std=std,panic_abort, verifies new instance creation, static reset, persistence without signal, and multiple reinit cycles

@guybedford guybedford force-pushed the panic-abort-reinit branch 5 times, most recently from d04d3cd to cbdf659 Compare April 9, 2026 00:33
Comment thread crates/cli-support/src/js/binding.rs Outdated
Comment thread crates/cli-support/src/js/binding.rs
Comment thread crates/cli-support/src/js/binding.rs
Comment thread crates/cli/tests/wasm-bindgen/main.rs Outdated

@hoodmane hoodmane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM aside from a few suggestions.

@guybedford guybedford force-pushed the panic-abort-reinit branch from 0ecd8b4 to cf1989e Compare April 9, 2026 19:21
@guybedford guybedford merged commit 6640596 into main Apr 9, 2026
63 checks passed
@guybedford guybedford deleted the panic-abort-reinit branch April 9, 2026 20:24
@guybedford guybedford mentioned this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants