Use instantiateStreaming for --no-modules mode if possible
@@ -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;
}});
