@@ -437,8 +437,9 @@ def log_time(name):
437437 default_cxx_std = '-std=c++03' # Enforce a consistent C++ standard when compiling .cpp files, if user does not specify one on the cmdline.
438438 use_closure_compiler = None
439439 js_transform = None
440- pre_js = ''
441- post_js = ''
440+ pre_js = '' # before all js
441+ post_module = '' # in js, after Module exists
442+ post_js = '' # after all js
442443 preload_files = []
443444 embed_files = []
444445 exclude_files = []
@@ -1695,12 +1696,15 @@ def save_intermediate(name=None, suffix='js'):
16951696 else :
16961697 wasm_js_glue = wasm_js_glue .replace ('{{{ wasmJSMethod }}}' , 'null' )
16971698 wasm_js_glue = wasm_js_glue .replace ('{{{ WASM_BACKEND }}}' , str (shared .Settings .WASM_BACKEND )) # if wasm backend, wasm contains memory segments
1698- pre_js = wasm_js_glue + '\n ' + pre_js
1699+ wasm_js_glue += '\n integrateWasmJS(Module);\n ' # add a call
1700+ post_module += wasm_js_glue # we can set up the glue once we have the module
16991701
17001702 # Apply pre and postjs files
1701- if pre_js or post_js :
1703+ if pre_js or post_module or post_js :
17021704 logging .debug ('applying pre/postjses' )
17031705 src = open (final ).read ()
1706+ if post_module :
1707+ src = src .replace ('// {{PREAMBLE_ADDITIONS}}' , post_module + '\n // {{PREAMBLE_ADDITIONS}}' )
17041708 final += '.pp.js'
17051709 if WINDOWS : # Avoid duplicating \r\n to \r\r\n when writing out.
17061710 if pre_js : pre_js = pre_js .replace ('\r \n ' , '\n ' )
@@ -1779,13 +1783,6 @@ def repl(m):
17791783 if shared .Settings .FETCH and shared .Settings .USE_PTHREADS :
17801784 shared .make_fetch_worker (final , os .path .join (os .path .dirname (os .path .abspath (target )), 'fetch-worker.js' ))
17811785
1782- if shared .Settings .BINARYEN :
1783- # Insert a call to integrate with wasm.js
1784- js = open (final ).read ()
1785- js = js .replace ('// {{PREAMBLE_ADDITIONS}}' , 'integrateWasmJS(Module);\n // {{PREAMBLE_ADDITIONS}}' )
1786- final += '.binaryen.js'
1787- open (final , 'w' ).write (js )
1788-
17891786 # exit block 'memory initializer'
17901787 log_time ('memory initializer' )
17911788
0 commit comments