Merge pull request #1723 from alexcrichton/instntiate-streaming

Improve instantiateStreaming fallback
This commit is contained in:
Alex Crichton 2019-08-15 11:55:51 -05:00 committed by GitHub
commit bd7c90788a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -536,13 +536,19 @@ impl<'a> Context<'a> {
if (typeof WebAssembly.instantiateStreaming === 'function') {{
result = WebAssembly.instantiateStreaming(response, imports)
.catch(e => {{
console.warn(\"`WebAssembly.instantiateStreaming` failed. Assuming this is \
because your server does not serve wasm with \
`application/wasm` MIME type. Falling back to \
`WebAssembly.instantiate` which is slower. Original \
error:\\n\", e);
return response
.then(r => r.arrayBuffer())
.then(r => {{
if (r.headers.get('Content-Type') != 'application/wasm') {{
console.warn(\"`WebAssembly.instantiateStreaming` failed \
because your server does not serve wasm with \
`application/wasm` MIME type. Falling back to \
`WebAssembly.instantiate` which is slower. Original \
error:\\n\", e);
return r.arrayBuffer();
}} else {{
throw e;
}}
}})
.then(bytes => WebAssembly.instantiate(bytes, imports));
}});
}} else {{