@@ -23,11 +23,9 @@ var LibraryExceptions = {
23
23
//
24
24
// excPtr - Thrown object pointer to wrap. Metadata pointer is calculated from it.
25
25
$ExceptionInfo__docs : '/** @constructor */' ,
26
- $ExceptionInfo__deps : [ '__cxa_is_pointer_type' ,
27
26
#if EXCEPTION_DEBUG
28
- '$ptrToString' ,
27
+ $ExceptionInfo__deps: [ '$ptrToString' ] ,
29
28
#endif
30
- ] ,
31
29
$ExceptionInfo : function ( excPtr ) {
32
30
this . excPtr = excPtr ;
33
31
this . ptr = excPtr - { { { C_STRUCTS . __cxa_exception . __size__ } } } ;
@@ -48,10 +46,6 @@ var LibraryExceptions = {
48
46
return { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . exceptionDestructor , '*' ) } } } ;
49
47
} ;
50
48
51
- this . set_refcount = function ( refcount ) {
52
- { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'refcount' , 'i32' ) } } } ;
53
- } ;
54
-
55
49
this . set_caught = function ( caught ) {
56
50
caught = caught ? 1 : 0 ;
57
51
{ { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . caught , 'caught' , 'i8' ) } } } ;
@@ -78,34 +72,8 @@ var LibraryExceptions = {
78
72
this . set_adjusted_ptr ( 0 ) ;
79
73
this . set_type ( type ) ;
80
74
this . set_destructor ( destructor ) ;
81
- this . set_refcount ( 0 ) ;
82
- this . set_caught ( false ) ;
83
- this . set_rethrown ( false ) ;
84
75
}
85
76
86
- this . add_ref = function ( ) {
87
- #if SHARED_MEMORY
88
- Atomics . add ( HEAP32 , ( this . ptr + { { { C_STRUCTS . __cxa_exception . referenceCount } } } ) >> 2 , 1 ) ;
89
- #else
90
- var value = { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'i32' ) } } } ;
91
- { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'value + 1' , 'i32' ) } } } ;
92
- #endif
93
- } ;
94
-
95
- // Returns true if last reference released.
96
- this . release_ref = function ( ) {
97
- #if SHARED_MEMORY
98
- var prev = Atomics . sub ( HEAP32 , ( this . ptr + { { { C_STRUCTS . __cxa_exception . referenceCount } } } ) >> 2 , 1 ) ;
99
- #else
100
- var prev = { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'i32' ) } } } ;
101
- { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'prev - 1' , 'i32' ) } } } ;
102
- #endif
103
- #if ASSERTIONS
104
- assert ( prev > 0 ) ;
105
- #endif
106
- return prev === 1 ;
107
- } ;
108
-
109
77
this . set_adjusted_ptr = function ( adjustedPtr ) {
110
78
{ { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . adjustedPtr , 'adjustedPtr' , '*' ) } } } ;
111
79
} ;
@@ -131,52 +99,6 @@ var LibraryExceptions = {
131
99
} ;
132
100
} ,
133
101
134
- $exception_addRef: function ( info ) {
135
- #if EXCEPTION_DEBUG
136
- dbg ( 'exception_addRef ' + ptrToString ( info . excPtr ) ) ;
137
- #endif
138
- info . add_ref ( ) ;
139
- } ,
140
-
141
- $exception_decRef__deps : [ '__cxa_free_exception'
142
- #if EXCEPTION_DEBUG
143
- , '$exceptionLast' , '$exceptionCaught'
144
- #endif
145
- ] ,
146
- $exception_decRef : function ( info ) {
147
- #if EXCEPTION_DEBUG
148
- dbg ( 'exception_decRef ' + ptrToString ( info . excPtr ) ) ;
149
- #endif
150
- // A rethrown exception can reach refcount 0; it must not be discarded
151
- // Its next handler will clear the rethrown flag and addRef it, prior to
152
- // final decRef and destruction here
153
- if ( info . release_ref ( ) && ! info . get_rethrown ( ) ) {
154
- var destructor = info . get_destructor ( ) ;
155
- if ( destructor ) {
156
- // In Wasm, destructors return 'this' as in ARM
157
- { { { makeDynCall ( 'pp' , 'destructor' ) } } } ( info . excPtr ) ;
158
- }
159
- ___cxa_free_exception ( info . excPtr ) ;
160
- #if EXCEPTION_DEBUG
161
- dbg ( 'decref freeing exception ' + [ ptrToString ( info . excPtr ) , exceptionLast , 'stack' , exceptionCaught ] ) ;
162
- #endif
163
- }
164
- } ,
165
-
166
- __cxa_increment_exception_refcount__deps : [ '$exception_addRef' , '$ExceptionInfo' ] ,
167
- __cxa_increment_exception_refcount__sig : 'vp' ,
168
- __cxa_increment_exception_refcount : function ( ptr ) {
169
- if ( ! ptr ) return ;
170
- exception_addRef ( new ExceptionInfo ( ptr ) ) ;
171
- } ,
172
-
173
- __cxa_decrement_exception_refcount__deps : [ '$exception_decRef' , '$ExceptionInfo' ] ,
174
- __cxa_decrement_exception_refcount__sig : 'vp' ,
175
- __cxa_decrement_exception_refcount : function ( ptr ) {
176
- if ( ! ptr ) return ;
177
- exception_decRef ( new ExceptionInfo ( ptr ) ) ;
178
- } ,
179
-
180
102
// Here, we throw an exception after recording a couple of values that we need to remember
181
103
// We also remember that it was the last exception thrown as we need to know that later.
182
104
__cxa_throw__sig: 'vppp' ,
@@ -224,7 +146,8 @@ var LibraryExceptions = {
224
146
return type ;
225
147
} ,
226
148
227
- __cxa_begin_catch__deps : [ '$exceptionCaught' , '$exception_addRef' , '$uncaughtExceptionCount' ] ,
149
+ __cxa_begin_catch__deps : [ '$exceptionCaught' , '__cxa_increment_exception_refcount' ,
150
+ '$uncaughtExceptionCount' ] ,
228
151
__cxa_begin_catch__sig : 'pp' ,
229
152
__cxa_begin_catch : function ( ptr ) {
230
153
var info = new ExceptionInfo ( ptr ) ;
@@ -237,15 +160,15 @@ var LibraryExceptions = {
237
160
#if EXCEPTION_DEBUG
238
161
dbg ( '__cxa_begin_catch ' + [ ptrToString ( ptr ) , 'stack' , exceptionCaught ] ) ;
239
162
#endif
240
- exception_addRef ( info ) ;
163
+ ___cxa_increment_exception_refcount ( info . excPtr ) ;
241
164
return info . get_exception_ptr ( ) ;
242
165
} ,
243
166
244
167
// We're done with a catch. Now, we can run the destructor if there is one
245
168
// and free the exception. Note that if the dynCall on the destructor fails
246
169
// due to calling apply on undefined, that means that the destructor is
247
170
// an invalid index into the FUNCTION_TABLE, so something has gone wrong.
248
- __cxa_end_catch__deps : [ '$exceptionCaught' , '$exceptionLast' , '$exception_decRef ' ] ,
171
+ __cxa_end_catch__deps : [ '$exceptionCaught' , '$exceptionLast' , '__cxa_decrement_exception_refcount' , 'setThrew '] ,
249
172
__cxa_end_catch__sig : 'v' ,
250
173
__cxa_end_catch : function ( ) {
251
174
// Clear state flag.
@@ -259,17 +182,18 @@ var LibraryExceptions = {
259
182
#if EXCEPTION_DEBUG
260
183
dbg ( '__cxa_end_catch popped ' + [ info , exceptionLast , 'stack' , exceptionCaught ] ) ;
261
184
#endif
262
- exception_decRef ( info ) ;
185
+ ___cxa_decrement_exception_refcount ( info . excPtr ) ;
263
186
exceptionLast = 0 ; // XXX in decRef?
264
187
} ,
265
188
266
189
__cxa_get_exception_ptr__deps : [ '$ExceptionInfo' ] ,
267
190
__cxa_get_exception_ptr__sig : 'pp' ,
268
191
__cxa_get_exception_ptr : function ( ptr ) {
192
+ var rtn = new ExceptionInfo ( ptr ) . get_exception_ptr ( ) ;
269
193
#if EXCEPTION_DEBUG
270
- dbg ( '__cxa_get_exception_ptr ' + ptrToString ( ptr ) ) ;
194
+ err ( '__cxa_get_exception_ptr ' + ptrToString ( ptr ) + ' -> ' + ptrToString ( rtn ) ) ;
271
195
#endif
272
- return new ExceptionInfo ( ptr ) . get_exception_ptr ( ) ;
196
+ return rtn ;
273
197
} ,
274
198
275
199
__cxa_uncaught_exceptions__deps : [ '$uncaughtExceptionCount' ] ,
@@ -285,13 +209,13 @@ var LibraryExceptions = {
285
209
throw exception ;
286
210
} ,
287
211
288
- __cxa_current_primary_exception__deps : [ '$exceptionCaught' , '$exception_addRef ' ] ,
212
+ __cxa_current_primary_exception__deps : [ '$exceptionCaught' , '__cxa_increment_exception_refcount ' ] ,
289
213
__cxa_current_primary_exception : function ( ) {
290
214
if ( ! exceptionCaught . length ) {
291
215
return 0 ;
292
216
}
293
217
var info = exceptionCaught [ exceptionCaught . length - 1 ] ;
294
- exception_addRef ( info ) ;
218
+ ___cxa_increment_exception_refcount ( info . excPtr ) ;
295
219
return info . excPtr ;
296
220
} ,
297
221
0 commit comments