Skip to content

Commit 39c27d1

Browse files
committed
Add __cxa_init_primary_exception to library_exception.js
llvm/llvm-project#65534 added `__cxa_init_primary_exception` function and use it in both in libcxxabi's `__cxa_throw` and also directly in libcxx. Because we create exceptions in JS, we need a counterpart in JS exception library too.
1 parent e4d4bc7 commit 39c27d1

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/library_exceptions.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,28 @@ var LibraryExceptions = {
102102
}
103103
},
104104

105+
// Initialize exception info and return it.
106+
__cxa_init_primary_exception__deps: ['$ExceptionInfo'],
107+
__cxa_init_primary_exception: (ptr, type, destructor) => {
108+
#if EXCEPTION_DEBUG
109+
dbg('__cxa_init_primary_exception: ' + [ptrToString(ptr), type, ptrToString(destructor)]);
110+
#endif
111+
var info = new ExceptionInfo(ptr);
112+
// Initialize ExceptionInfo content after it was allocated in __cxa_allocate_exception.
113+
info.init(type, destructor);
114+
var ret;
115+
{{{ storeException('ret', 'ptr') }}}
116+
return ret;
117+
},
118+
105119
// Here, we throw an exception after recording a couple of values that we need to remember
106120
// We also remember that it was the last exception thrown as we need to know that later.
107-
__cxa_throw__deps: ['$ExceptionInfo', '$exceptionLast', '$uncaughtExceptionCount'],
121+
__cxa_throw__deps: ['$exceptionLast', '$uncaughtExceptionCount', '__cxa_init_primary_exception'],
108122
__cxa_throw: (ptr, type, destructor) => {
109123
#if EXCEPTION_DEBUG
110124
dbg('__cxa_throw: ' + [ptrToString(ptr), type, ptrToString(destructor)]);
111125
#endif
112-
var info = new ExceptionInfo(ptr);
113-
// Initialize ExceptionInfo content after it was allocated in __cxa_allocate_exception.
114-
info.init(type, destructor);
115-
{{{ storeException('exceptionLast', 'ptr') }}}
126+
exceptionLast = ___cxa_init_primary_exception(ptr, type, destructor);
116127
uncaughtExceptionCount++;
117128
{{{ makeThrow('exceptionLast') }}}
118129
},

src/library_sigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ 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',
224225
__cxa_rethrow__sig: 'v',
225226
__cxa_rethrow_primary_exception__sig: 'vp',
226227
__cxa_throw__sig: 'vppp',

0 commit comments

Comments
 (0)