Wasm: update loader to use instantiateStreaming method

This commit is contained in:
Alexey Andreev 2022-11-20 14:05:35 +01:00
parent 1399045ff6
commit 6222241651

View File

@ -159,25 +159,6 @@ TeaVM.wasm = function() {
}
function load(path, options) {
let xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
xhr.open("GET", path);
return new Promise((resolve, reject) => {
xhr.onload = () => {
let response = xhr.response;
if (!response) {
reject("Error loading Wasm data")
return;
}
resolve(response);
};
xhr.send();
}).then(data => create(data, options));
}
function create(data, options) {
if (!options) {
options = {};
}
@ -188,12 +169,12 @@ TeaVM.wasm = function() {
options.installImports(importObj);
}
return WebAssembly.instantiate(data, importObj).then(resultObject => {
controller.instance = resultObject.instance;
let teavm = createTeaVM(resultObject.instance);
return WebAssembly.instantiateStreaming(fetch(path), importObj).then((obj => {
controller.instance = obj.instance;
let teavm = createTeaVM(obj.instance);
teavm.main = createMain(teavm, controller);
return teavm;
});
}));
}
function createMain(teavm, controller) {
@ -223,5 +204,5 @@ TeaVM.wasm = function() {
}
}
return { JavaError, load, create };
return { JavaError, load };
}();