@@ -558,11 +558,40 @@ function instrumentWasmTableWithAbort() {
558558}
559559#endif
560560
561+ #if LOAD_SOURCE_MAP
562+ var wasmSourceMap ;
563+ #include "source_map_support.js"
564+
565+ function receiveSourceMapJSON ( sourceMap ) {
566+ wasmSourceMap = new WasmSourceMap ( sourceMap ) ;
567+ { { { runIfMainThread ( "removeRunDependency('source-map');" ) } } }
568+ }
569+ #endif
570+
571+ #if ( PTHREADS || WASM_WORKERS ) && ( LOAD_SOURCE_MAP || USE_OFFSET_CONVERTER )
572+ // When using postMessage to send an object, it is processed by the structured
573+ // clone algorithm. The prototype, and hence methods, on that object is then
574+ // lost. This function adds back the lost prototype. This does not work with
575+ // nested objects that has prototypes, but it suffices for WasmSourceMap and
576+ // WasmOffsetConverter.
577+ function resetPrototype ( constructor , attrs ) {
578+ var object = Object . create ( constructor . prototype ) ;
579+ return Object . assign ( object , attrs ) ;
580+ }
581+ #endif
582+
583+ #if USE_OFFSET_CONVERTER
584+ var wasmOffsetConverter ;
585+ #include "wasm_offset_converter.js"
586+ #endif
587+
588+ #if ! SOURCE_PHASE_IMPORTS
561589#if SINGLE_FILE
562590// In SINGLE_FILE mode the wasm binary is encoded inline here as a data: URL.
563591var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}' ;
564592#else
565593var wasmBinaryFile ;
594+
566595function findWasmBinary ( ) {
567596#if EXPORT_ES6 && ! AUDIO_WORKLET
568597 if ( Module [ 'locateFile' ] ) {
@@ -647,13 +676,6 @@ var splitModuleProxyHandler = {
647676} ;
648677#endif
649678
650- #if LOAD_SOURCE_MAP
651- function receiveSourceMapJSON ( sourceMap ) {
652- wasmSourceMap = new WasmSourceMap ( sourceMap ) ;
653- { { { runIfMainThread ( "removeRunDependency('source-map');" ) } } }
654- }
655- #endif
656-
657679#if SPLIT_MODULE || ! WASM_ASYNC_COMPILATION
658680function instantiateSync ( file , info ) {
659681 var module ;
@@ -701,18 +723,6 @@ function instantiateSync(file, info) {
701723}
702724#endif
703725
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-
716726#if WASM_ASYNC_COMPILATION
717727async function instantiateArrayBuffer ( binaryFile , imports ) {
718728 try {
@@ -815,6 +825,7 @@ async function instantiateAsync(binary, binaryFile, imports) {
815825 return instantiateArrayBuffer ( binaryFile , imports ) ;
816826}
817827#endif // WASM_ASYNC_COMPILATION
828+ #endif // SOURCE_PHASE_IMPORTS
818829
819830function getWasmImports ( ) {
820831#if PTHREADS
@@ -1016,10 +1027,14 @@ function getWasmImports() {
10161027 }
10171028#endif
10181029
1030+ #if SOURCE_PHASE_IMPORTS
1031+ var instance = await WebAssembly . instantiate ( wasmModule , info ) ;
1032+ var exports = receiveInstantiationResult ( { instance, 'module' :wasmModule } ) ;
1033+ return exports ;
1034+ #else
10191035#if ! SINGLE_FILE
10201036 wasmBinaryFile ??= findWasmBinary ( ) ;
10211037#endif
1022-
10231038#if WASM_ASYNC_COMPILATION
10241039#if RUNTIME_DEBUG
10251040 dbg ( 'asynchronously preparing wasm' ) ;
@@ -1051,6 +1066,7 @@ function getWasmImports() {
10511066 return receiveInstance ( result [ 0 ] ) ;
10521067#endif
10531068#endif // WASM_ASYNC_COMPILATION
1069+ #endif // SOURCE_PHASE_IMPORTS
10541070}
10551071
10561072#if ! WASM_BIGINT
0 commit comments