From 2b9af530308b44c066515184c130352f72949842 Mon Sep 17 00:00:00 2001 From: Sharad Chand Date: Fri, 6 Apr 2018 12:30:38 +0545 Subject: [PATCH] wasm is compiled, mod in uncompiled --- crates/cli-support/src/js.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/cli-support/src/js.rs b/crates/cli-support/src/js.rs index dbed199d2..02de09524 100644 --- a/crates/cli-support/src/js.rs +++ b/crates/cli-support/src/js.rs @@ -236,14 +236,14 @@ impl<'a> Context<'a> { const path = require('path'); const wasm_path = path.join(__dirname, '{module}_bg.wasm'); const buffer = fs.readFileSync(wasm_path); - const wasm = new WebAssembly.Module(buffer); + const mod = new WebAssembly.Module(buffer); - return __initialize(wasm, false); + return __initialize(mod, false); }} else {{ return fetch('{module}_bg.wasm') .then(response => response.arrayBuffer()) .then(bytes => WebAssembly.compile(bytes)) - .then(wasm => __initialize(wasm, true)); + .then(mod => __initialize(mod, true)); }}", module = module_name) } else { format!("import * as wasm from './{}_bg';", module_name) @@ -260,15 +260,18 @@ impl<'a> Context<'a> { root.{module} = factory(); }} }}(typeof self !== 'undefined' ? self : this, function() {{ - function __initialize(wasm, __load_async) {{ + let wasm; + {import_wasm} + function __initialize(__mod, __load_async) {{ const __js_exports = {{}}; const __exports = {{}}; {globals} __js_exports['./{module}'] = __exports; if (__load_async) {{ - return WebAssembly.instantiate(wasm, __js_exports) + return WebAssembly.instantiate(__mod, __js_exports) .then(instance => {{ + wasm = instance.exports; return instance.exports; }}) .catch(error => {{ @@ -276,11 +279,11 @@ impl<'a> Context<'a> { throw error; }}); }} else {{ - const instance = new WebAssembly.Instance(wasm, __js_exports); + const instance = new WebAssembly.Instance(__mod, __js_exports); + wasm = instance.exports; return instance.exports; }} }} - {import_wasm} }})) ", module = module_name,