Fall back to WebAssembly.compile on mime type error (#628)

This commit is contained in:
jcaesar 2020-03-31 02:28:34 +09:00 committed by GitHub
parent 3ec7849cfe
commit 7398edb787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 5 deletions

View File

@ -331,13 +331,22 @@ var languagePluginLoader = new Promise((resolve, reject) => {
Module.preloadedWasm = {};
let isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
let wasm_promise;
let wasm_promise, wasm_fetch = fetch(wasmURL);
const compileBuffer = () =>
wasm_fetch.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.compile(bytes));
if (WebAssembly.compileStreaming === undefined) {
wasm_promise = fetch(wasmURL)
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.compile(bytes));
wasm_promise = compileBuffer();
} else {
wasm_promise = WebAssembly.compileStreaming(fetch(wasmURL));
wasm_promise = WebAssembly.compileStreaming(wasm_fetch);
wasm_promise = wasm_promise.catch(e => {
if (e instanceof TypeError) {
console.error("pyodide streaming compilation failed:", e,
"- falling back to buffered compilation");
return compileBuffer()
}
throw e;
});
}
Module.instantiateWasm = (info, receiveInstance) => {