File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Plugins/PackageToJS/Templates Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -308,7 +308,12 @@ class SwiftRuntime {
308
308
// Cache the DataView as it's not a cheap operation
309
309
let cachedDataView = new DataView ( wasmMemory . buffer ) ;
310
310
let cachedUint8Array = new Uint8Array ( wasmMemory . buffer ) ;
311
- if ( typeof SharedArrayBuffer !== "undefined" && wasmMemory . buffer instanceof SharedArrayBuffer ) {
311
+ // Check the constructor name of the buffer to determine if it's backed by a SharedArrayBuffer.
312
+ // We can't reference SharedArrayBuffer directly here because:
313
+ // 1. It may not be available in the global scope if the context is not cross-origin isolated.
314
+ // 2. The underlying buffer may be still backed by SAB even if the context is not cross-origin
315
+ // isolated (e.g. localhost on Chrome on Android).
316
+ if ( Object . getPrototypeOf ( wasmMemory . buffer ) . constructor . name === "SharedArrayBuffer" ) {
312
317
// When the wasm memory is backed by a SharedArrayBuffer, growing the memory
313
318
// doesn't invalidate the data view by setting the byte length to 0. Instead,
314
319
// the data view points to an old buffer after growing the memory. So we have
Original file line number Diff line number Diff line change @@ -64,7 +64,13 @@ export class SwiftRuntime {
64
64
// Cache the DataView as it's not a cheap operation
65
65
let cachedDataView = new DataView ( wasmMemory . buffer ) ;
66
66
let cachedUint8Array = new Uint8Array ( wasmMemory . buffer ) ;
67
- if ( typeof SharedArrayBuffer !== "undefined" && wasmMemory . buffer instanceof SharedArrayBuffer ) {
67
+
68
+ // Check the constructor name of the buffer to determine if it's backed by a SharedArrayBuffer.
69
+ // We can't reference SharedArrayBuffer directly here because:
70
+ // 1. It may not be available in the global scope if the context is not cross-origin isolated.
71
+ // 2. The underlying buffer may be still backed by SAB even if the context is not cross-origin
72
+ // isolated (e.g. localhost on Chrome on Android).
73
+ if ( Object . getPrototypeOf ( wasmMemory . buffer ) . constructor . name === "SharedArrayBuffer" ) {
68
74
// When the wasm memory is backed by a SharedArrayBuffer, growing the memory
69
75
// doesn't invalidate the data view by setting the byte length to 0. Instead,
70
76
// the data view points to an old buffer after growing the memory. So we have
You can’t perform that action at this time.
0 commit comments