From 23d3488895071f1b8f71f45509ee36f40662cedd Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Sun, 1 Sep 2013 11:32:33 -0700 Subject: gracefully handle ExitStatus exception in async main loops --- src/library_browser.js | 10 +++++++++- src/postamble.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/library_browser.js b/src/library_browser.js index 235ccc78..e4966e15 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -724,7 +724,15 @@ mergeInto(LibraryManager.library, { Module['preMainLoop'](); } - Runtime.dynCall('v', func); + try { + Runtime.dynCall('v', func); + } catch (e) { + if (e instanceof ExitStatus) { + return; + } else { + throw e; + } + } if (Module['postMainLoop']) { Module['postMainLoop'](); diff --git a/src/postamble.js b/src/postamble.js index df844121..897bb269 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -126,7 +126,15 @@ function exit(status) { // exit the runtime exitRuntime(); - + + // TODO We should handle this differently based on environment. + // In the browser, the best we can do is throw an exception + // to halt execution, but in node we could process.exit and + // I'd imagine SM shell would have something equivalent. + // This would let us set a proper exit status (which + // would be great for checking test exit statuses). + // https://github.com/kripken/emscripten/issues/1371 + // throw an exception to halt the current execution throw new ExitStatus(status); } -- cgit v1.2.3-18-g5258