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) { 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) { if (!options) {
options = {}; options = {};
} }
@ -188,12 +169,12 @@ TeaVM.wasm = function() {
options.installImports(importObj); options.installImports(importObj);
} }
return WebAssembly.instantiate(data, importObj).then(resultObject => { return WebAssembly.instantiateStreaming(fetch(path), importObj).then((obj => {
controller.instance = resultObject.instance; controller.instance = obj.instance;
let teavm = createTeaVM(resultObject.instance); let teavm = createTeaVM(obj.instance);
teavm.main = createMain(teavm, controller); teavm.main = createMain(teavm, controller);
return teavm; return teavm;
}); }));
} }
function createMain(teavm, controller) { function createMain(teavm, controller) {
@ -223,5 +204,5 @@ TeaVM.wasm = function() {
} }
} }
return { JavaError, load, create }; return { JavaError, load };
}(); }();