diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-05-09 21:36:08 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-05-09 21:36:08 -0700 |
commit | a7ef69ec6fd292e2252424743b0a0dc9ed67f89f (patch) | |
tree | 1dcce3efe4b46c68c3a1dfb3625e6b1b2c6d6701 | |
parent | bb9317e1eb68a975cb9462d0cd61c62ff6061a49 (diff) |
allow adding runDependencies in preRun
-rw-r--r-- | src/postamble.js | 5 | ||||
-rw-r--r-- | src/preamble.js | 3 | ||||
-rw-r--r-- | tests/pre_run_deps.cpp | 10 | ||||
-rwxr-xr-x | tests/runner.py | 14 |
4 files changed, 32 insertions, 0 deletions
diff --git a/src/postamble.js b/src/postamble.js index cf863669..24b8e4a1 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -38,6 +38,11 @@ function run(args) { if (Module['preRun']) { Module['preRun'](); + if (runDependencies > 0) { + // preRun added a dependency, run will be called later + Module['preRun'] = null; + return 0; + } } var ret = null; diff --git a/src/preamble.js b/src/preamble.js index e9ba2009..997e5ab3 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -854,6 +854,9 @@ var STRING_TABLE = []; // do asynchronous work before running, increment this and // decrement it. Incrementing must happen in a place like // PRE_RUN_ADDITIONS (used by emcc to add file preloading). +// Note that you can add dependencies in preRun, even though +// it happens right before run - run will be postponed until +// the dependencies are met. var runDependencies = 0; function addRunDependency() { runDependencies++; diff --git a/tests/pre_run_deps.cpp b/tests/pre_run_deps.cpp new file mode 100644 index 00000000..41c06972 --- /dev/null +++ b/tests/pre_run_deps.cpp @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <emscripten.h> + +int main() { + printf("main() called.\n"); + int result = emscripten_run_script_int("Module.okk"); + REPORT_RESULT(); + return 1; +} + diff --git a/tests/runner.py b/tests/runner.py index f44dc95a..a1a3425a 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7299,6 +7299,20 @@ elif 'browser' in str(sys.argv): def test_cubegeom_color2(self): self.btest('cubegeom_color2.c', expected='1121999515') + def test_pre_run_deps(self): + # Adding a dependency in preRun will delay run + open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' + Module.preRun = function() { + addRunDependency(); + Module.print('preRun called, added a dependency...'); + setTimeout(function() { + Module.okk = 10; + removeRunDependency() + }, 2000); + }; + ''') + self.btest('pre_run_deps.cpp', expected='10', args=['--pre-js', 'pre.js']) + elif 'benchmark' in str(sys.argv): # Benchmarks. Run them with argument |benchmark|. To run a specific test, do # |benchmark.test_X|. |