aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-04-09 20:09:45 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-04-09 20:47:55 -0700
commit86097bafbe336131ba9cf2d8d8d2fd1a8774e570 (patch)
treeaba1ca83fda1b2c90921a2b0a7a733cc001d2843
parentfa307241513ecc2e9a7711c79ed0b3a7e321f686 (diff)
init runtime immediately, so that even with noInitialRun we can still call filesystem-using functions and they will work
-rw-r--r--src/library.js3
-rw-r--r--src/postamble.js5
-rw-r--r--src/preamble.js5
-rwxr-xr-xtests/runner.py9
4 files changed, 17 insertions, 5 deletions
diff --git a/src/library.js b/src/library.js
index 56583c76..19b8e90f 100644
--- a/src/library.js
+++ b/src/library.js
@@ -26,7 +26,8 @@ LibraryManager.library = {
_impure_ptr: 0,
$FS__deps: ['$ERRNO_CODES', '__setErrNo', 'stdin', 'stdout', 'stderr', '_impure_ptr'],
- $FS__postset: '__ATINIT__.unshift({ func: function() { FS.ignorePermissions = false; if (!FS.init.initialized) FS.init() } });' +
+ $FS__postset: '__ATINIT__.unshift({ func: function() { if (!Module["noFSInit"] && !FS.init.initialized) FS.init() } });' +
+ '__ATMAIN__.push({ func: function() { FS.ignorePermissions = false } });' +
'__ATEXIT__.push({ func: function() { FS.quit() } });',
$FS: {
// The path to the current folder.
diff --git a/src/postamble.js b/src/postamble.js
index 1f4c9c04..cf863669 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -40,10 +40,9 @@ function run(args) {
Module['preRun']();
}
- initRuntime();
-
var ret = null;
if (Module['_main']) {
+ preMain();
ret = Module.callMain(args);
if (!Module['noExitRuntime']) {
exitRuntime();
@@ -60,6 +59,8 @@ Module['run'] = run;
// {{PRE_RUN_ADDITIONS}}
+initRuntime();
+
#if INVOKE_RUN
#else
addRunDependency();
diff --git a/src/preamble.js b/src/preamble.js
index 39412bc3..968571a0 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -697,12 +697,15 @@ function callRuntimeCallbacks(callbacks) {
}
var __ATINIT__ = []; // functions called during startup
+var __ATMAIN__ = []; // functions called when main() is to be run
var __ATEXIT__ = []; // functions called during shutdown
function initRuntime() {
callRuntimeCallbacks(__ATINIT__);
}
-
+function preMain() {
+ callRuntimeCallbacks(__ATMAIN__);
+}
function exitRuntime() {
callRuntimeCallbacks(__ATEXIT__);
diff --git a/tests/runner.py b/tests/runner.py
index 477cd29c..3baf91fd 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -3825,6 +3825,7 @@ Pass: 0.000012 0.000012''')
def process(filename):
src = \'\'\'
var Module = {
+ 'noFSInit': true,
'preRun': function() {
FS.createDataFile('/', 'somefile.binary', [100, 200, 50, 25, 10, 77, 123], true, false); // 200 becomes -56, since signed chars are used in memory
FS.createLazyFile('/', 'test.file', 'test.file', true, false);
@@ -6551,10 +6552,16 @@ f.close()
# noInitialRun prevents run
for no_initial_run in [0, 1]:
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();
+ src = 'var Module = { noInitialRun: %d };\n' % no_initial_run + open(os.path.join(self.get_dir(), 'a.out.js')).read()
open(os.path.join(self.get_dir(), 'a.out.js'), 'w').write(src)
assert ('hello from main' in run_js(os.path.join(self.get_dir(), 'a.out.js'))) != no_initial_run, 'only run if no noInitialRun'
+ if no_initial_run:
+ # Calling main later should still work, filesystem etc. must be set up.
+ src = open(os.path.join(self.get_dir(), 'a.out.js')).read() + '\n_main();\n';
+ open(os.path.join(self.get_dir(), 'a.out.js'), 'w').write(src)
+ assert 'hello from main' in run_js(os.path.join(self.get_dir(), 'a.out.js')), 'main should print when called manually'
+
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()