Skip to content
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

Deprecate JsStatic in favor of #[wasm_bindgen(thread_local)] #4057

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

daxpedda
Copy link
Collaborator

@daxpedda daxpedda commented Aug 6, 2024

This PR deprecated JsStatic in favor of #[wasm_bindgen(thread_local)], which creates a std::thread::LocalKey. The syntax is otherwise the same.

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(thread_local)]
    static FOO: JsValue;
}

JsStatic was pretty much a hack that exposed a thread local variable by transmuting the lifetime to 'static, which does make sense on Web, but not with multi-threading, which was making this rather unsound.

Additionally, impl Deref for JsStatic is not present anymore when compiling with cfg(target_feature = "atomics") to remove the possibility of unsoundness entirely.

@daxpedda daxpedda force-pushed the static-thread-local branch 2 times, most recently from 1170d25 to 26781fa Compare August 6, 2024 21:56
Removed `impl Deref for JsStatic` when compiling with `cfg(target_feature = "atomics")`, which was unsound.
@daxpedda daxpedda changed the title Deprecate JsStatic in favor of #[wasm_bindgen(thread_local)]` Deprecate JsStatic in favor of #[wasm_bindgen(thread_local)] Aug 6, 2024
@daxpedda daxpedda merged commit acfd1ee into rustwasm:main Aug 6, 2024
27 checks passed
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.

1 participant