Skip to content

Fix cross-thread JSString deinit by wrapping JSObject instead of raw ref#741

Merged
kateinoigakukun merged 1 commit intomainfrom
claude/fix-jsstring-threading-XtWUJ
May 6, 2026
Merged

Fix cross-thread JSString deinit by wrapping JSObject instead of raw ref#741
kateinoigakukun merged 1 commit intomainfrom
claude/fix-jsstring-threading-XtWUJ

Conversation

@kateinoigakukun
Copy link
Copy Markdown
Member

@kateinoigakukun kateinoigakukun commented May 6, 2026

JSString.Guts previously held a raw JavaScriptObjectRef and released it unconditionally on whatever thread ran deinit. In the multithreaded Wasm runtime each thread has its own JSObjectSpace, so releasing a ref on the wrong thread caused a crash

JSObject already handles this correctly by capturing ownerTid at init time and routing deinit through swjs_release_remote when destroyed off-thread.
This change makes Guts hold a JSObject instead of a raw ref, delegating the correct cross-thread release behaviour to the existing JSObject.deinit path.

JSString.Guts previously held a raw JavaScriptObjectRef and released it
unconditionally on whatever thread ran deinit. In the multithreaded Wasm
runtime each thread has its own JSObjectSpace, so releasing a ref on the
wrong thread caused a TypeError crash (BugSnag: rc property of undefined).

JSObject already handles this correctly by capturing ownerTid at init time
and routing deinit through swjs_release_remote when destroyed off-thread.
This change makes Guts hold a JSObject instead of a raw ref, delegating the
correct cross-thread release behaviour to the existing JSObject.deinit path.

Adds a regression test testDeinitJSStringOnDifferentThread that reproduces
the crash deterministically: it forces JS ref allocation on the main thread
via asInternalJSRef(), then drops the last reference on a worker thread.

Fixes the crash seen in v292745-rc4 after upgrading to JavaScriptKit 0.50.2.

https://claude.ai/code/session_01Qhg5GLXZYNJtH63Gs1SwJH
@kateinoigakukun kateinoigakukun merged commit 6ea916b into main May 6, 2026
13 checks passed
@kateinoigakukun kateinoigakukun deleted the claude/fix-jsstring-threading-XtWUJ branch May 6, 2026 19:00
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