@@ -22,11 +22,9 @@ var LibraryExceptions = {
22
22
//
23
23
// excPtr - Thrown object pointer to wrap. Metadata pointer is calculated from it.
24
24
$ExceptionInfo__docs : '/** @constructor */' ,
25
- $ExceptionInfo__deps : [ '__cxa_is_pointer_type' ,
26
25
#if EXCEPTION_DEBUG
27
- '$ptrToString' ,
26
+ $ExceptionInfo__deps : [ '$ptrToString' ] ,
28
27
#endif
29
- ] ,
30
28
$ExceptionInfo : function ( excPtr ) {
31
29
this . excPtr = excPtr ;
32
30
this . ptr = excPtr - { { { C_STRUCTS . __cxa_exception . __size__ } } } ;
@@ -47,10 +45,6 @@ var LibraryExceptions = {
47
45
return { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . exceptionDestructor , '*' ) } } } ;
48
46
} ;
49
47
50
- this . set_refcount = function ( refcount ) {
51
- { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'refcount' , 'i32' ) } } } ;
52
- } ;
53
-
54
48
this . set_caught = function ( caught ) {
55
49
caught = caught ? 1 : 0 ;
56
50
{ { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . caught , 'caught' , 'i8' ) } } } ;
@@ -77,34 +71,8 @@ var LibraryExceptions = {
77
71
this . set_adjusted_ptr ( 0 ) ;
78
72
this . set_type ( type ) ;
79
73
this . set_destructor ( destructor ) ;
80
- this . set_refcount ( 0 ) ;
81
- this . set_caught ( false ) ;
82
- this . set_rethrown ( false ) ;
83
74
}
84
75
85
- this . add_ref = function ( ) {
86
- #if SHARED_MEMORY
87
- Atomics . add ( HEAP32 , ( this . ptr + { { { C_STRUCTS . __cxa_exception . referenceCount } } } ) >> 2 , 1 ) ;
88
- #else
89
- var value = { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'i32' ) } } } ;
90
- { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'value + 1' , 'i32' ) } } } ;
91
- #endif
92
- } ;
93
-
94
- // Returns true if last reference released.
95
- this . release_ref = function ( ) {
96
- #if SHARED_MEMORY
97
- var prev = Atomics . sub ( HEAP32 , ( this . ptr + { { { C_STRUCTS . __cxa_exception . referenceCount } } } ) >> 2 , 1 ) ;
98
- #else
99
- var prev = { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'i32' ) } } } ;
100
- { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'prev - 1' , 'i32' ) } } } ;
101
- #endif
102
- #if ASSERTIONS
103
- assert ( prev > 0 ) ;
104
- #endif
105
- return prev === 1 ;
106
- } ;
107
-
108
76
this . set_adjusted_ptr = function ( adjustedPtr ) {
109
77
{ { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . adjustedPtr , 'adjustedPtr' , '*' ) } } } ;
110
78
} ;
@@ -130,73 +98,6 @@ var LibraryExceptions = {
130
98
} ;
131
99
} ,
132
100
133
- $exception_addRef: function ( info ) {
134
- #if EXCEPTION_DEBUG
135
- err ( 'exception_addRef ' + ptrToString ( info . excPtr ) ) ;
136
- #endif
137
- info . add_ref ( ) ;
138
- } ,
139
-
140
- $exception_decRef__deps : [ '__cxa_free_exception'
141
- #if EXCEPTION_DEBUG
142
- , '$exceptionLast' , '$exceptionCaught'
143
- #endif
144
- ] ,
145
- $exception_decRef : function ( info ) {
146
- #if EXCEPTION_DEBUG
147
- err ( 'exception_decRef ' + ptrToString ( info . excPtr ) ) ;
148
- #endif
149
- // A rethrown exception can reach refcount 0; it must not be discarded
150
- // Its next handler will clear the rethrown flag and addRef it, prior to
151
- // final decRef and destruction here
152
- if ( info . release_ref ( ) && ! info . get_rethrown ( ) ) {
153
- var destructor = info . get_destructor ( ) ;
154
- if ( destructor ) {
155
- // In Wasm, destructors return 'this' as in ARM
156
- { { { makeDynCall ( 'ii' , 'destructor' ) } } } ( info . excPtr ) ;
157
- }
158
- ___cxa_free_exception ( info . excPtr ) ;
159
- #if EXCEPTION_DEBUG
160
- err ( 'decref freeing exception ' + [ ptrToString ( info . excPtr ) , exceptionLast , 'stack' , exceptionCaught ] ) ;
161
- #endif
162
- }
163
- } ,
164
-
165
- // Exceptions
166
- __cxa_allocate_exception__sig : 'vi' ,
167
- __cxa_allocate_exception : function ( size ) {
168
- // Thrown object is prepended by exception metadata block
169
- return _malloc ( size + { { { C_STRUCTS . __cxa_exception . __size__ } } } ) + { { { C_STRUCTS . __cxa_exception . __size__ } } } ;
170
- } ,
171
-
172
- __cxa_free_exception__deps: [ '$ExceptionInfo' ] ,
173
- __cxa_free_exception__sig : 'vi' ,
174
- __cxa_free_exception : function ( ptr ) {
175
- #if ABORTING_MALLOC || ASSERTIONS
176
- try {
177
- #endif
178
- return _free ( new ExceptionInfo ( ptr ) . ptr ) ;
179
- #if ABORTING_MALLOC || ASSERTIONS
180
- } catch ( e ) {
181
- #if ASSERTIONS
182
- err ( 'exception during __cxa_free_exception: ' + e ) ;
183
- #endif
184
- }
185
- #endif
186
- } ,
187
-
188
- __cxa_increment_exception_refcount__deps : [ '$exception_addRef' , '$ExceptionInfo' ] ,
189
- __cxa_increment_exception_refcount : function ( ptr ) {
190
- if ( ! ptr ) return ;
191
- exception_addRef ( new ExceptionInfo ( ptr ) ) ;
192
- } ,
193
-
194
- __cxa_decrement_exception_refcount__deps : [ '$exception_decRef' , '$ExceptionInfo' ] ,
195
- __cxa_decrement_exception_refcount : function ( ptr ) {
196
- if ( ! ptr ) return ;
197
- exception_decRef ( new ExceptionInfo ( ptr ) ) ;
198
- } ,
199
-
200
101
// Here, we throw an exception after recording a couple of values that we need to remember
201
102
// We also remember that it was the last exception thrown as we need to know that later.
202
103
__cxa_throw__sig: 'viii' ,
@@ -243,7 +144,8 @@ var LibraryExceptions = {
243
144
return type ;
244
145
} ,
245
146
246
- __cxa_begin_catch__deps : [ '$exceptionCaught' , '$exception_addRef' , '$uncaughtExceptionCount' ] ,
147
+ __cxa_begin_catch__deps : [ '$exceptionCaught' , '__cxa_increment_exception_refcount' ,
148
+ '$uncaughtExceptionCount' ] ,
247
149
__cxa_begin_catch : function ( ptr ) {
248
150
var info = new ExceptionInfo ( ptr ) ;
249
151
if ( ! info . get_caught ( ) ) {
@@ -255,15 +157,15 @@ var LibraryExceptions = {
255
157
#if EXCEPTION_DEBUG
256
158
err ( '__cxa_begin_catch ' + [ ptrToString ( ptr ) , 'stack' , exceptionCaught ] ) ;
257
159
#endif
258
- exception_addRef ( info ) ;
160
+ ___cxa_increment_exception_refcount ( info . excPtr ) ;
259
161
return info . get_exception_ptr ( ) ;
260
162
} ,
261
163
262
164
// We're done with a catch. Now, we can run the destructor if there is one
263
165
// and free the exception. Note that if the dynCall on the destructor fails
264
166
// due to calling apply on undefined, that means that the destructor is
265
167
// an invalid index into the FUNCTION_TABLE, so something has gone wrong.
266
- __cxa_end_catch__deps : [ '$exceptionCaught' , '$exceptionLast' , '$exception_decRef ' ] ,
168
+ __cxa_end_catch__deps : [ '$exceptionCaught' , '$exceptionLast' , '__cxa_decrement_exception_refcount' , 'setThrew '] ,
267
169
__cxa_end_catch__sig : 'v' ,
268
170
__cxa_end_catch : function ( ) {
269
171
// Clear state flag.
@@ -277,16 +179,17 @@ var LibraryExceptions = {
277
179
#if EXCEPTION_DEBUG
278
180
err ( '__cxa_end_catch popped ' + [ info , exceptionLast , 'stack' , exceptionCaught ] ) ;
279
181
#endif
280
- exception_decRef ( info ) ;
182
+ ___cxa_decrement_exception_refcount ( info . excPtr ) ;
281
183
exceptionLast = 0 ; // XXX in decRef?
282
184
} ,
283
185
284
186
__cxa_get_exception_ptr__deps : [ '$ExceptionInfo' ] ,
285
187
__cxa_get_exception_ptr : function ( ptr ) {
188
+ var rtn = new ExceptionInfo ( ptr ) . get_exception_ptr ( ) ;
286
189
#if EXCEPTION_DEBUG
287
- err ( '__cxa_get_exception_ptr ' + ptrToString ( ptr ) ) ;
190
+ err ( '__cxa_get_exception_ptr ' + ptrToString ( ptr ) + ' -> ' + ptrToString ( rtn ) ) ;
288
191
#endif
289
- return new ExceptionInfo ( ptr ) . get_exception_ptr ( ) ;
192
+ return rtn ;
290
193
} ,
291
194
292
195
__cxa_uncaught_exceptions__deps : [ '$uncaughtExceptionCount' ] ,
@@ -302,13 +205,13 @@ var LibraryExceptions = {
302
205
throw exception ;
303
206
} ,
304
207
305
- __cxa_current_primary_exception__deps : [ '$exceptionCaught' , '$exception_addRef ' ] ,
208
+ __cxa_current_primary_exception__deps : [ '$exceptionCaught' , '__cxa_increment_exception_refcount ' ] ,
306
209
__cxa_current_primary_exception : function ( ) {
307
210
if ( ! exceptionCaught . length ) {
308
211
return 0 ;
309
212
}
310
213
var info = exceptionCaught [ exceptionCaught . length - 1 ] ;
311
- exception_addRef ( info ) ;
214
+ ___cxa_increment_exception_refcount ( info . excPtr ) ;
312
215
return info . excPtr ;
313
216
} ,
314
217
0 commit comments