aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jsifier.js9
-rw-r--r--src/preamble.js5
2 files changed, 9 insertions, 5 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index eab4a88d..23fbb4c5 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1529,11 +1529,10 @@ function JSify(data, functionsOnly, givenFunctions) {
}
// Run postsets right before main, and after the memory initializer has been set up
- if (itemsDict.GlobalVariablePostSet.length > 0) {
- print('__ATMAIN__.push(function() {\n');
- print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n'));
- print('});\n');
- }
+ print('function runPostSets() {\n');
+ print(itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n'));
+ print('}\n');
+ print('if (!awaitingMemoryInitializer) runPostSets();\n'); // if we load the memory initializer, this is done later
}
return;
diff --git a/src/preamble.js b/src/preamble.js
index 6961a0e9..592363f9 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -891,6 +891,8 @@ __ATEXIT__.push({ func: function() { PGOMonitor.dump() } });
addPreRun(function() { addRunDependency('pgo') });
#endif
+var awaitingMemoryInitializer = false;
+
function loadMemoryInitializer(filename) {
function applyData(data) {
#if USE_TYPED_ARRAYS == 2
@@ -898,6 +900,7 @@ function loadMemoryInitializer(filename) {
#else
allocate(data, 'i8', ALLOC_NONE, TOTAL_STACK);
#endif
+ runPostSets();
}
// always do this asynchronously, to keep shell and web as similar as possible
@@ -912,6 +915,8 @@ function loadMemoryInitializer(filename) {
});
}
});
+
+ awaitingMemoryInitializer = false;
}
// === Body ===