From 50f7b19f2016edd75c8d985442babb469c33d8a3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 30 Jul 2015 17:12:57 -0700 Subject: [PATCH] export Module when wasm --- emcc | 2 +- third_party/wasm-polyfill/wasmator.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/emcc b/emcc index 010b24ea5..3a38c6b94 100755 --- a/emcc +++ b/emcc @@ -1820,7 +1820,7 @@ try { if shared.Settings.WASM: logging.debug('converting to WebAssembly') wasm_target = unsuffixed(js_target) + '.wasm' - subprocess.check_call([shared.PYTHON, shared.path_from_root('third_party', 'wasm-polyfill', 'wasmator.py'), js_target, wasm_target]) + subprocess.check_call([shared.PYTHON, shared.path_from_root('third_party', 'wasm-polyfill', 'wasmator.py'), js_target, wasm_target, shared.Settings.EXPORT_NAME]) log_time('final emitting') diff --git a/third_party/wasm-polyfill/wasmator.py b/third_party/wasm-polyfill/wasmator.py index 0e7999c19..11eb72928 100644 --- a/third_party/wasm-polyfill/wasmator.py +++ b/third_party/wasm-polyfill/wasmator.py @@ -30,6 +30,7 @@ import shared as emscripten jsfile = sys.argv[1] wasmfile = sys.argv[2] +export_name = sys.argv[3] tempfile = jsfile + '.temp.js' tempfile2 = jsfile + '.temp2.js' @@ -86,17 +87,20 @@ function runEmscriptenModule(Module, unwasmed_) { ''' + patched + ''' + return Module; } ''' + open(path_in_polyfill('jslib', 'load-wasm.js')).read() + ''' // note: web worker messages must be queued, as we delay the scripts chance to listen to them +var ''' + export_name + '''; + loadWebAssembly("''' + wasmfile + '''", 'load-wasm-worker.js').then(function(unwasmed) { if (typeof importScripts === 'function') { onmessage = null; } - runEmscriptenModule(typeof Module !== 'undefined' ? Module : {}, unwasmed); + ''' + export_name + ''' = runEmscriptenModule(typeof Module !== 'undefined' ? Module : {}, unwasmed); if (typeof importScripts === 'function' && onmessage) { queuedMessages.forEach(function(e) { onmessage(e);