Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib/libemval.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ ${functionBody}
#if !DISABLE_EXCEPTION_CATCHING
var info = new ExceptionInfo(object.excPtr);
info.set_caught(false);
info.set_rethrown(false);
exceptionLast = object;
#endif
incrementUncaughtExceptionCount();
Expand Down
15 changes: 0 additions & 15 deletions src/lib/libexceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ var LibraryExceptions = {
return {{{ makeGetValue('this.ptr', C_STRUCTS.__cxa_exception.caught, 'i8') }}} != 0;
}

set_rethrown(rethrown) {
rethrown = rethrown ? 1 : 0;
{{{ makeSetValue('this.ptr', C_STRUCTS.__cxa_exception.rethrown, 'rethrown', 'i8') }}};
}

get_rethrown() {
return {{{ makeGetValue('this.ptr', C_STRUCTS.__cxa_exception.rethrown, 'i8') }}} != 0;
}

// Initialize native structure fields. Should be called once after allocated.
init(type, destructor) {
#if EXCEPTION_DEBUG
Expand Down Expand Up @@ -116,9 +107,6 @@ var LibraryExceptions = {
__Unwind_RaiseException(ptr);
},

// This exception will be caught twice, but while begin_catch runs twice,
// we early-exit from end_catch when the exception has been rethrown, so
// pop that here from the caught exceptions.
__cxa_rethrow__deps: ['$exceptionCaught', '$uncaughtExceptionCount',
#if !DISABLE_EXCEPTION_CATCHING
'$exceptionLast',
Expand All @@ -132,7 +120,6 @@ var LibraryExceptions = {
}
var info = exceptionCaught.at(-1);
var ptr = info.excPtr;
info.set_rethrown(true);
info.set_caught(false);
uncaughtExceptionCount++;
#if !DISABLE_EXCEPTION_CATCHING
Expand All @@ -156,7 +143,6 @@ var LibraryExceptions = {
info.set_caught(true);
uncaughtExceptionCount--;
}
info.set_rethrown(false);
exceptionCaught.push(info);
#if EXCEPTION_DEBUG
dbg('__cxa_begin_catch ' + [ptrToString(ptr), 'stack', exceptionCaught]);
Expand Down Expand Up @@ -227,7 +213,6 @@ var LibraryExceptions = {
dbg('__cxa_rethrow_primary_exception: ' + ptrToString(ptr));
#endif
var info = new ExceptionInfo(ptr);
info.set_rethrown(true);
info.set_caught(false);
uncaughtExceptionCount++;
#if !DISABLE_EXCEPTION_CATCHING
Expand Down
1 change: 0 additions & 1 deletion src/struct_info_cxx.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"exceptionDestructor",
"exceptionType",
"caught",
"rethrown",
"adjustedPtr"
]
}
Expand Down
3 changes: 1 addition & 2 deletions src/struct_info_generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,7 @@
"adjustedPtr": 16,
"caught": 12,
"exceptionDestructor": 8,
"exceptionType": 4,
"rethrown": 13
"exceptionType": 4
},
"__wasi_fdstat_t": {
"__size__": 24,
Expand Down
3 changes: 1 addition & 2 deletions src/struct_info_generated_wasm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,7 @@
"adjustedPtr": 32,
"caught": 24,
"exceptionDestructor": 16,
"exceptionType": 8,
"rethrown": 25
"exceptionType": 8
},
"__wasi_fdstat_t": {
"__size__": 24,
Expand Down
1 change: 0 additions & 1 deletion system/lib/libcxxabi/src/cxa_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
// In wasm, destructors return 'this' as in ARM
void* (*exceptionDestructor)(void *);
uint8_t caught;
uint8_t rethrown;
void *adjustedPtr;
// Add padding to ensure that the size of __cxa_exception is a multiple of
// the maximum useful alignment for the target machine. This ensures that
Expand Down
12 changes: 5 additions & 7 deletions system/lib/libcxxabi/src/cxa_exception_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
// TODO(sbc): consider merging them
//
// Notable changes:
// __cxa_allocate_exception doesn't add get_cxa_exception_offset
// __cxa_decrement_exception_refcount doesn't call the destructor if rethrown
// Both of these changes are mirrored from the historical JS implementation of
// these functions.
// __cxa_allocate_exception doesn't add get_cxa_exception_offset
// This change is mirrored from the historical JS implementation of
// this function.
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -144,10 +143,9 @@ void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
if (thrown_object != NULL )
{
__cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
DEBUG("DEC: %p refcnt=%zu rethrown=%d", thrown_object,
exception_header->referenceCount, exception_header->rethrown);
DEBUG("DEC: %p refcnt=%zu", thrown_object, exception_header->referenceCount);
assert(exception_header->referenceCount > 0);
if (std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(-1)) == 0 && !exception_header->rethrown)
if (std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(-1)) == 0)
{
DEBUG("DEL: %p (dtor=%p)", thrown_object, exception_header->exceptionDestructor);
if (NULL != exception_header->exceptionDestructor)
Expand Down
12 changes: 6 additions & 6 deletions test/codesize/test_codesize_cxx_except.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22820,
"a.out.js.gz": 9041,
"a.out.nodebug.wasm": 176407,
"a.out.nodebug.wasm.gz": 58760,
"total": 199227,
"total_gz": 67801,
"a.out.js": 22796,
"a.out.js.gz": 9032,
"a.out.nodebug.wasm": 176397,
"a.out.nodebug.wasm.gz": 58755,
"total": 199193,
"total_gz": 67787,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
12 changes: 6 additions & 6 deletions test/codesize/test_codesize_cxx_mangle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 22870,
"a.out.js.gz": 9061,
"a.out.nodebug.wasm": 242680,
"a.out.nodebug.wasm.gz": 80978,
"total": 265550,
"total_gz": 90039,
"a.out.js": 22846,
"a.out.js.gz": 9052,
"a.out.nodebug.wasm": 242670,
"a.out.nodebug.wasm.gz": 80973,
"total": 265516,
"total_gz": 90025,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
26 changes: 26 additions & 0 deletions test/core/test_exceptions_refcount_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <cstdio>
#include <emscripten.h>
#include <exception>

class MyException : public std::exception {
public:
~MyException() { puts("~MyException()"); }
};

EMSCRIPTEN_KEEPALIVE extern "C" void rethrow() {
try {
throw MyException();
} catch (...) {
throw;
}
}

int main() {
EM_ASM({
try {
_rethrow();
} catch (e) {
decrementExceptionRefcount(e);
}
});
}
1 change: 1 addition & 0 deletions test/core/test_exceptions_refcount_2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
~MyException()
5 changes: 5 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,11 @@ def test_exceptions_destroy_virtual(self):
def test_exceptions_refcount(self):
self.do_core_test('test_exceptions_refcount.cpp')

@with_all_eh_sjlj
def test_exceptions_refcount_2(self):
self.set_setting('ASSERTIONS')
self.do_core_test('test_exceptions_refcount_2.cpp')

@with_all_eh_sjlj
def test_exceptions_primary(self):
self.do_core_test('test_exceptions_primary.cpp')
Expand Down
Loading