diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-02-09 10:58:41 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-02-09 10:58:41 -0800 |
commit | d23d2cc53e9b3a011b5789094f8cf5e84fd3fbc4 (patch) | |
tree | efe2aa1064273a697beac4f89026c34c0ec253f3 | |
parent | 18d7818121e8501ccd01962acd36aa9f45843b52 (diff) | |
parent | 6d8bc1b3a1bd1756c4a2fdc5a08b892607c76cc6 (diff) |
Merge pull request #238 from ehsan/uncaught_exception
Implement std::uncaught_exception()
-rw-r--r-- | src/library.js | 12 | ||||
-rw-r--r-- | system/lib/libcxx/symbols | 1 | ||||
-rwxr-xr-x | tests/runner.py | 26 |
3 files changed, 37 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js index 6385507c..86c499a7 100644 --- a/src/library.js +++ b/src/library.js @@ -4392,7 +4392,7 @@ LibraryManager.library = { __cxa_free_exception: function(ptr) { return _free(ptr); }, - __cxa_throw__deps: ['llvm_eh_exception'], + __cxa_throw__deps: ['llvm_eh_exception', '_ZSt18uncaught_exceptionv'], __cxa_throw: function(ptr, type, destructor) { #if EXCEPTION_DEBUG print('Compiled code throwing an exception, ' + [ptr,type,destructor] + ', at ' + new Error().stack); @@ -4400,6 +4400,11 @@ LibraryManager.library = { {{{ makeSetValue('_llvm_eh_exception.buf', '0', 'ptr', 'void*') }}} {{{ makeSetValue('_llvm_eh_exception.buf', QUANTUM_SIZE, 'type', 'void*') }}} {{{ makeSetValue('_llvm_eh_exception.buf', 2 * QUANTUM_SIZE, 'destructor', 'void*') }}} + if (!("uncaught_exception" in __ZSt18uncaught_exceptionv)) { + __ZSt18uncaught_exceptionv.uncaught_exception = 1; + } else { + __ZSt18uncaught_exceptionv.uncaught_exception++; + } throw ptr; }, __cxa_rethrow__deps: ['llvm_eh_exception', '__cxa_end_catch'], @@ -4425,7 +4430,9 @@ LibraryManager.library = { _Unwind_Resume_or_Rethrow: function(ptr) { throw ptr; }, + __cxa_begin_catch__deps: ['_ZSt18uncaught_exceptionv'], __cxa_begin_catch: function(ptr) { + __ZSt18uncaught_exceptionv.uncaught_exception--; return ptr; }, __cxa_end_catch__deps: ['llvm_eh_exception', '__cxa_free_exception'], @@ -4455,6 +4462,9 @@ LibraryManager.library = { __cxa_get_exception_ptr: function(ptr) { return ptr; }, + _ZSt18uncaught_exceptionv: function() { // std::uncaught_exception() + return !!__ZSt18uncaught_exceptionv.uncaught_exception; + }, __cxa_call_unexpected: function(exception) { ABORT = true; diff --git a/system/lib/libcxx/symbols b/system/lib/libcxx/symbols index 0cea51cb..23d4a7a4 100644 --- a/system/lib/libcxx/symbols +++ b/system/lib/libcxx/symbols @@ -2577,7 +2577,6 @@ T _ZSt17current_exceptionv T _ZSt17rethrow_exceptionSt13exception_ptr C _ZSt18make_exception_ptrINSt3__112future_errorEESt13exception_ptrT_ - T _ZSt18uncaught_exceptionv D _ZSt7nothrow D _ZTCNSt3__110istrstreamE0_NS_13basic_istreamIcNS_11char_traitsIcEEEE D _ZTCNSt3__110ostrstreamE0_NS_13basic_ostreamIcNS_11char_traitsIcEEEE diff --git a/tests/runner.py b/tests/runner.py index 069598d1..b8927332 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1402,6 +1402,32 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): Settings.DISABLE_EXCEPTION_CATCHING = 0 self.do_run(src, 'Throw...Construct...Catched...Destruct...Throw...Construct...Copy...Catched...Destruct...Destruct...') + def test_uncaught_exception(self): + Settings.EXCEPTION_DEBUG = 0 # Messes up expected output. + Settings.DISABLE_EXCEPTION_CATCHING = 0 + + src = r''' + #include <stdio.h> + #include <exception> + struct X { + ~X() { + printf("exception? %s\n", std::uncaught_exception() ? "yes" : "no"); + } + }; + int main() { + printf("exception? %s\n", std::uncaught_exception() ? "yes" : "no"); + try { + X x; + throw 1; + } catch(...) { + printf("exception? %s\n", std::uncaught_exception() ? "yes" : "no"); + } + printf("exception? %s\n", std::uncaught_exception() ? "yes" : "no"); + return 0; + } + ''' + self.do_run(src, 'exception? no\nexception? yes\nexception? no\nexception? no\n') + def test_typed_exceptions(self): return self.skip('TODO: fix this for llvm 3.0') |