Skip to content

Commit 5ef23f2

Browse files
authored
[EH] Move EH status management to exceptions.js (#27528)
#27498 moved EH status management (`uncaughtExceptionCount` and `exceptionLast` from `libexceptions.js` to `libunwind.js`, but because in the native libcxxabi and libunwind, the management is done within libcxxabi, I think it'd be more consistent if we do the same for the JS libraries.
1 parent 801c2fb commit 5ef23f2

12 files changed

Lines changed: 50 additions & 63 deletions

‎src/lib/libexceptions.js‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
var LibraryExceptions = {
88
#if !WASM_EXCEPTIONS
9+
$uncaughtExceptionCount: 0,
10+
#if !DISABLE_EXCEPTION_CATCHING
11+
$exceptionLast: null,
12+
#endif
913
$exceptionCaught: ' []',
1014

1115
// This class is the exception metadata which is prepended to each thrown object (in WASM memory).
@@ -80,7 +84,7 @@ var LibraryExceptions = {
8084

8185
// Here, we throw an exception after recording a couple of values that we need to remember
8286
// We also remember that it was the last exception thrown as we need to know that later.
83-
__cxa_throw__deps: ['$ExceptionInfo',
87+
__cxa_throw__deps: ['$ExceptionInfo', '$uncaughtExceptionCount',
8488
#if !DISABLE_EXCEPTION_CATCHING
8589
'$exceptionLast',
8690
'__cxa_increment_exception_refcount',
@@ -106,15 +110,16 @@ var LibraryExceptions = {
106110
info.init(type, destructor);
107111
#if !DISABLE_EXCEPTION_CATCHING
108112
___cxa_increment_exception_refcount(ptr);
109-
ptr = new CppException(ptr);
113+
ptr = exceptionLast = new CppException(ptr);
110114
#endif
115+
uncaughtExceptionCount++;
111116
__Unwind_RaiseException(ptr);
112117
},
113118

114119
// This exception will be caught twice, but while begin_catch runs twice,
115120
// we early-exit from end_catch when the exception has been rethrown, so
116121
// pop that here from the caught exceptions.
117-
__cxa_rethrow__deps: ['$exceptionCaught',
122+
__cxa_rethrow__deps: ['$exceptionCaught', '$uncaughtExceptionCount',
118123
#if !DISABLE_EXCEPTION_CATCHING
119124
'$exceptionLast',
120125
'__cxa_increment_exception_refcount',
@@ -129,13 +134,14 @@ var LibraryExceptions = {
129134
var ptr = info.excPtr;
130135
info.set_rethrown(true);
131136
info.set_caught(false);
137+
uncaughtExceptionCount++;
132138
#if !DISABLE_EXCEPTION_CATCHING
133139
___cxa_increment_exception_refcount(ptr);
134140
#if EXCEPTION_DEBUG
135141
dbg('__cxa_rethrow: ' +
136142
[ptrToString(ptr), exceptionLast, 'stack', exceptionCaught]);
137143
#endif
138-
ptr = new CppException(ptr);
144+
ptr = exceptionLast = new CppException(ptr);
139145
#endif
140146
__Unwind_RaiseException(ptr);
141147
},
@@ -208,7 +214,7 @@ var LibraryExceptions = {
208214
return info.get_type();
209215
},
210216

211-
__cxa_rethrow_primary_exception__deps: ['$ExceptionInfo',
217+
__cxa_rethrow_primary_exception__deps: ['$ExceptionInfo', '$uncaughtExceptionCount',
212218
#if !DISABLE_EXCEPTION_CATCHING
213219
'$exceptionLast',
214220
'__cxa_increment_exception_refcount',
@@ -223,9 +229,10 @@ var LibraryExceptions = {
223229
var info = new ExceptionInfo(ptr);
224230
info.set_rethrown(true);
225231
info.set_caught(false);
232+
uncaughtExceptionCount++;
226233
#if !DISABLE_EXCEPTION_CATCHING
227234
___cxa_increment_exception_refcount(ptr);
228-
ptr = new CppException(ptr);
235+
ptr = exceptionLast = new CppException(ptr);
229236
#endif
230237
__Unwind_RaiseException(ptr);
231238
},
@@ -300,7 +307,7 @@ var LibraryExceptions = {
300307
#if EXCEPTION_DEBUG
301308
dbg("__resumeException " + [ptrToString(ptr), exceptionLast]);
302309
#endif
303-
ptr = exceptionLast ?? new CppException(ptr);
310+
ptr = exceptionLast ??= new CppException(ptr);
304311
#endif
305312
__Unwind_Resume(ptr);
306313
},

‎src/lib/libunwind.js‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
#endif
1010

1111
var LibraryUnwind = {
12-
$uncaughtExceptionCount: '0',
13-
#if !DISABLE_EXCEPTION_CATCHING
14-
$exceptionLast: null,
15-
#endif
1612

1713
_Unwind_Backtrace__deps: ['$getCallstack'],
1814
_Unwind_Backtrace: (func, arg) => {
@@ -28,26 +24,11 @@ var LibraryUnwind = {
2824

2925
_Unwind_FindEnclosingFunction: (ip) => 0, // we cannot succeed
3026

31-
_Unwind_RaiseException__deps: ['$uncaughtExceptionCount',
32-
#if !DISABLE_EXCEPTION_CATCHING
33-
'$exceptionLast',
34-
#endif
35-
],
3627
_Unwind_RaiseException: (ex) => {
37-
#if !DISABLE_EXCEPTION_CATCHING
38-
exceptionLast = ex;
39-
uncaughtExceptionCount++;
40-
#endif
4128
{{{ makeThrow('ex') }}}
4229
},
4330

44-
#if !DISABLE_EXCEPTION_CATCHING
45-
_Unwind_Resume__deps: ['$exceptionLast'],
46-
#endif
4731
_Unwind_Resume: (ex) => {
48-
#if !DISABLE_EXCEPTION_CATCHING
49-
exceptionLast = ex;
50-
#endif
5132
{{{ makeThrow('ex') }}}
5233
},
5334

‎test/codesize/test_codesize_cxx_ctors1.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19198,
3-
"a.out.js.gz": 8107,
2+
"a.out.js": 19208,
3+
"a.out.js.gz": 8121,
44
"a.out.nodebug.wasm": 134739,
55
"a.out.nodebug.wasm.gz": 51534,
6-
"total": 153937,
7-
"total_gz": 59641,
6+
"total": 153947,
7+
"total_gz": 59655,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

‎test/codesize/test_codesize_cxx_ctors2.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19175,
3-
"a.out.js.gz": 8091,
2+
"a.out.js": 19185,
3+
"a.out.js.gz": 8104,
44
"a.out.nodebug.wasm": 134168,
55
"a.out.nodebug.wasm.gz": 51198,
6-
"total": 153343,
7-
"total_gz": 59289,
6+
"total": 153353,
7+
"total_gz": 59302,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

‎test/codesize/test_codesize_cxx_except.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 22904,
3-
"a.out.js.gz": 9078,
2+
"a.out.js": 22901,
3+
"a.out.js.gz": 9079,
44
"a.out.nodebug.wasm": 177205,
55
"a.out.nodebug.wasm.gz": 59111,
6-
"total": 200109,
7-
"total_gz": 68189,
6+
"total": 200106,
7+
"total_gz": 68190,
88
"sent": [
99
"__cxa_begin_catch",
1010
"__cxa_end_catch",

‎test/codesize/test_codesize_cxx_mangle.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"a.out.js": 22954,
2+
"a.out.js": 22951,
33
"a.out.js.gz": 9099,
44
"a.out.nodebug.wasm": 243485,
55
"a.out.nodebug.wasm.gz": 81306,
6-
"total": 266439,
6+
"total": 266436,
77
"total_gz": 90405,
88
"sent": [
99
"__cxa_begin_catch",

‎test/codesize/test_codesize_cxx_noexcept.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19198,
3-
"a.out.js.gz": 8107,
2+
"a.out.js": 19208,
3+
"a.out.js.gz": 8121,
44
"a.out.nodebug.wasm": 136649,
55
"a.out.nodebug.wasm.gz": 52153,
6-
"total": 155847,
7-
"total_gz": 60260,
6+
"total": 155857,
7+
"total_gz": 60274,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

‎test/codesize/test_codesize_cxx_wasmfs.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 6594,
3-
"a.out.js.gz": 3145,
2+
"a.out.js": 6604,
3+
"a.out.js.gz": 3154,
44
"a.out.nodebug.wasm": 174371,
55
"a.out.nodebug.wasm.gz": 64908,
6-
"total": 180965,
7-
"total_gz": 68053,
6+
"total": 180975,
7+
"total_gz": 68062,
88
"sent": [
99
"__cxa_throw",
1010
"_abort_js",

‎test/codesize/test_codesize_hello_O0.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 23494,
3-
"a.out.js.gz": 8565,
2+
"a.out.js": 23471,
3+
"a.out.js.gz": 8555,
44
"a.out.nodebug.wasm": 15115,
55
"a.out.nodebug.wasm.gz": 7464,
6-
"total": 38609,
7-
"total_gz": 16029,
6+
"total": 38586,
7+
"total_gz": 16019,
88
"sent": [
99
"fd_write"
1010
],

‎test/codesize/test_codesize_minimal_O0.expected.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
10301030
'emClearImmediate_deps',
10311031
'emClearImmediate',
10321032
'promiseMap',
1033-
'uncaughtExceptionCount',
10341033
'Browser',
10351034
'requestFullscreen',
10361035
'setCanvasSize',

0 commit comments

Comments
 (0)