Skip to content

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

Merged
daxpedda merged 1 commit intowasm-bindgen:mainfrom
daxpedda:static-thread-local
Aug 6, 2024
Merged

Deprecate JsStatic in favor of #[wasm_bindgen(thread_local)]#4057
daxpedda merged 1 commit intowasm-bindgen:mainfrom
daxpedda:static-thread-local

Conversation

@daxpedda
Copy link
Copy Markdown
Member

@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 force-pushed the static-thread-local branch from 26781fa to 05a575e Compare August 6, 2024 22:07
@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 wasm-bindgen:main Aug 6, 2024
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