mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
Wasm: update loader to use instantiateStreaming method
This commit is contained in:
parent
1399045ff6
commit
6222241651
|
@ -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 };
|
||||||
}();
|
}();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user