66
77var 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 } ,
0 commit comments