diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-04-05 10:53:09 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-04-05 10:53:09 -0700 |
commit | 8098fe7e06ff47d6944afd47158aac22d9354d32 (patch) | |
tree | c2620e8d9b0813357b19f9c1dd1ad0a554f4c2ce /src | |
parent | 1c504965bdb643dc338774a4eb5027a0030ae837 (diff) |
refactor runtime initialization
Diffstat (limited to 'src')
-rw-r--r-- | src/postamble.js | 10 | ||||
-rw-r--r-- | src/preamble.js | 6 |
2 files changed, 7 insertions, 9 deletions
diff --git a/src/postamble.js b/src/postamble.js index 971568cd..576366fe 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -4,10 +4,7 @@ Module.callMain = function callMain(args) { args = args || []; - if (!calledInit) { - initRuntime(); - calledInit = true; - } + ensureInitRuntime(); var argc = args.length+1; function pad() { @@ -58,10 +55,7 @@ Module.callMain = function callMain(args) { function run(args) { args = args || Module['arguments']; - if (!calledInit) { - initRuntime(); - calledInit = true; - } + ensureInitRuntime(); if (runDependencies > 0) { Module.printErr('run() called, but dependencies remain, so not running'); diff --git a/src/preamble.js b/src/preamble.js index e7778b30..f85cf4f3 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() { |