From c431a42658a516a974ebd02ecb6e530081ec9bed Mon Sep 17 00:00:00 2001
From: Frank Denis <github@pureftpd.org>
Date: Thu, 5 Oct 2017 08:31:07 +0200
Subject: [PATCH] "this" doesn't seem to ever be defined in a module

isNan is undefined
---
 dist-build/emscripten.sh | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/dist-build/emscripten.sh b/dist-build/emscripten.sh
index d4392820..20cd3ca9 100755
--- a/dist-build/emscripten.sh
+++ b/dist-build/emscripten.sh
@@ -78,18 +78,16 @@ if [ "$DIST" = yes ]; then
     if (typeof Module === 'undefined') {
       Module = {};
     }
-    var root = {};
-    if (typeof this === 'object') {
-      root = this.global || this.self || this.window || this;
+    var root = Module;
+    if (root['sodium'] !== 'object') {
+      if (typeof global === 'object') {
+        root = global;
+      } else if (typeof window === 'object') {
+        root = window;
+      }
     }
-    if (typeof global === 'object') {
-      root = global;
-    }
-    if (typeof window === 'object') {
-      root = window;
-    }
-    if (root.sodium && !isNaN(root.sodium.totalMemory)) {
-      Module['TOTAL_MEMORY'] = root.sodium.totalMemory;
+    if (root['sodium'] === 'object' && typeof root['sodium']['totalMemory'] === 'number') {
+      Module['TOTAL_MEMORY'] = root['sodium']['totalMemory'];
     }
     var _Module = Module;
     Module.ready = new Promise(function (resolve, reject) {