diff options
-rw-r--r-- | src/postamble.js | 8 | ||||
-rw-r--r-- | src/settings.js | 4 | ||||
-rwxr-xr-x | tests/runner.py | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/src/postamble.js b/src/postamble.js index ea520eae..8dd01589 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -3,6 +3,7 @@ Module.callMain = function callMain(args) { assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on __ATMAIN__)'); + assert(!Module['preRun'] || Module['preRun'].length == 0, 'cannot call main when preRun functions remain to be called'); args = args || []; @@ -82,7 +83,7 @@ function run(args) { var ret = 0; calledRun = true; - if (Module['_main']) { + if (Module['_main'] && shouldRunNow) { ret = Module.callMain(args); if (!Module['noExitRuntime']) { exitRuntime(); @@ -121,6 +122,7 @@ if (Module['preInit']) { } } +// shouldRunNow refers to calling main(), not run(). #if INVOKE_RUN var shouldRunNow = true; #else @@ -130,9 +132,7 @@ if (Module['noInitialRun']) { shouldRunNow = false; } -if (shouldRunNow) { - run(); -} +run(); // {{POST_RUN_ADDITIONS}} diff --git a/src/settings.js b/src/settings.js index f9b47228..78a21616 100644 --- a/src/settings.js +++ b/src/settings.js @@ -35,8 +35,8 @@ var ASSERTIONS = 1; // Whether we should add runtime assertions, for example to // if code flow runs into a fault var VERBOSE = 0; // When set to 1, will generate more verbose output during compilation. -var INVOKE_RUN = 1; // Whether we will call run(). Disable if you embed the generated - // code in your own, and will call run() yourself at the right time +var INVOKE_RUN = 1; // Whether we will run the main() function. Disable if you embed the generated + // code in your own, and will call main() yourself at the right time. var INIT_HEAP = 0; // Whether to initialize memory anywhere other than the stack to 0. var TOTAL_STACK = 5*1024*1024; // The total stack size. There is no way to enlarge the stack, so this // value must be large enough for the program's requirements. If diff --git a/tests/runner.py b/tests/runner.py index 982b6899..325ecdb5 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -10016,7 +10016,7 @@ f.close() self.assertNotContained('pre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js'))) # noInitialRun prevents run - for no_initial_run, run_dep in [(0, 0), (1, 0), (0, 1), (1, 1)]: + for no_initial_run, run_dep in [(0, 0), (1, 0), (0, 1)]: print no_initial_run, run_dep Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp')]).communicate() src = 'var Module = { noInitialRun: %d };\n' % no_initial_run + open(os.path.join(self.get_dir(), 'a.out.js')).read() |