diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/postamble.js | 11 | ||||
-rw-r--r-- | src/preamble.js | 10 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/postamble.js b/src/postamble.js index fb552606..066b83e3 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -37,14 +37,9 @@ function run(args) { __globalConstructor__(); - _main(argc, argv); - - while( __ATEXIT__.length > 0) { - var func = __ATEXIT__.pop(); - if (typeof func === 'number') { - func = FUNCTION_TABLE[func]; - } - func(); + if (Module['_main']) { + _main(argc, argv); + __shutdownRuntime__(); } } diff --git a/src/preamble.js b/src/preamble.js index 07ddf7ea..8a42243a 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -168,6 +168,16 @@ function __initializeRuntime__() { STATICTOP = alignMemoryPage(STACK_MAX); } +function __shutdownRuntime__() { + while( __ATEXIT__.length > 0) { + var func = __ATEXIT__.pop(); + if (typeof func === 'number') { + func = FUNCTION_TABLE[func]; + } + func(); + } +} + // stdio.h // C-style: we work on ints on the HEAP. |