From af5ce360b472ee6199bb7e05f79512f7e2ce261b Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 5 Oct 2017 08:12:05 +0200 Subject: [PATCH] `this` may not be defined --- dist-build/emscripten.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dist-build/emscripten.sh b/dist-build/emscripten.sh index b7ab90df..d4392820 100755 --- a/dist-build/emscripten.sh +++ b/dist-build/emscripten.sh @@ -74,12 +74,22 @@ if [ "$DIST" = yes ]; then emccLibsodium "${PREFIX}/lib/libsodium.wasm.tmp.js" -O3 -s WASM=1 cat > "${PREFIX}/lib/libsodium.js" <<- EOM + var Module; if (typeof Module === 'undefined') { - var Module = {}; + Module = {}; + } + var root = {}; + if (typeof this === 'object') { + root = this.global || this.self || this.window || this; + } + if (typeof global === 'object') { + root = global; + } + if (typeof window === 'object') { + root = window; } - var root = this.global || this.self || this.window || this; if (root.sodium && !isNaN(root.sodium.totalMemory)) { - Module.TOTAL_MEMORY = root.sodium.totalMemory; + Module['TOTAL_MEMORY'] = root.sodium.totalMemory; } var _Module = Module; Module.ready = new Promise(function (resolve, reject) {