@@ -444,8 +444,9 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
444444 pre = None
445445
446446 receiving = create_receiving (function_exports )
447+ receiving += create_global_exports (global_exports )
447448
448- module = create_module (receiving , metadata , global_exports , forwarded_json ['librarySymbols' ])
449+ module = create_module (receiving , metadata , forwarded_json ['librarySymbols' ])
449450
450451 metadata .library_definitions = forwarded_json ['libraryDefinitions' ]
451452
@@ -877,13 +878,7 @@ def create_sending(metadata, library_symbols):
877878
878879
879880def can_use_await ():
880- # In MODULARIZE mode we can use `await` since the factory function itself
881- # is marked as `async` and the generated code all lives inside that factory
882- # function.
883- # However, because closure does not see this (it runs only on the inner code),
884- # it sees this as a top-level-await, which it does not yet support.
885- # FIXME(https://github.com/emscripten-core/emscripten/issues/23158)
886- return settings .MODULARIZE and not settings .USE_CLOSURE_COMPILER
881+ return settings .MODULARIZE
887882
888883
889884def make_export_wrappers (function_exports ):
@@ -973,8 +968,7 @@ def create_receiving(function_exports):
973968 return '\n ' .join (receiving ) + '\n '
974969
975970
976- def create_module (receiving , metadata , global_exports , library_symbols ):
977- receiving += create_global_exports (global_exports )
971+ def create_module (receiving , metadata , library_symbols ):
978972 module = []
979973
980974 sending = create_sending (metadata , library_symbols )
@@ -993,7 +987,10 @@ def create_module(receiving, metadata, global_exports, library_symbols):
993987 if settings .WASM_ASYNC_COMPILATION :
994988 if can_use_await ():
995989 # In modularize mode the generated code is within a factory function.
996- module .append ("var wasmExports = await createWasm();\n " )
990+ # This magic string gets replaced by `await createWasm`. It needed to allow
991+ # closure and acorn to process the module without seeing this as a top-level
992+ # await.
993+ module .append ("var wasmExports = EMSCRIPTEN$AWAIT(createWasm());\n " )
997994 else :
998995 module .append ("var wasmExports;\n createWasm();\n " )
999996 else :
0 commit comments