@@ -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 ;
@@ -701,18 +715,6 @@ function instantiateSync(file, info) {
701715}
702716#endif
703717
704- #if ( PTHREADS || WASM_WORKERS ) && ( LOAD_SOURCE_MAP || USE_OFFSET_CONVERTER )
705- // When using postMessage to send an object, it is processed by the structured
706- // clone algorithm. The prototype, and hence methods, on that object is then
707- // lost. This function adds back the lost prototype. This does not work with
708- // nested objects that has prototypes, but it suffices for WasmSourceMap and
709- // WasmOffsetConverter.
710- function resetPrototype ( constructor , attrs ) {
711- var object = Object . create ( constructor . prototype ) ;
712- return Object . assign ( object , attrs ) ;
713- }
714- #endif
715-
716718#if WASM_ASYNC_COMPILATION
717719async function instantiateArrayBuffer ( binaryFile , imports ) {
718720 try {
@@ -815,6 +817,7 @@ async function instantiateAsync(binary, binaryFile, imports) {
815817 return instantiateArrayBuffer ( binaryFile , imports ) ;
816818}
817819#endif // WASM_ASYNC_COMPILATION
820+ #endif // SOURCE_PHASE_IMPORTS
818821
819822function getWasmImports ( ) {
820823#if PTHREADS
@@ -1016,10 +1019,14 @@ function getWasmImports() {
10161019 }
10171020#endif
10181021
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
10191027#if ! SINGLE_FILE
10201028 wasmBinaryFile ??= findWasmBinary ( ) ;
10211029#endif
1022-
10231030#if WASM_ASYNC_COMPILATION
10241031#if RUNTIME_DEBUG
10251032 dbg ( 'asynchronously preparing wasm' ) ;
@@ -1051,6 +1058,7 @@ function getWasmImports() {
10511058 return receiveInstance ( result [ 0 ] ) ;
10521059#endif
10531060#endif // WASM_ASYNC_COMPILATION
1061+ #endif // SOURCE_PHASE_IMPORTS
10541062}
10551063
10561064#if ! WASM_BIGINT
0 commit comments