mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-28 05:52:21 +03:00
Use instantiateStreaming for --no-modules mode if possible
This commit is contained in:
parent
94fe55ce80
commit
9c275d1f1d
@ -406,13 +406,19 @@ impl<'a> Context<'a> {
|
||||
const __exports = {{}};
|
||||
{globals}
|
||||
function init(wasm_path) {{
|
||||
return fetch(wasm_path)
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}))
|
||||
.then(({{instance}}) => {{
|
||||
wasm = init.wasm = instance.exports;
|
||||
return;
|
||||
}});
|
||||
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 }}));
|
||||
}}
|
||||
return resultPromise.then(({{instance}}) => {{
|
||||
wasm = init.wasm = instance.exports;
|
||||
return;
|
||||
}});
|
||||
}};
|
||||
self.{global_name} = Object.assign(init, __exports);
|
||||
}})();
|
||||
|
Loading…
Reference in New Issue
Block a user