From 403da0d1fcd21d4d8803b96c6c4227fc3e19178b Mon Sep 17 00:00:00 2001 From: Ryan Lester Date: Wed, 11 Sep 2019 10:49:46 -0400 Subject: [PATCH] fix for asm.js async loading --- dist-build/emscripten.sh | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/dist-build/emscripten.sh b/dist-build/emscripten.sh index 0125b0a7..3f5d8ded 100755 --- a/dist-build/emscripten.sh +++ b/dist-build/emscripten.sh @@ -118,20 +118,28 @@ if [ "$DIST" = yes ]; then } }; Module.useBackupModule = function() { - var Module = {}; - $(cat "${PREFIX}/lib/libsodium.asm.tmp.js" | sed 's|use asm||g') - Object.keys(_Module).forEach(function(k) { - if (k !== 'getRandomValue') { - delete _Module[k]; - } - }); - Object.keys(Module).forEach(function(k) { - _Module[k] = Module[k]; + return new Promise(function(resolve, reject) { + var Module = {}; + Module.onAbort = reject; + + Module.onRuntimeInitialized = function() { + Object.keys(_Module).forEach(function(k) { + if (k !== 'getRandomValue') { + delete _Module[k]; + } + }); + Object.keys(Module).forEach(function(k) { + _Module[k] = Module[k]; + }); + resolve(); + }; + + $(cat "${PREFIX}/lib/libsodium.asm.tmp.js" | sed 's|use asm||g') }); }; $(cat "${PREFIX}/lib/libsodium.wasm.tmp.js") }).catch(function() { - _Module.useBackupModule(); + return _Module.useBackupModule(); }); EOM