Skip to content

Commit aa62dd1

Browse files
committed
Always check the constructor name for simplicity
1 parent 59c32bf commit aa62dd1

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
@@ -65,8 +65,8 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
6565
fn is_sab() -> bool {
6666
use core::sync::atomic::{AtomicU8, Ordering};
6767

68+
use js_sys::Object;
6869
use js_sys::WebAssembly::Memory;
69-
use js_sys::{Object, SharedArrayBuffer};
7070
use wasm_bindgen::JsCast;
7171

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

0 commit comments

Comments
 (0)