Skip to content

Commit 8cbc677

Browse files
committed
Always check the constructor name for simplicity
1 parent 82d0751 commit 8cbc677

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

src/backends/wasm_js.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
6363
fn is_sab() -> bool {
6464
use core::sync::atomic::{AtomicU8, Ordering};
6565

66+
use js_sys::Object;
6667
use js_sys::WebAssembly::Memory;
67-
use js_sys::{Object, SharedArrayBuffer};
6868
use wasm_bindgen::JsCast;
6969

7070
const MEMORY_KIND_UNINIT: u8 = 0;
@@ -83,19 +83,9 @@ fn is_sab() -> bool {
8383
// `SharedArrayBuffer` is only available with COOP & COEP. But even without its
8484
// possible to create a shared `WebAssembly.Memory`, so we check for that via
8585
// the constructor name.
86-
//
87-
// Keep in mind that `crossOriginIsolated` is not available on Node.js, in
88-
// which case we can still use `instanceof` because `SharedArrayBuffer` is
89-
// always available.
90-
let shared = match CROSS_ORIGIN_ISOLATED.with(Option::clone) {
91-
Some(true) | None => buffer.is_instance_of::<SharedArrayBuffer>(),
92-
Some(false) => {
93-
let constructor_name = Object::from(buffer).constructor().name();
94-
SHARED_ARRAY_BUFFER_NAME.with(|name| &constructor_name == name)
95-
}
96-
};
97-
98-
let val = if shared {
86+
let constructor_name = Object::from(buffer).constructor().name();
87+
let val = if SHARED_ARRAY_BUFFER_NAME.with(|sab_name| &constructor_name == sab_name)
88+
{
9989
MEMORY_KIND_SHARED
10090
} else {
10191
MEMORY_KIND_NOT_SHARED
@@ -126,9 +116,6 @@ extern "C" {
126116
fn get_random_values(this: &Crypto, buf: &Uint8Array) -> Result<(), JsValue>;
127117
#[wasm_bindgen(method, js_name = getRandomValues, catch)]
128118
fn get_random_values_ref(this: &Crypto, buf: &mut [u8]) -> Result<(), JsValue>;
129-
// Returns the [`crossOriginIsolated`](https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated) global property.
130-
#[wasm_bindgen(thread_local_v2, js_namespace = globalThis, js_name = crossOriginIsolated)]
131-
static CROSS_ORIGIN_ISOLATED: Option<bool>;
132119
#[wasm_bindgen(thread_local_v2, static_string)]
133120
static SHARED_ARRAY_BUFFER_NAME: JsString = "SharedArrayBuffer";
134121
}

0 commit comments

Comments
 (0)