@@ -1719,23 +1719,24 @@ def create_receiving(function_table_data, function_tables_defs, exported_impleme
1719
1719
module_exports = exported_implemented_functions + function_tables (function_table_data )
1720
1720
shared .Settings .MODULE_EXPORTS = [(f , f ) for f in module_exports ]
1721
1721
1722
- if not shared .Settings .SWAPPABLE_ASM_MODULE :
1723
- if runtime_assertions :
1724
- # assert on the runtime being in a valid state when calling into compiled code. The only
1725
- # exceptions are some support code.
1726
- receiving_functions = [f for f in exported_implemented_functions if f not in ('_memcpy' , '_memset' , '_emscripten_replace_memory' , '__start_module' )]
1727
-
1728
- wrappers = []
1729
- for name in receiving_functions :
1730
- wrappers .append ('''\
1731
- var real_%(name)s = asm["%(name)s"];
1732
- asm["%(name)s"] = function() {%(runtime_assertions)s
1733
- return real_%(name)s.apply(null, arguments);
1734
- };
1735
- ''' % {'name' : name , 'runtime_assertions' : runtime_assertions })
1736
- receiving += '\n ' .join (wrappers )
1722
+ if not shared .Settings .DECLARE_ASM_MODULE_EXPORTS :
1723
+ receiving += 'exportAsmFunctions(asm);'
1724
+ else :
1725
+ if not shared .Settings .SWAPPABLE_ASM_MODULE :
1726
+ if runtime_assertions :
1727
+ # assert on the runtime being in a valid state when calling into compiled code. The only
1728
+ # exceptions are some support code.
1729
+ receiving_functions = [f for f in exported_implemented_functions if f not in ('_memcpy' , '_memset' , '_emscripten_replace_memory' , '__start_module' )]
1730
+ wrappers = []
1731
+ for name in receiving_functions :
1732
+ wrappers .append ('''\
1733
+ var real_%(name)s = asm["%(name)s"];
1734
+ asm["%(name)s"] = function() {%(runtime_assertions)s
1735
+ return real_%(name)s.apply(null, arguments);
1736
+ };
1737
+ ''' % {'name' : name , 'runtime_assertions' : runtime_assertions })
1738
+ receiving += '\n ' .join (wrappers )
1737
1739
1738
- if shared .Settings .DECLARE_ASM_MODULE_EXPORTS :
1739
1740
imported_exports = [s for s in module_exports if s not in initializers ]
1740
1741
1741
1742
if shared .Settings .WASM and shared .Settings .MINIMAL_RUNTIME :
@@ -1754,18 +1755,16 @@ def create_receiving(function_table_data, function_tables_defs, exported_impleme
1754
1755
else :
1755
1756
receiving += '\n ' .join (['var ' + s + ' = Module["' + s + '"] = asm["' + s + '"];' for s in module_exports ]) + '\n '
1756
1757
else :
1757
- receiving += 'exportAsmFunctions(asm);'
1758
- else :
1759
- receiving += 'Module["asm"] = asm;\n '
1760
- wrappers = []
1761
- for name in module_exports :
1762
- wrappers .append ('''\
1758
+ receiving += 'Module["asm"] = asm;\n '
1759
+ wrappers = []
1760
+ for name in module_exports :
1761
+ wrappers .append ('''\
1763
1762
var %(name)s = Module["%(name)s"] = function() {%(runtime_assertions)s
1764
1763
return Module["asm"]["%(name)s"].apply(null, arguments)
1765
1764
};
1766
1765
''' % {'name' : name , 'runtime_assertions' : runtime_assertions })
1767
1766
1768
- receiving += '\n ' .join (wrappers )
1767
+ receiving += '\n ' .join (wrappers )
1769
1768
1770
1769
if shared .Settings .EXPORT_FUNCTION_TABLES and not shared .Settings .WASM :
1771
1770
for table in function_table_data .values ():
@@ -2613,6 +2612,11 @@ def fix_import_name(g):
2613
2612
2614
2613
2615
2614
def create_receiving_wasm (exports , initializers ):
2615
+ # When not declaring asm exports this section is empty and we instead programatically export
2616
+ # synbols on the global object by calling exportAsmFunctions after initialization
2617
+ if not shared .Settings .DECLARE_ASM_MODULE_EXPORTS :
2618
+ return ''
2619
+
2616
2620
exports_that_are_not_initializers = [x for x in exports if x not in initializers ]
2617
2621
2618
2622
receiving = []
@@ -2631,24 +2635,21 @@ def create_receiving_wasm(exports, initializers):
2631
2635
return real_%(mangled)s.apply(null, arguments);
2632
2636
};
2633
2637
''' % {'mangled' : asmjs_mangle (e ), 'e' : e , 'assertions' : runtime_assertions })
2634
- if shared .Settings .DECLARE_ASM_MODULE_EXPORTS :
2635
- if shared .Settings .WASM and shared .Settings .MINIMAL_RUNTIME :
2636
- # In Wasm exports are assigned inside a function to variables existing in top level JS scope, i.e.
2637
- # var _main;
2638
- # WebAssembly.instantiate(Module["wasm"], imports).then((function(output) {
2639
- # var asm = output.instance.exports;
2640
- # _main = asm["_main"];
2641
- receiving += [asmjs_mangle (s ) + ' = asm["' + s + '"];' for s in exports_that_are_not_initializers ]
2642
- else :
2643
- if shared .Settings .MINIMAL_RUNTIME :
2644
- # In wasm2js exports can be directly processed at top level, i.e.
2645
- # var asm = Module["asm"](asmGlobalArg, asmLibraryArg, buffer);
2646
- # var _main = asm["_main"];
2647
- receiving += ['var ' + asmjs_mangle (s ) + ' = asm["' + asmjs_mangle (s ) + '"];' for s in exports_that_are_not_initializers ]
2648
- else :
2649
- receiving += ['var ' + asmjs_mangle (s ) + ' = Module["' + asmjs_mangle (s ) + '"] = asm["' + s + '"];' for s in exports ]
2638
+ if shared .Settings .WASM and shared .Settings .MINIMAL_RUNTIME :
2639
+ # In Wasm exports are assigned inside a function to variables existing in top level JS scope, i.e.
2640
+ # var _main;
2641
+ # WebAssembly.instantiate(Module["wasm"], imports).then((function(output) {
2642
+ # var asm = output.instance.exports;
2643
+ # _main = asm["_main"];
2644
+ receiving += [asmjs_mangle (s ) + ' = asm["' + s + '"];' for s in exports_that_are_not_initializers ]
2650
2645
else :
2651
- receiving .append ('exportAsmFunctions(asm);' )
2646
+ if shared .Settings .MINIMAL_RUNTIME :
2647
+ # In wasm2js exports can be directly processed at top level, i.e.
2648
+ # var asm = Module["asm"](asmGlobalArg, asmLibraryArg, buffer);
2649
+ # var _main = asm["_main"];
2650
+ receiving += ['var ' + asmjs_mangle (s ) + ' = asm["' + asmjs_mangle (s ) + '"];' for s in exports_that_are_not_initializers ]
2651
+ else :
2652
+ receiving += ['var ' + asmjs_mangle (s ) + ' = Module["' + asmjs_mangle (s ) + '"] = asm["' + s + '"];' for s in exports ]
2652
2653
else :
2653
2654
receiving .append ('Module["asm"] = asm;' )
2654
2655
for e in exports :
0 commit comments