diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-12 11:59:50 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-12 11:59:50 -0800 |
commit | e02762158e8f105fae65583fe9cfe331494b11c7 (patch) | |
tree | 21c776705d2557ddbd4762ef133201f682c7458b | |
parent | 76b5adaf554a0d636ba5eeb9bd1d25659f45167f (diff) | |
parent | ddd3820c79562079e58c7717c5f88c81aac6a379 (diff) |
Merge pull request #170 from FishingCactus/class_exception
Catching specific exception type now works
-rw-r--r-- | src/jsifier.js | 6 | ||||
-rw-r--r-- | src/library.js | 12 | ||||
-rw-r--r-- | system/include/libcxx/exception | 2 | ||||
-rw-r--r-- | tests/runner.py | 49 |
4 files changed, 60 insertions, 9 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 501ed3f9..b14c213f 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -926,7 +926,8 @@ function JSify(data, functionsOnly, givenFunctions) { return ret + ';'; }); makeFuncLineActor('resume', function(item) { - return (EXCEPTION_DEBUG ? 'print("Resuming exception");' : '') + 'throw [0,0];'; + return (EXCEPTION_DEBUG ? 'print("Resuming exception");' : '') + + 'throw ' + makeGetValue('_llvm_eh_exception.buf', '0', 'void*') + ';'; }); makeFuncLineActor('invoke', function(item) { // Wrapping in a function lets us easily return values if we are @@ -945,7 +946,8 @@ function JSify(data, functionsOnly, givenFunctions) { }); makeFuncLineActor('landingpad', function(item) { // Just a stub - return '{ f0: 0, f1: 0 }'; + return '{ f0: ' + makeGetValue('_llvm_eh_exception.buf', '0', 'void*') + + ', f1:' + makeGetValue('_llvm_eh_exception.buf', QUANTUM_SIZE, 'void*') + ' }'; }); makeFuncLineActor('load', function(item) { var value = finalizeLLVMParameter(item.pointer); diff --git a/src/library.js b/src/library.js index a0160279..3ede01af 100644 --- a/src/library.js +++ b/src/library.js @@ -4320,8 +4320,8 @@ LibraryManager.library = { print('Compiled code throwing an exception, ' + [ptr,type,destructor] + ', at ' + new Error().stack); #endif {{{ makeSetValue('_llvm_eh_exception.buf', '0', 'ptr', 'void*') }}} - {{{ makeSetValue('_llvm_eh_exception.buf', '4', 'type', 'void*') }}} - {{{ makeSetValue('_llvm_eh_exception.buf', '8', 'destructor', 'void*') }}} + {{{ makeSetValue('_llvm_eh_exception.buf', QUANTUM_SIZE, 'type', 'void*') }}} + {{{ makeSetValue('_llvm_eh_exception.buf', 2 * QUANTUM_SIZE, 'destructor', 'void*') }}} throw ptr; }, __cxa_rethrow__deps: ['llvm_eh_exception', '__cxa_end_catch'], @@ -4335,7 +4335,7 @@ LibraryManager.library = { }, llvm_eh_selector__jsargs: true, llvm_eh_selector: function(unused_exception_value, personality/*, varargs*/) { - var type = {{{ makeGetValue('_llvm_eh_exception.buf', '4', 'void*') }}} + var type = {{{ makeGetValue('_llvm_eh_exception.buf', QUANTUM_SIZE, 'void*') }}} for (var i = 2; i < arguments.length; i++) { if (arguments[i] == type) return type; } @@ -4359,13 +4359,13 @@ LibraryManager.library = { // Clear state flag. __THREW__ = false; // Clear type. - {{{ makeSetValue('_llvm_eh_exception.buf', '4', '0', 'void*') }}} + {{{ makeSetValue('_llvm_eh_exception.buf', QUANTUM_SIZE, '0', 'void*') }}} // Call destructor if one is registered then clear it. var ptr = {{{ makeGetValue('_llvm_eh_exception.buf', '0', 'void*') }}}; - var destructor = {{{ makeGetValue('_llvm_eh_exception.buf', '8', 'void*') }}}; + var destructor = {{{ makeGetValue('_llvm_eh_exception.buf', 2 * QUANTUM_SIZE, 'void*') }}}; if (destructor) { FUNCTION_TABLE[destructor](ptr); - {{{ makeSetValue('_llvm_eh_exception.buf', '8', '0', 'i32') }}} + {{{ makeSetValue('_llvm_eh_exception.buf', 2 * QUANTUM_SIZE, '0', 'i32') }}} } // Free ptr if it isn't null. if (ptr) { diff --git a/system/include/libcxx/exception b/system/include/libcxx/exception index 5b1db9b6..f05855b4 100644 --- a/system/include/libcxx/exception +++ b/system/include/libcxx/exception @@ -89,7 +89,7 @@ class _LIBCPP_EXCEPTION_ABI exception { public: _LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {} - virtual ~exception() _NOEXCEPT; + virtual ~exception() _NOEXCEPT{} virtual const char* what() const _NOEXCEPT; }; diff --git a/tests/runner.py b/tests/runner.py index dd11b950..a23297f6 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -1189,6 +1189,55 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv): Settings.DISABLE_EXCEPTION_CATCHING = 1 self.do_run(src, 'Compiled code throwing an exception') + + src = ''' + #include <iostream> + + class MyException + { + public: + MyException(){ std::cout << "Construct..."; } + MyException( const MyException & ) { std::cout << "Copy..."; } + ~MyException(){ std::cout << "Destruct..."; } + }; + + int function() + { + std::cout << "Throw..."; + throw MyException(); + } + + int function2() + { + return function(); + } + + int main() + { + try + { + function2(); + } + catch (MyException & e) + { + std::cout << "Catched..."; + } + + try + { + function2(); + } + catch (MyException e) + { + std::cout << "Catched..."; + } + + return 0; + } + ''' + + Settings.DISABLE_EXCEPTION_CATCHING = 0 + self.do_run(src, 'Throw...Construct...Catched...Destruct...Throw...Construct...Copy...Catched...Destruct...Destruct...') def test_typed_exceptions(self): return self.skip('TODO: fix this for llvm 3.0') |