aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-04-09 16:25:56 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-04-09 17:26:57 -0700
commit7b2d1583a184edef4b920982426706224b937414 (patch)
tree8f93cbbd4990365241b17fd7e2a9b355eb1d2cd1
parentbba3cd9cf5d797a2aef02bf966d595d3ec3cbcad (diff)
run postsets right before main, and after the memory initializer has been set up
-rw-r--r--src/jsifier.js3
-rw-r--r--src/postamble.js3
-rw-r--r--src/preamble.js4
3 files changed, 9 insertions, 1 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 2a9c5ba8..6ef9781c 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1529,7 +1529,10 @@ function JSify(data, functionsOnly, givenFunctions) {
}
}
+ // Run postsets right before main, and after the memory initializer has been set up
+ print('__ATMAIN__.push(function() {\n');
print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n'));
+ print('});\n');
return;
}
diff --git a/src/postamble.js b/src/postamble.js
index 4b3e831d..ea520eae 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -78,10 +78,11 @@ function run(args) {
function doRun() {
ensureInitRuntime();
+ preMain();
+
var ret = 0;
calledRun = true;
if (Module['_main']) {
- preMain();
ret = Module.callMain(args);
if (!Module['noExitRuntime']) {
exitRuntime();
diff --git a/src/preamble.js b/src/preamble.js
index 56f01751..6961a0e9 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -701,6 +701,10 @@ var nullString = allocate(intArrayFromString('(null)'), 'i8', ALLOC_STACK);
function callRuntimeCallbacks(callbacks) {
while(callbacks.length > 0) {
var callback = callbacks.shift();
+ if (typeof callback == 'function') {
+ callback();
+ continue;
+ }
var func = callback.func;
if (typeof func === 'number') {
if (callback.arg === undefined) {