summaryrefslogtreecommitdiffstats
path: root/platform/javascript/js/engine/config.js
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-03-01 11:26:22 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-03-05 20:11:18 +0100
commit272e491f52d4277667c35021f5fdf60655ccc917 (patch)
treea6fa2dfaf4adf223e154e8d5dc28ce348e6d35f8 /platform/javascript/js/engine/config.js
parent4de0768cdbaf68781214601e679548a69c15c673 (diff)
downloadredot-engine-272e491f52d4277667c35021f5fdf60655ccc917.tar.gz
[HTML5] Preloader fetch, streaming instantiation.
Diffstat (limited to 'platform/javascript/js/engine/config.js')
-rw-r--r--platform/javascript/js/engine/config.js21
1 files changed, 13 insertions, 8 deletions
diff --git a/platform/javascript/js/engine/config.js b/platform/javascript/js/engine/config.js
index bba20dc360..8c2636c7ab 100644
--- a/platform/javascript/js/engine/config.js
+++ b/platform/javascript/js/engine/config.js
@@ -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) {