@@ -558,11 +558,32 @@ function instrumentWasmTableWithAbort() {
558558}
559559#endif
560560
561+ #if LOAD_SOURCE_MAP
562+ function receiveSourceMapJSON ( sourceMap ) {
563+ wasmSourceMap = new WasmSourceMap ( sourceMap ) ;
564+ { { { runIfMainThread ( "removeRunDependency('source-map');" ) } } }
565+ }
566+ #endif
567+
568+ #if ( PTHREADS || WASM_WORKERS ) && ( LOAD_SOURCE_MAP || USE_OFFSET_CONVERTER )
569+ // When using postMessage to send an object, it is processed by the structured
570+ // clone algorithm. The prototype, and hence methods, on that object is then
571+ // lost. This function adds back the lost prototype. This does not work with
572+ // nested objects that has prototypes, but it suffices for WasmSourceMap and
573+ // WasmOffsetConverter.
574+ function resetPrototype ( constructor , attrs ) {
575+ var object = Object . create ( constructor . prototype ) ;
576+ return Object . assign ( object , attrs ) ;
577+ }
578+ #endif
579+
580+ #if ! SOURCE_PHASE_IMPORTS
561581#if SINGLE_FILE
562582// In SINGLE_FILE mode the wasm binary is encoded inline here as a data: URL.
563583var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}' ;
564584#else
565585var wasmBinaryFile ;
586+
566587function findWasmBinary ( ) {
567588#if EXPORT_ES6 && ! AUDIO_WORKLET
568589 if ( Module [ 'locateFile' ] ) {
@@ -647,13 +668,6 @@ var splitModuleProxyHandler = {
647668} ;
648669#endif
649670
650- #if LOAD_SOURCE_MAP
651- function receiveSourceMapJSON ( sourceMap ) {
652- wasmSourceMap = new WasmSourceMap ( sourceMap ) ;
653- { { { runIfMainThread ( "removeRunDependency('source-map');" ) } } }
654- }
655- #endif
656-
657671#if SPLIT_MODULE || ! WASM_ASYNC_COMPILATION
658672function instantiateSync ( file , info ) {
659673 var module ;
@@ -803,6 +817,7 @@ async function instantiateAsync(binary, binaryFile, imports) {
803817 return instantiateArrayBuffer ( binaryFile , imports ) ;
804818}
805819#endif // WASM_ASYNC_COMPILATION
820+ #endif // SOURCE_PHASE_IMPORTS
806821
807822function getWasmImports ( ) {
808823#if PTHREADS
@@ -1004,10 +1019,14 @@ function getWasmImports() {
10041019 }
10051020#endif
10061021
1022+ #if SOURCE_PHASE_IMPORTS
1023+ var instance = await WebAssembly . instantiate ( wasmModule , info ) ;
1024+ var exports = receiveInstantiationResult ( { instance, 'module' :wasmModule } ) ;
1025+ return exports ;
1026+ #else
10071027#if ! SINGLE_FILE
10081028 wasmBinaryFile ??= findWasmBinary ( ) ;
10091029#endif
1010-
10111030#if WASM_ASYNC_COMPILATION
10121031#if RUNTIME_DEBUG
10131032 dbg ( 'asynchronously preparing wasm' ) ;
@@ -1039,6 +1058,7 @@ function getWasmImports() {
10391058 return receiveInstance ( result [ 0 ] ) ;
10401059#endif
10411060#endif // WASM_ASYNC_COMPILATION
1061+ #endif // SOURCE_PHASE_IMPORTS
10421062}
10431063
10441064#if ! WASM_BIGINT
0 commit comments