Skip to content

Commit a4ec944

Browse files
committed
Move __cxa_init_primary_exception to native
Given that our JS `__cxa_throw` does not depend on `__cxa_init_primary_exception` anymore, there's no reason this function needs to be in JS. This moves the function to the native library. Also this changes a couple `ifdef __USING_WASM_EXCEPTIONS__`s to `ifdef __wasm__` because Wasm's destructor type pertains to Emscripten EH too.
1 parent 1fbe318 commit a4ec944

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

src/library_exceptions.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ var LibraryExceptions = {
102102
}
103103
},
104104

105-
__cxa_init_primary_exception__deps: ['$ExceptionInfo'],
106-
__cxa_init_primary_exception: (ptr, type, destructor) => {
107-
#if EXCEPTION_DEBUG
108-
dbg('__cxa_init_primary_exception: ' + [ptrToString(ptr), type, ptrToString(destructor)]);
109-
#endif
110-
return ptr;
111-
},
112-
113105
// Here, we throw an exception after recording a couple of values that we need to remember
114106
// We also remember that it was the last exception thrown as we need to know that later.
115107
__cxa_throw__deps: ['$ExceptionInfo', '$exceptionLast', '$uncaughtExceptionCount'],

src/library_sigs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ sigs = {
221221
__cxa_current_primary_exception__sig: 'p',
222222
__cxa_end_catch__sig: 'v',
223223
__cxa_get_exception_ptr__sig: 'pp',
224-
__cxa_init_primary_exception__sig: 'pppp',
225224
__cxa_rethrow__sig: 'v',
226225
__cxa_rethrow_primary_exception__sig: 'vp',
227226
__cxa_throw__sig: 'vppp',

system/lib/libcxx/include/__exception/exception_ptr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
3838
std::type_info*,
3939
# if defined(_WIN32)
4040
void(__thiscall*)(void*)) throw();
41-
# elif defined(__USING_WASM_EXCEPTIONS__)
41+
# elif defined(__wasm__)
4242
// In Wasm, a destructor returns its argument
4343
void* (*)(void*)) throw();
4444
# else
@@ -91,14 +91,14 @@ _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
9191
using _Ep2 = __decay_t<_Ep>;
9292

9393
void* __ex = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ep));
94-
# ifdef __USING_WASM_EXCEPTIONS__
94+
# ifdef __wasm__
9595
// In Wasm, a destructor returns its argument
9696
(void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) -> void* {
9797
# else
9898
(void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) {
9999
# endif
100100
std::__destroy_at(static_cast<_Ep2*>(__p));
101-
# ifdef __USING_WASM_EXCEPTIONS__
101+
# ifdef __wasm__
102102
return __p;
103103
# endif
104104
});

system/lib/libcxxabi/include/cxxabi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern _LIBCXXABI_FUNC_VIS void
4848
__cxa_free_exception(void *thrown_exception) throw();
4949
// This function is an LLVM extension, which mirrors the same extension in libsupc++ and libcxxrt
5050
extern _LIBCXXABI_FUNC_VIS __cxa_exception*
51-
#ifdef __USING_WASM_EXCEPTIONS__
51+
#ifdef __wasm__
5252
// In Wasm, a destructor returns its argument
5353
__cxa_init_primary_exception(void* object, std::type_info* tinfo, void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
5454
#else

system/lib/libcxxabi/src/cxa_exception_emscripten.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
152152
}
153153
}
154154

155+
__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* tinfo,
156+
void *(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {
157+
__cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
158+
exception_header->referenceCount = 0;
159+
exception_header->exceptionType = tinfo;
160+
exception_header->exceptionDestructor = dest;
161+
return exception_header;
162+
}
163+
155164
} // extern "C"
156165

157166
} // abi

0 commit comments

Comments
 (0)