@@ -928,18 +928,35 @@ def should_export(sym):
928928
929929
930930def create_receiving (function_exports , tag_exports ):
931+ generate_dyncall_assignment = settings .DYNCALLS and '$dynCall' in settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE
931932 receiving = ['\n // Imports from the Wasm binary.' ]
932933
933934 if settings .WASM_ESM_INTEGRATION :
934- exports = tag_exports + list (function_exports .keys ())
935- exports = [f'{ f } as { asmjs_mangle (f )} ' for f in exports ]
935+ exported_symbols = tag_exports + list (function_exports .keys ())
936+ exports = []
937+ for sym in exported_symbols :
938+ mangled = asmjs_mangle (sym )
939+ if mangled != sym :
940+ exports .append (f'{ sym } as { mangled } ' )
941+ else :
942+ exports .append (sym )
936943 if not settings .IMPORTED_MEMORY :
937944 exports .append ('memory as wasmMemory' )
938945 if not settings .RELOCATABLE :
939946 exports .append ('__indirect_function_table as wasmTable' )
940947 receiving .append ('import {' )
941948 receiving .append (' ' + ',\n ' .join (exports ))
942949 receiving .append (f"}} from './{ settings .WASM_BINARY_FILE } ';" )
950+
951+ if generate_dyncall_assignment :
952+ receiving .append ('\n function assignDynCalls() {' )
953+ receiving .append (' // Construct dynCalls mapping' )
954+ for sym in function_exports :
955+ if sym .startswith ('dynCall_' ):
956+ sig_str = sym .replace ('dynCall_' , '' )
957+ receiving .append (f" dynCalls['{ sig_str } '] = { sym } ;" )
958+ receiving .append ('}' )
959+
943960 return '\n ' .join (receiving ) + '\n \n '
944961
945962 # When not declaring asm exports this section is empty and we instead programmatically export
@@ -952,7 +969,6 @@ def create_receiving(function_exports, tag_exports):
952969 # var _main;
953970 # function assignWasmExports(wasmExport) {
954971 # _main = wasmExports["_main"];
955- generate_dyncall_assignment = settings .DYNCALLS and '$dynCall' in settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE
956972 exports = {name : sig for name , sig in function_exports .items () if name != building .WASM_CALL_CTORS }
957973
958974 if settings .ASSERTIONS :
@@ -981,7 +997,7 @@ def create_receiving(function_exports, tag_exports):
981997 receiving .append ('\n function assignWasmExports(wasmExports) {' )
982998 for sym , sig in exports .items ():
983999 mangled = asmjs_mangle (sym )
984- if generate_dyncall_assignment and mangled .startswith ('dynCall_' ):
1000+ if generate_dyncall_assignment and sym .startswith ('dynCall_' ):
9851001 sig_str = sym .replace ('dynCall_' , '' )
9861002 dynCallAssignment = f"dynCalls['{ sig_str } '] = "
9871003 else :
0 commit comments