aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-07 12:54:29 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-07 12:54:29 -0800
commit578971453d4d1140486229bedc711f52b8e1948f (patch)
tree72f2371905d7d08a1a86641ccd977649088dcde9 /src
parent904d9b751241bfa1e1a334877c8489a27e535892 (diff)
reset the stack top when CATCH_EXIT_CODE
Diffstat (limited to 'src')
-rw-r--r--src/postamble.js4
-rw-r--r--src/settings.js4
2 files changed, 7 insertions, 1 deletions
diff --git a/src/postamble.js b/src/postamble.js
index 83a4daa6..5f541733 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -18,10 +18,14 @@ Module.callMain = function callMain(args) {
argv = allocate(argv, 'i32', ALLOC_STATIC);
#if CATCH_EXIT_CODE
+ var initialStackTop = STACKTOP;
try {
return Module['_main'](argc, argv, 0);
}
catch(e) { if (e.name == "ExitStatus") return e.status; throw e; }
+ finally {
+ STACKTOP = initialStackTop;
+ }
#else
return Module['_main'](argc, argv, 0);
#endif
diff --git a/src/settings.js b/src/settings.js
index 84d64167..11af4692 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -118,7 +118,9 @@ var INLINING_LIMIT = 50; // A limit on inlining. If 0, we will inline normally i
var CATCH_EXIT_CODE = 0; // If set, causes exit() to throw an exception object which is caught
// in a try..catch block and results in the exit status being
// returned from run(). If zero (the default), the program is just
- // terminated with an error message.
+ // terminated with an error message, that is, the exception thrown
+ // by exit() is not handled in any way (in particular, the stack
+ // position will not be reset).
// Generated code debugging options
var SAFE_HEAP = 0; // Check each write to the heap, for example, this will give a clear