From 0f6626977bd246acc14d320ac8872ef1e751c998 Mon Sep 17 00:00:00 2001 From: Leon Krause Date: Tue, 27 Mar 2018 09:06:19 +0200 Subject: [PATCH] Expose Emscripten libs to engine.js discreetly (cherry picked from commit 63c7fc6358343c3de6cfaa40436063646eb8b7a1) --- platform/javascript/detect.py | 1 - platform/javascript/engine.js | 7 +++++-- platform/javascript/pre.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 74d6536343e..485a586f2b1 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -116,7 +116,6 @@ def configure(env): env.Append(LINKFLAGS=['-s', 'BINARYEN=1']) env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1']) env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1']) - env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS="[\'FS\']"']) env.Append(LINKFLAGS=['-s', 'INVOKE_RUN=0']) env.Append(LINKFLAGS=['-s', 'NO_EXIT_RUNTIME=1']) diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js index bca1851f402..527587c7c5d 100644 --- a/platform/javascript/engine.js +++ b/platform/javascript/engine.js @@ -1,3 +1,4 @@ + exposedLibs['FS'] = FS; return Module; }, }; @@ -31,6 +32,8 @@ this.rtenv = null; + var LIBS = {}; + var initPromise = null; var unloadAfterInit = true; @@ -80,7 +83,7 @@ return new Promise(function(resolve, reject) { rtenvProps.onRuntimeInitialized = resolve; rtenvProps.onAbort = reject; - rtenvProps.engine.rtenv = Engine.RuntimeEnvironment(rtenvProps); + rtenvProps.engine.rtenv = Engine.RuntimeEnvironment(rtenvProps, LIBS); }); } @@ -175,7 +178,7 @@ this.rtenv.thisProgram = executableName || getBaseName(basePath); preloadedFiles.forEach(function(file) { - this.rtenv.FS.createDataFile('/', file.name, new Uint8Array(file.buffer), true, true, true); + LIBS.FS.createDataFile('/', file.name, new Uint8Array(file.buffer), true, true, true); }, this); preloadedFiles = null; diff --git a/platform/javascript/pre.js b/platform/javascript/pre.js index 311aa44fda9..02194bc75ea 100644 --- a/platform/javascript/pre.js +++ b/platform/javascript/pre.js @@ -1,2 +1,2 @@ var Engine = { - RuntimeEnvironment: function(Module) { + RuntimeEnvironment: function(Module, exposedLibs) {