Skip to content

Commit 04a539e

Browse files
committed
Always check the constructor name for simplicity
1 parent 25d9233 commit 04a539e

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

src/backends/wasm_js.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use crate::util::{inner_u32, inner_u64};
1616
#[cfg(not(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"))))]
1717
compile_error!("`wasm_js` backend can be enabled only for OS-less WASM targets!");
1818

19-
use js_sys::{JsString, Object, SharedArrayBuffer, Uint8Array, WebAssembly::Memory};
19+
use js_sys::{JsString, Object, Uint8Array, WebAssembly::Memory};
2020
use wasm_bindgen::{prelude::wasm_bindgen, JsCast, JsValue};
2121

2222
// Size of our temporary Uint8Array buffer used with WebCrypto methods
@@ -43,19 +43,10 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
4343
// `SharedArrayBuffer` is only available with COOP & COEP. But even without its
4444
// possible to create a shared `WebAssembly.Memory`, so we check for that via
4545
// the constructor name.
46-
//
47-
// Keep in mind that `crossOriginIsolated` is not available on Node.js, in
48-
// which case we can still use `instanceof` because `SharedArrayBuffer` is
49-
// always available.
50-
let shared = match CROSS_ORIGIN_ISOLATED.with(Option::clone) {
51-
Some(true) | None => buffer.is_instance_of::<SharedArrayBuffer>(),
52-
Some(false) => {
53-
let constructor_name = Object::from(buffer).constructor().name();
54-
SHARED_ARRAY_BUFFER_NAME.with(|name| &constructor_name == name)
55-
}
56-
};
57-
58-
let val = if shared {
46+
let constructor_name = Object::from(buffer).constructor().name();
47+
let val = if SHARED_ARRAY_BUFFER_NAME
48+
.with(|sab_name| &constructor_name == sab_name)
49+
{
5950
MEMORY_KIND_SHARED
6051
} else {
6152
MEMORY_KIND_NOT_SHARED
@@ -115,9 +106,6 @@ extern "C" {
115106
fn get_random_values(this: &Crypto, buf: &Uint8Array) -> Result<(), JsValue>;
116107
#[wasm_bindgen(method, js_name = getRandomValues, catch)]
117108
fn get_random_values_ref(this: &Crypto, buf: &mut [u8]) -> Result<(), JsValue>;
118-
// Returns the [`crossOriginIsolated`](https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated) global property.
119-
#[wasm_bindgen(thread_local_v2, js_namespace = globalThis, js_name = crossOriginIsolated)]
120-
static CROSS_ORIGIN_ISOLATED: Option<bool>;
121109
#[wasm_bindgen(thread_local_v2, static_string)]
122110
static SHARED_ARRAY_BUFFER_NAME: JsString = "SharedArrayBuffer";
123111
}

0 commit comments

Comments
 (0)