diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-03-22 13:48:53 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-03-22 13:48:53 -0700 |
commit | e65c9798d79e84385e9caeb79c6055881ad64087 (patch) | |
tree | e1ee269faa1a7ef6182a3b954845791a19a86f5e | |
parent | 3b7bd2555a5e42814ce6c2ff39cc1dccc72d50dc (diff) |
do preRun and postRun only if we actually run
-rw-r--r-- | src/postamble.js | 17 | ||||
-rwxr-xr-x | tests/runner.py | 23 |
2 files changed, 32 insertions, 8 deletions
diff --git a/src/postamble.js b/src/postamble.js index 4a2fbf60..c42d6794 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -34,6 +34,10 @@ function run(args) { initRuntime(); + if (Module['preRun']) { + Module['preRun'](); + } + var ret = null; if (Module['_main']) { ret = Module.callMain(args); @@ -41,16 +45,17 @@ function run(args) { exitRuntime(); } } + + if (Module['postRun']) { + Module['postRun'](); + } + return ret; } Module['run'] = run; // {{PRE_RUN_ADDITIONS}} -if (Module['preRun']) { - Module['preRun'](); -} - #if INVOKE_RUN #else addRunDependency(); @@ -65,7 +70,3 @@ if (runDependencies == 0) { // {{POST_RUN_ADDITIONS}} -if (Module['postRun']) { - Module['postRun'](); -} - diff --git a/tests/runner.py b/tests/runner.py index fddcf1df..00c78a35 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6539,6 +6539,29 @@ f.close() Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'before.js', '--post-js', 'after.js']).communicate() self.assertContained('hello from main\nhello from js\n', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_prepost(self): + open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(''' + #include <stdio.h> + int main() { + printf("hello from main\\n"); + return 0; + } + ''') + open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' + var Module = { + preRun: function() { Module.print('pre-run') }, + postRun: function() { Module.print('post-run') } + }; + ''') + + Popen(['python', EMCC, os.path.join(self.get_dir(), 'main.cpp'), '--pre-js', 'pre.js']).communicate() + self.assertContained('pre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + + # never run, so no preRun or postRun + src = open(os.path.join(self.get_dir(), 'a.out.js')).read().replace('// {{PRE_RUN_ADDITIONS}}', 'addRunDependency()') + open(os.path.join(self.get_dir(), 'a.out.js'), 'w').write(src) + self.assertNotContained('pre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_eliminator(self): input = open(path_from_root('tools', 'eliminator', 'eliminator-test.js')).read() expected = open(path_from_root('tools', 'eliminator', 'eliminator-test-output.js')).read() |