aboutsummaryrefslogtreecommitdiff
path: root/src/preamble.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/preamble.js')
-rw-r--r--src/preamble.js73
1 files changed, 56 insertions, 17 deletions
diff --git a/src/preamble.js b/src/preamble.js
index 218e0388..2955c885 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -242,12 +242,6 @@ var tempI64, tempI64b;
var tempRet0, tempRet1, tempRet2, tempRet3, tempRet4, tempRet5, tempRet6, tempRet7, tempRet8, tempRet9;
#endif
-function abort(text) {
- Module.print(text + ':\n' + (new Error).stack);
- ABORT = true;
- throw "Assertion: " + text;
-}
-
function assert(condition, text) {
if (!condition) {
abort('Assertion failed: ' + text);
@@ -711,24 +705,75 @@ 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
+var __ATPRERUN__ = []; // functions called before the runtime is initialized
+var __ATINIT__ = []; // functions called during startup
+var __ATMAIN__ = []; // functions called when main() is to be run
+var __ATEXIT__ = []; // functions called during shutdown
+var __ATPOSTRUN__ = []; // functions called after the runtime has exited
var runtimeInitialized = false;
+function preRun() {
+ // compatibility - merge in anything from Module['preRun'] at this time
+ if (Module['preRun']) {
+ if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
+ while (Module['preRun'].length) {
+ addOnPreRun(Module['preRun'].shift());
+ }
+ }
+ callRuntimeCallbacks(__ATPRERUN__);
+}
+
function ensureInitRuntime() {
if (runtimeInitialized) return;
runtimeInitialized = true;
callRuntimeCallbacks(__ATINIT__);
}
+
function preMain() {
callRuntimeCallbacks(__ATMAIN__);
}
+
function exitRuntime() {
callRuntimeCallbacks(__ATEXIT__);
}
+function postRun() {
+ // compatibility - merge in anything from Module['postRun'] at this time
+ if (Module['postRun']) {
+ if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
+ while (Module['postRun'].length) {
+ addOnPostRun(Module['postRun'].shift());
+ }
+ }
+ callRuntimeCallbacks(__ATPOSTRUN__);
+}
+
+function addOnPreRun(cb) {
+ __ATPRERUN__.unshift(cb);
+}
+Module['addOnPreRun'] = Module.addOnPreRun = addOnPreRun;
+
+function addOnInit(cb) {
+ __ATINIT__.unshift(cb);
+}
+Module['addOnInit'] = Module.addOnInit = addOnInit;
+
+function addOnPreMain(cb) {
+ __ATMAIN__.unshift(cb);
+}
+Module['addOnPreMain'] = Module.addOnPreMain = addOnPreMain;
+
+function addOnExit(cb) {
+ __ATEXIT__.unshift(cb);
+}
+Module['addOnExit'] = Module.addOnExit = addOnExit;
+
+function addOnPostRun(cb) {
+ __ATPOSTRUN__.unshift(cb);
+}
+Module['addOnPostRun'] = Module.addOnPostRun = addOnPostRun;
+
// Tools
// This processes a JS string into a C-line array of numbers, 0-terminated.
@@ -865,12 +910,6 @@ Module['removeRunDependency'] = removeRunDependency;
Module["preloadedImages"] = {}; // maps url to image data
Module["preloadedAudios"] = {}; // maps url to audio data
-function addPreRun(func) {
- if (!Module['preRun']) Module['preRun'] = [];
- else if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
- Module['preRun'].push(func);
-}
-
#if PGO
var PGOMonitor = {
called: {},
@@ -885,7 +924,7 @@ var PGOMonitor = {
};
Module['PGOMonitor'] = PGOMonitor;
__ATEXIT__.push({ func: function() { PGOMonitor.dump() } });
-addPreRun(function() { addRunDependency('pgo') });
+addOnPreRun(function() { addRunDependency('pgo') });
#endif
function loadMemoryInitializer(filename) {
@@ -898,7 +937,7 @@ function loadMemoryInitializer(filename) {
}
// always do this asynchronously, to keep shell and web as similar as possible
- addPreRun(function() {
+ addOnPreRun(function() {
if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) {
applyData(Module['readBinary'](filename));
} else {