aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-11-20 15:19:01 -0800
committerAlon Zakai <azakai@mozilla.com>2010-11-20 15:19:01 -0800
commitaa7790adb7357136620b4a4f4924b3ab5dccc75d (patch)
tree36d31a878320b62eadd64742368a25e045e005d3
parent77fe34354be3cf141622d7869afafc622924d44a (diff)
minimal C++ exceptions support
-rw-r--r--src/library.js12
-rw-r--r--src/settings.js2
-rw-r--r--tests/runner.py26
3 files changed, 38 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js
index a1a3ac2f..3e337c9d 100644
--- a/src/library.js
+++ b/src/library.js
@@ -166,12 +166,22 @@ var Library = {
return 1;
},
+ // Exceptions - minimal support, only (...) for now (no actual exception objects can be caught)
+ __cxa_allocate_exception: function(size) {
+ return _malloc(size); // warning: leaked
+ },
+ __cxa_throw: function(ptr, data, dunno) {
+ throw ptr;
+ },
llvm_eh_exception: function() {
return 'code-generated exception: ' + (new Error().stack);
},
-
llvm_eh_selector: function(exception, personality, num) {
},
+ __cxa_begin_catch: function(ptr) {
+ },
+ __cxa_end_catch: function(ptr) {
+ },
__cxa_call_unexpected: function(exception) {
ABORT = true;
diff --git a/src/settings.js b/src/settings.js
index 7312488b..8aa9427e 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -30,7 +30,7 @@ USE_TYPED_ARRAYS = 0; // Try to use typed arrays for the heap
// Generated code debugging options
SAFE_HEAP = 0; // Check each write to the heap against a list of blocked addresses
LABEL_DEBUG = 0; // Print out labels and functions as we enter them
-EXCEPTION_DEBUG = 1; // Print out exceptions in emscriptened code
+EXCEPTION_DEBUG = 0; // Print out exceptions in emscriptened code
EXECUTION_TIMEOUT = -1; // Throw an exception after X seconds - useful to debug infinite loops
// Compiler debugging options
diff --git a/tests/runner.py b/tests/runner.py
index bf39bb55..fc9e2f21 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -442,6 +442,32 @@ if 'benchmark' not in sys.argv:
'''
self.do_test(src, 'Assertion failed: 1 == false')
+ def test_exceptions(self):
+ src = '''
+ #include <stdio.h>
+ void thrower() {
+ printf("infunc...");
+ throw(99);
+ printf("FAIL");
+ }
+ int main() {
+ try {
+ printf("*throw...");
+ throw(1);
+ printf("FAIL");
+ } catch(...) {
+ printf("caught!");
+ }
+ try {
+ thrower();
+ } catch(...) {
+ printf("done!*\\n");
+ }
+ return 1;
+ }
+ '''
+ self.do_test(src, '*throw...caught!infunc...done!*')
+
def test_class(self):
src = '''
#include <stdio.h>