mirror of
https://github.com/konsoletyper/teavm.git
synced 2024-11-21 01:00:54 +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) {
|
||||
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 };
|
||||
}();
|
||||
|
Loading…
Reference in New Issue
Block a user