mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 17:21:35 +00:00
Use instantiateStreaming for --no-modules mode if possible
This commit is contained in:
committed by
Alex Crichton
parent
94fe55ce80
commit
9c275d1f1d
@ -406,10 +406,16 @@ impl<'a> Context<'a> {
|
||||
const __exports = {{}};
|
||||
{globals}
|
||||
function init(wasm_path) {{
|
||||
return fetch(wasm_path)
|
||||
const fetchPromise = fetch(wasm_path);
|
||||
let resultPromise;
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {{
|
||||
resultPromise = WebAssembly.instantiateStreaming(fetchPromise, {{ './{module}': __exports }});
|
||||
}} else {{
|
||||
resultPromise = fetchPromise
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}))
|
||||
.then(({{instance}}) => {{
|
||||
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}));
|
||||
}}
|
||||
return resultPromise.then(({{instance}}) => {{
|
||||
wasm = init.wasm = instance.exports;
|
||||
return;
|
||||
}});
|
||||
|
Reference in New Issue
Block a user