diff --git a/src/backends/wasm_js.rs b/src/backends/wasm_js.rs index 8c05aa3c..6ccef112 100644 --- a/src/backends/wasm_js.rs +++ b/src/backends/wasm_js.rs @@ -65,8 +65,8 @@ pub fn fill_inner(dest: &mut [MaybeUninit]) -> Result<(), Error> { fn is_sab() -> bool { use core::sync::atomic::{AtomicU8, Ordering}; + use js_sys::Object; use js_sys::WebAssembly::Memory; - use js_sys::{Object, SharedArrayBuffer}; use wasm_bindgen::JsCast; const MEMORY_KIND_UNINIT: u8 = 0; @@ -85,19 +85,9 @@ fn is_sab() -> bool { // `SharedArrayBuffer` is only available with COOP & COEP. But even without its // possible to create a shared `WebAssembly.Memory`, so we check for that via // the constructor name. - // - // Keep in mind that `crossOriginIsolated` is not available on Node.js, in - // which case we can still use `instanceof` because `SharedArrayBuffer` is - // always available. - let shared = match CROSS_ORIGIN_ISOLATED.with(Option::clone) { - Some(true) | None => buffer.is_instance_of::(), - Some(false) => { - let constructor_name = Object::from(buffer).constructor().name(); - SHARED_ARRAY_BUFFER_NAME.with(|name| &constructor_name == name) - } - }; - - let val = if shared { + let constructor_name = Object::from(buffer).constructor().name(); + let val = if SHARED_ARRAY_BUFFER_NAME.with(|sab_name| &constructor_name == sab_name) + { MEMORY_KIND_SHARED } else { MEMORY_KIND_NOT_SHARED @@ -128,9 +118,6 @@ extern "C" { fn get_random_values(this: &Crypto, buf: &Uint8Array) -> Result<(), JsValue>; #[wasm_bindgen(method, js_name = getRandomValues, catch)] fn get_random_values_ref(this: &Crypto, buf: &mut [u8]) -> Result<(), JsValue>; - // Returns the [`crossOriginIsolated`](https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated) global property. - #[wasm_bindgen(thread_local_v2, js_namespace = globalThis, js_name = crossOriginIsolated)] - static CROSS_ORIGIN_ISOLATED: Option; #[wasm_bindgen(thread_local_v2, static_string)] static SHARED_ARRAY_BUFFER_NAME: JsString = "SharedArrayBuffer"; }