Skip to content

Commit 5f7aa28

Browse files
committed
Make getExceptionMessage work with ASSERTIONS
`getExceptionMessage` didn't work with `-sASSERTIONS`, which is the default mode for `-O0`, because `getExceptionMessage` assumes the input `ptr` is a pointer, whereas when `ASSERTIONS` is set, it is an instance of `CppException`. `in/decrementExceptionRefcount` have the same problem. Now these methods check whether the pointer is a value or an instance of `CppException`. Fixes emscripten-core#17115 (comment).
1 parent 57ca8ad commit 5f7aa28

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/lib/libexceptions.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,34 @@ var LibraryExceptions = {
346346

347347
#elif !DISABLE_EXCEPTION_CATCHING
348348
$incrementExceptionRefcount__deps: ['__cxa_increment_exception_refcount'],
349-
$incrementExceptionRefcount: (ptr) => ___cxa_increment_exception_refcount(ptr),
349+
$incrementExceptionRefcount: (ptr) => {
350+
#if EXCEPTION_STACK_TRACES
351+
if (ptr instanceof CppException) {
352+
ptr = ptr.excPtr;
353+
}
354+
#endif
355+
___cxa_increment_exception_refcount(ptr);
356+
},
350357

351358
$decrementExceptionRefcount__deps: ['__cxa_decrement_exception_refcount'],
352-
$decrementExceptionRefcount: (ptr) => ___cxa_decrement_exception_refcount(ptr),
359+
$decrementExceptionRefcount: (ptr) => {
360+
#if EXCEPTION_STACK_TRACES
361+
if (ptr instanceof CppException) {
362+
ptr = ptr.excPtr;
363+
}
364+
#endif
365+
___cxa_decrement_exception_refcount(ptr);
366+
},
353367

354368
$getExceptionMessage__deps: ['$getExceptionMessageCommon'],
355-
$getExceptionMessage: (ptr) => getExceptionMessageCommon(ptr),
369+
$getExceptionMessage: (ptr) => {
370+
#if EXCEPTION_STACK_TRACES
371+
if (ptr instanceof CppException) {
372+
ptr = ptr.excPtr;
373+
}
374+
#endif
375+
return getExceptionMessageCommon(ptr);
376+
},
356377

357378
#endif
358379
};

test/test_core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,6 @@ def test_exceptions_rethrow_missing(self):
15071507

15081508
@with_all_eh_sjlj
15091509
def test_EXPORT_EXCEPTION_HANDLING_HELPERS(self):
1510-
self.set_setting('ASSERTIONS', 0)
15111510
self.set_setting('EXPORT_EXCEPTION_HANDLING_HELPERS')
15121511
# FIXME Temporary workaround. See 'FIXME' in the test source code below for
15131512
# details.
@@ -1568,7 +1567,9 @@ class myexception : public exception {
15681567
char const*,
15691568
'''
15701569

1571-
self.do_runf('main.cpp', expected)
1570+
for assertions in (0, 1):
1571+
self.set_setting('ASSERTIONS', assertions)
1572+
self.do_runf('main.cpp', expected)
15721573

15731574
@with_all_eh_sjlj
15741575
def test_bad_typeid(self):

0 commit comments

Comments
 (0)