66
77var LibraryExceptions = {
88#if ! WASM_EXCEPTIONS
9- $uncaughtExceptionCount: '0' ,
10- #if ! DISABLE_EXCEPTION_CATCHING
11- $exceptionLast: null ,
12- #endif
139 $exceptionCaught: ' []' ,
1410
1511 // This class is the exception metadata which is prepended to each thrown object (in WASM memory).
@@ -84,7 +80,7 @@ var LibraryExceptions = {
8480
8581 // Here, we throw an exception after recording a couple of values that we need to remember
8682 // We also remember that it was the last exception thrown as we need to know that later.
87- __cxa_throw__deps: [ '$ExceptionInfo' , '$uncaughtExceptionCount' ,
83+ __cxa_throw__deps: [ '$ExceptionInfo' ,
8884#if ! DISABLE_EXCEPTION_CATCHING
8985 '$exceptionLast' ,
9086 '__cxa_increment_exception_refcount' ,
@@ -99,6 +95,7 @@ var LibraryExceptions = {
9995 // 'throw' is used here.
10096 '$decrementExceptionRefcount' , '$incrementExceptionRefcount' ,
10197#endif
98+ '_Unwind_RaiseException' ,
10299 ] ,
103100 __cxa_throw : ( ptr , type , destructor ) = > {
104101#if EXCEPTION_DEBUG
@@ -109,20 +106,20 @@ var LibraryExceptions = {
109106 info . init ( type , destructor ) ;
110107#if ! DISABLE_EXCEPTION_CATCHING
111108 ___cxa_increment_exception_refcount ( ptr ) ;
112- exceptionLast = new CppException ( ptr ) ;
109+ ptr = new CppException ( ptr ) ;
113110#endif
114- uncaughtExceptionCount ++ ;
115- { { { makeThrow ( ) } } }
111+ __Unwind_RaiseException ( ptr ) ;
116112 } ,
117113
118114 // This exception will be caught twice, but while begin_catch runs twice,
119115 // we early-exit from end_catch when the exception has been rethrown, so
120116 // pop that here from the caught exceptions.
121- __cxa_rethrow__deps: [ '$exceptionCaught' , '$uncaughtExceptionCount' ,
117+ __cxa_rethrow__deps: [ '$exceptionCaught' ,
122118#if ! DISABLE_EXCEPTION_CATCHING
123119 '$exceptionLast' ,
124120 '__cxa_increment_exception_refcount' ,
125121#endif
122+ '_Unwind_RaiseException' ,
126123 ] ,
127124 __cxa_rethrow : ( ) = > {
128125 if ( ! exceptionCaught . length ) {
@@ -132,16 +129,15 @@ var LibraryExceptions = {
132129 var ptr = info . excPtr ;
133130 info . set_rethrown ( true ) ;
134131 info . set_caught ( false ) ;
135- uncaughtExceptionCount ++ ;
136132#if ! DISABLE_EXCEPTION_CATCHING
137133 ___cxa_increment_exception_refcount ( ptr ) ;
138134#if EXCEPTION_DEBUG
139135 dbg ( '__cxa_rethrow: ' +
140136 [ ptrToString ( ptr ) , exceptionLast , 'stack' , exceptionCaught ] ) ;
141137#endif
142- exceptionLast = new CppException ( ptr ) ;
138+ ptr = new CppException ( ptr ) ;
143139#endif
144- { { { makeThrow ( ) } } }
140+ __Unwind_RaiseException ( ptr ) ;
145141 } ,
146142
147143 llvm_eh_typeid_for: ( type ) => type ,
@@ -212,11 +208,12 @@ var LibraryExceptions = {
212208 return info . get_type ( ) ;
213209 } ,
214210
215- __cxa_rethrow_primary_exception__deps : [ '$ExceptionInfo' , '$uncaughtExceptionCount' ,
211+ __cxa_rethrow_primary_exception__deps : [ '$ExceptionInfo' ,
216212#if ! DISABLE_EXCEPTION_CATCHING
217213 '$exceptionLast' ,
218214 '__cxa_increment_exception_refcount' ,
219215#endif
216+ '_Unwind_RaiseException' ,
220217 ] ,
221218 __cxa_rethrow_primary_exception : ( ptr ) = > {
222219 if ( ! ptr ) return ;
@@ -226,12 +223,11 @@ var LibraryExceptions = {
226223 var info = new ExceptionInfo ( ptr ) ;
227224 info . set_rethrown ( true ) ;
228225 info . set_caught ( false ) ;
229- uncaughtExceptionCount ++ ;
230226#if ! DISABLE_EXCEPTION_CATCHING
231227 ___cxa_increment_exception_refcount ( ptr ) ;
232- exceptionLast = new CppException ( ptr ) ;
228+ ptr = new CppException ( ptr ) ;
233229#endif
234- { { { makeThrow ( 'exceptionLast' ) } } }
230+ __Unwind_RaiseException ( ptr ) ;
235231 } ,
236232
237233 // Finds a suitable catch clause for when an exception is thrown.
@@ -293,19 +289,20 @@ var LibraryExceptions = {
293289#endif
294290 } ,
295291
292+ __resumeException__deps : [
296293#if ! DISABLE_EXCEPTION_CATCHING
297- __resumeException__deps : [ '$exceptionLast' ] ,
294+ '$exceptionLast' ,
298295#endif
296+ '_Unwind_Resume' ,
297+ ] ,
299298 __resumeException : ( ptr ) = > {
300299#if ! DISABLE_EXCEPTION_CATCHING
301300#if EXCEPTION_DEBUG
302301 dbg ( "__resumeException " + [ ptrToString ( ptr ) , exceptionLast ] ) ;
303302#endif
304- if ( ! exceptionLast ) {
305- exceptionLast = new CppException ( ptr ) ;
306- }
303+ ptr = exceptionLast ?? new CppException ( ptr ) ;
307304#endif
308- { { { makeThrow ( ) } } }
305+ __Unwind_Resume ( ptr ) ;
309306 } ,
310307
311308#endif
0 commit comments