wasm is compiled, mod in uncompiled

This commit is contained in:
Sharad Chand
2018-04-06 12:30:38 +05:45
parent 1a428d69da
commit 2b9af53030

View File

@ -236,14 +236,14 @@ impl<'a> Context<'a> {
const path = require('path'); const path = require('path');
const wasm_path = path.join(__dirname, '{module}_bg.wasm'); const wasm_path = path.join(__dirname, '{module}_bg.wasm');
const buffer = fs.readFileSync(wasm_path); 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 {{ }} else {{
return fetch('{module}_bg.wasm') return fetch('{module}_bg.wasm')
.then(response => response.arrayBuffer()) .then(response => response.arrayBuffer())
.then(bytes => WebAssembly.compile(bytes)) .then(bytes => WebAssembly.compile(bytes))
.then(wasm => __initialize(wasm, true)); .then(mod => __initialize(mod, true));
}}", module = module_name) }}", module = module_name)
} else { } else {
format!("import * as wasm from './{}_bg';", module_name) format!("import * as wasm from './{}_bg';", module_name)
@ -260,15 +260,18 @@ impl<'a> Context<'a> {
root.{module} = factory(); root.{module} = factory();
}} }}
}}(typeof self !== 'undefined' ? self : this, function() {{ }}(typeof self !== 'undefined' ? self : this, function() {{
function __initialize(wasm, __load_async) {{ let wasm;
{import_wasm}
function __initialize(__mod, __load_async) {{
const __js_exports = {{}}; const __js_exports = {{}};
const __exports = {{}}; const __exports = {{}};
{globals} {globals}
__js_exports['./{module}'] = __exports; __js_exports['./{module}'] = __exports;
if (__load_async) {{ if (__load_async) {{
return WebAssembly.instantiate(wasm, __js_exports) return WebAssembly.instantiate(__mod, __js_exports)
.then(instance => {{ .then(instance => {{
wasm = instance.exports;
return instance.exports; return instance.exports;
}}) }})
.catch(error => {{ .catch(error => {{
@ -276,11 +279,11 @@ impl<'a> Context<'a> {
throw error; throw error;
}}); }});
}} else {{ }} else {{
const instance = new WebAssembly.Instance(wasm, __js_exports); const instance = new WebAssembly.Instance(__mod, __js_exports);
wasm = instance.exports;
return instance.exports; return instance.exports;
}} }}
}} }}
{import_wasm}
}})) }}))
", ",
module = module_name, module = module_name,