aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
authorDavid Claughton <dave@eclecticdave.com>2011-11-08 21:13:59 +0000
committerDavid Claughton <dave@eclecticdave.com>2011-12-03 01:29:44 +0000
commitca12d620e84fc5284976fb3ecfb8ef30ee7cfe4a (patch)
treeaec53cc648157cf6eab5469a472ba872c735da9e /src/library.js
parent62000632bb844fd0b6473ad0387ce3b82bc62909 (diff)
Modify exit() to throw an object and catch it.
* Changed exit from throwing an text string to throwing an Error-derived object encapsulating the exit status. Then catch it in 'callMain' and return the status. Enable this functionality by setting CATCH_EXIT_CODE in settings.js
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index 113c955c..1f63e6d0 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1752,9 +1752,25 @@ LibraryManager.library = {
_exit: function(status) {
// void _exit(int status);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/exit.html
+
+#if CATCH_EXIT_CODE
+ function ExitStatus() {
+ this.name = "ExitStatus";
+ this.message = "Program terminated with exit(" + status + ")";
+ this.status = status;
+ };
+ ExitStatus.prototype = new Error();
+ ExitStatus.prototype.constructor = ExitStatus;
+#endif
+
__shutdownRuntime__();
ABORT = true;
+
+#if CATCH_EXIT_CODE
+ throw new ExitStatus();
+#else
throw 'exit(' + status + ') called, at ' + new Error().stack;
+#endif
},
fork__deps: ['__setErrNo', '$ERRNO_CODES'],
fork: function() {