Skip to content

Commit b787395

Browse files
committed
do not call run if dependencies are resolved but we were not supposed to call run in the first place
1 parent 8e12485 commit b787395

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/preamble.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ function removeRunDependency(id) {
871871
clearInterval(runDependencyWatcher);
872872
runDependencyWatcher = null;
873873
}
874-
if (!calledRun) run();
874+
// If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
875+
if (!calledRun && shouldRunNow) run();
875876
}
876877
}
877878
Module['removeRunDependency'] = removeRunDependency;

tests/runner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8788,9 +8788,13 @@ def test_prepost(self):
87888788
self.assertNotContained('pre-run\nhello from main\npost-run\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
87898789

87908790
# noInitialRun prevents run
8791-
for no_initial_run in [0, 1]:
8791+
for no_initial_run, run_dep in [(0, 0), (1, 0), (0, 1), (1, 1)]:
8792+
print no_initial_run, run_dep
87928793
Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'main.cpp')]).communicate()
87938794
src = 'var Module = { noInitialRun: %d };\n' % no_initial_run + open(os.path.join(self.get_dir(), 'a.out.js')).read()
8795+
if run_dep:
8796+
src = src.replace('// {{PRE_RUN_ADDITIONS}}', '// {{PRE_RUN_ADDITIONS}}\naddRunDependency("test");') \
8797+
.replace('// {{POST_RUN_ADDITIONS}}', '// {{POST_RUN_ADDITIONS}}\nremoveRunDependency("test");')
87948798
open(os.path.join(self.get_dir(), 'a.out.js'), 'w').write(src)
87958799
assert ('hello from main' in run_js(os.path.join(self.get_dir(), 'a.out.js'))) != no_initial_run, 'only run if no noInitialRun'
87968800

0 commit comments

Comments
 (0)