@@ -444,8 +444,9 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
444
444
pre = None
445
445
446
446
receiving = create_receiving (function_exports )
447
+ receiving += create_global_exports (global_exports )
447
448
448
- module = create_module (receiving , metadata , global_exports , forwarded_json ['librarySymbols' ])
449
+ module = create_module (receiving , metadata , forwarded_json ['librarySymbols' ])
449
450
450
451
metadata .library_definitions = forwarded_json ['libraryDefinitions' ]
451
452
@@ -877,13 +878,7 @@ def create_sending(metadata, library_symbols):
877
878
878
879
879
880
def 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
887
882
888
883
889
884
def make_export_wrappers (function_exports ):
@@ -973,8 +968,7 @@ def create_receiving(function_exports):
973
968
return '\n ' .join (receiving ) + '\n '
974
969
975
970
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 ):
978
972
module = []
979
973
980
974
sending = create_sending (metadata , library_symbols )
@@ -993,7 +987,10 @@ def create_module(receiving, metadata, global_exports, library_symbols):
993
987
if settings .WASM_ASYNC_COMPILATION :
994
988
if can_use_await ():
995
989
# 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 " )
997
994
else :
998
995
module .append ("var wasmExports;\n createWasm();\n " )
999
996
else :
0 commit comments