[HTML5] Preloader fetch, streaming instantiation.

This commit is contained in:
Fabio Alessandrelli 2021-03-01 11:26:22 +01:00
parent 8a020a6573
commit f64ec5f1ad
4 changed files with 103 additions and 70 deletions

View file

@ -227,10 +227,10 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
/**
* @ignore
* @param {string} loadPath
* @param {Promise} loadPromise
* @param {Response} response
*/
Config.prototype.getModuleConfig = function (loadPath, loadPromise) {
let loader = loadPromise;
Config.prototype.getModuleConfig = function (loadPath, response) {
let r = response;
return {
'print': this.onPrint,
'printErr': this.onPrintError,
@ -238,12 +238,17 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
'noExitRuntime': true,
'dynamicLibraries': [`${loadPath}.side.wasm`],
'instantiateWasm': function (imports, onSuccess) {
loader.then(function (xhr) {
WebAssembly.instantiate(xhr.response, imports).then(function (result) {
onSuccess(result['instance'], result['module']);
function done(result) {
onSuccess(result['instance'], result['module']);
}
if (typeof (WebAssembly.instantiateStreaming) !== 'undefined') {
WebAssembly.instantiateStreaming(Promise.resolve(r), imports).then(done);
} else {
r.arrayBuffer().then(function (buffer) {
WebAssembly.instantiate(buffer, imports).then(done);
});
});
loader = null;
}
r = null;
return {};
},
'locateFile': function (path) {