@@ -308,7 +308,12 @@ class SwiftRuntime {
308308 // Cache the DataView as it's not a cheap operation
309309 let cachedDataView = new DataView ( wasmMemory . buffer ) ;
310310 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" ) {
312317 // When the wasm memory is backed by a SharedArrayBuffer, growing the memory
313318 // doesn't invalidate the data view by setting the byte length to 0. Instead,
314319 // the data view points to an old buffer after growing the memory. So we have
@@ -796,8 +801,9 @@ class SwiftRuntime {
796801 throw new Error ( "threadChannel is not set in options given to SwiftRuntime. Please set it to request transferring objects." ) ;
797802 }
798803 const broker = getMessageBroker ( this . options . threadChannel ) ;
799- const sendingObjects = decodeObjectRefs ( sending_objects , sending_objects_count , this . getDataView ( ) ) ;
800- const transferringObjects = decodeObjectRefs ( transferring_objects , transferring_objects_count , this . getDataView ( ) ) ;
804+ const dataView = this . getDataView ( ) ;
805+ const sendingObjects = decodeObjectRefs ( sending_objects , sending_objects_count , dataView ) ;
806+ const transferringObjects = decodeObjectRefs ( transferring_objects , transferring_objects_count , dataView ) ;
801807 broker . request ( {
802808 type : "request" ,
803809 data : {
0 commit comments