diff options
Diffstat (limited to 'src/preamble.js')
-rw-r--r-- | src/preamble.js | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/preamble.js b/src/preamble.js index 2cff440c..68510e3a 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -718,7 +718,11 @@ var __ATINIT__ = []; // functions called during startup var __ATMAIN__ = []; // functions called when main() is to be run var __ATEXIT__ = []; // functions called during shutdown -function initRuntime() { +var runtimeInitialized = false; + +function ensureInitRuntime() { + if (runtimeInitialized) return; + runtimeInitialized = true; callRuntimeCallbacks(__ATINIT__); } function preMain() { @@ -805,7 +809,7 @@ Math.imul = function(a, b) { // the dependencies are met. var runDependencies = 0; var runDependencyTracking = {}; -var calledRun = false; +var calledInit = false, calledRun = false; var runDependencyWatcher = null; function addRunDependency(id) { runDependencies++; @@ -861,6 +865,12 @@ Module['removeRunDependency'] = removeRunDependency; Module["preloadedImages"] = {}; // maps url to image data Module["preloadedAudios"] = {}; // maps url to audio data +function addPreRun(func) { + if (!Module['preRun']) Module['preRun'] = []; + else if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']]; + Module['preRun'].push(func); +} + #if PGO var PGOMonitor = { called: {}, @@ -874,9 +884,32 @@ var PGOMonitor = { } }; __ATEXIT__.push({ func: function() { PGOMonitor.dump() } }); -if (!Module.preRun) Module.preRun = []; -Module.preRun.push(function() { addRunDependency('pgo') }); +addPreRun(function() { addRunDependency('pgo') }); +#endif + +function loadMemoryInitializer(filename) { + function applyData(data) { +#if USE_TYPED_ARRAYS == 2 + HEAPU8.set(data, TOTAL_STACK); +#else + allocate(data, 'i8', ALLOC_NONE, TOTAL_STACK); #endif + } + + if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) { + // synchronous + applyData(Module['readBinary'](filename)); + } else { + // asynchronous + addPreRun(function() { + Browser.asyncLoad(filename, function(data) { + applyData(data); + }, function(data) { + throw 'could not load memory initializer ' + filename; + }); + }); + } +} // === Body === |