@@ -429,13 +429,7 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
429
429
function_exports ['asyncify_stop_rewind' ] = webassembly .FuncType ([], [])
430
430
431
431
parts = [pre ]
432
- receiving = create_receiving (function_exports )
433
- if settings .WASM_ESM_INTEGRATION :
434
- sending = create_sending (metadata , forwarded_json ['librarySymbols' ])
435
- reexports = create_reexports ()
436
- parts += [sending , receiving , reexports ]
437
- else :
438
- parts += create_module (receiving , metadata , global_exports , forwarded_json ['librarySymbols' ])
432
+ parts += create_module (metadata , function_exports , global_exports , forwarded_json ['librarySymbols' ])
439
433
parts .append (post )
440
434
441
435
full_js_module = '' .join (parts )
@@ -1004,44 +998,56 @@ def create_receiving(function_exports):
1004
998
return '\n ' .join (receiving ) + '\n '
1005
999
1006
1000
1007
- def create_module (receiving , metadata , global_exports , library_symbols ):
1008
- receiving += create_global_exports (global_exports )
1001
+ def create_module (metadata , function_exports , global_exports , library_symbols ):
1009
1002
module = []
1010
1003
1004
+ receiving = create_receiving (function_exports )
1011
1005
sending = create_sending (metadata , library_symbols )
1012
- if settings .PTHREADS or settings .WASM_WORKERS :
1013
- sending = textwrap .indent (sending , ' ' ).strip ()
1014
- module .append ('''\
1015
- var wasmImports;
1016
- function assignWasmImports() {
1017
- wasmImports = %s;
1018
- }
1019
- ''' % sending )
1020
- else :
1021
- module .append ('var wasmImports = %s;\n ' % sending )
1022
1006
1023
- if not settings .MINIMAL_RUNTIME :
1024
- if settings .MODULARIZE == 'instance' :
1025
- module .append ("var wasmExports;\n " )
1026
- elif settings .WASM_ASYNC_COMPILATION :
1027
- if can_use_await ():
1028
- # In modularize mode the generated code is within a factory function.
1029
- # This magic string gets replaced by `await createWasm`. It needed to allow
1030
- # closure and acorn to process the module without seeing this as a top-level
1031
- # await.
1032
- module .append ("var wasmExports = EMSCRIPTEN$AWAIT(createWasm());\n " )
1033
- else :
1034
- module .append ("var wasmExports;\n createWasm();\n " )
1007
+ if settings .WASM_ESM_INTEGRATION :
1008
+ module .append (sending )
1009
+ else :
1010
+ receiving += create_global_exports (global_exports )
1011
+
1012
+ if settings .PTHREADS or settings .WASM_WORKERS :
1013
+ sending = textwrap .indent (sending , ' ' ).strip ()
1014
+ module .append ('''\
1015
+ var wasmImports;
1016
+ function assignWasmImports() {
1017
+ wasmImports = %s;
1018
+ }
1019
+ ''' % sending )
1035
1020
else :
1036
- module .append ("var wasmExports = createWasm();\n " )
1021
+ module .append ('var wasmImports = %s;\n ' % sending )
1022
+
1023
+ if not settings .MINIMAL_RUNTIME :
1024
+ if settings .MODULARIZE == 'instance' :
1025
+ module .append ("var wasmExports;\n " )
1026
+ elif settings .WASM_ASYNC_COMPILATION :
1027
+ if can_use_await ():
1028
+ # In modularize mode the generated code is within a factory function.
1029
+ # This magic string gets replaced by `await createWasm`. It needed to allow
1030
+ # closure and acorn to process the module without seeing this as a top-level
1031
+ # await.
1032
+ module .append ("var wasmExports = EMSCRIPTEN$AWAIT(createWasm());\n " )
1033
+ else :
1034
+ module .append ("var wasmExports;\n createWasm();\n " )
1035
+ else :
1036
+ module .append ("var wasmExports = createWasm();\n " )
1037
1037
1038
1038
module .append (receiving )
1039
+
1039
1040
if settings .SUPPORT_LONGJMP == 'emscripten' or not settings .DISABLE_EXCEPTION_CATCHING :
1040
1041
module .append (create_invoke_wrappers (metadata ))
1041
1042
else :
1042
1043
assert not metadata .invoke_funcs , "invoke_ functions exported but exceptions and longjmp are both disabled"
1044
+
1043
1045
if settings .MEMORY64 or settings .CAN_ADDRESS_2GB :
1044
1046
module .append (create_pointer_conversion_wrappers (metadata ))
1047
+
1048
+ if settings .WASM_ESM_INTEGRATION :
1049
+ module .append (create_reexports ())
1050
+
1045
1051
return module
1046
1052
1047
1053
0 commit comments