mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 17:51:33 +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 = {{}};
|
const __exports = {{}};
|
||||||
{globals}
|
{globals}
|
||||||
function init(wasm_path) {{
|
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(response => response.arrayBuffer())
|
||||||
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}))
|
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}));
|
||||||
.then(({{instance}}) => {{
|
}}
|
||||||
|
return resultPromise.then(({{instance}}) => {{
|
||||||
wasm = init.wasm = instance.exports;
|
wasm = init.wasm = instance.exports;
|
||||||
return;
|
return;
|
||||||
}});
|
}});
|
||||||
|
Reference in New Issue
Block a user