@@ -9,20 +9,6 @@ var LibraryExceptions = {
99 $exceptionLast : '0' ,
1010 $exceptionCaught : ' []' ,
1111
12- // Static fields for ExceptionInfo class.
13- $ExceptionInfoAttrs : {
14- // ExceptionInfo native structure layout.
15- DESTRUCTOR_OFFSET : 0 ,
16- REFCOUNT_OFFSET : Runtime . POINTER_SIZE ,
17- TYPE_OFFSET : Runtime . POINTER_SIZE + 4 ,
18- CAUGHT_OFFSET : Runtime . POINTER_SIZE + 8 ,
19- RETHROWN_OFFSET : Runtime . POINTER_SIZE + 9 ,
20-
21- // Total structure size with padding, should be multiple of allocation alignment.
22- SIZE : alignMemory ( Runtime . POINTER_SIZE + 10 )
23- } ,
24-
25- $ExceptionInfo__deps : [ '$ExceptionInfoAttrs' ] ,
2612 // This class is the exception metadata which is prepended to each thrown object (in WASM memory).
2713 // It is allocated in one block among with a thrown object in __cxa_allocate_exception and freed
2814 // in ___cxa_free_exception. It roughly corresponds to __cxa_exception structure in libcxxabi. The
@@ -37,44 +23,44 @@ var LibraryExceptions = {
3723 // excPtr - Thrown object pointer to wrap. Metadata pointer is calculated from it.
3824 $ExceptionInfo : function ( excPtr ) {
3925 this . excPtr = excPtr ;
40- this . ptr = excPtr - ExceptionInfoAttrs . SIZE ;
26+ this . ptr = excPtr - { { { C_STRUCTS . __cxa_exception . __size__ } } } ;
4127
4228 this . set_type = function ( type ) {
43- { { { makeSetValue ( 'this.ptr' , 'ExceptionInfoAttrs.TYPE_OFFSET' , 'type' , '*' ) } } } ;
29+ { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . exceptionType , 'type' , '*' ) } } } ;
4430 } ;
4531
4632 this . get_type = function ( ) {
47- return { { { makeGetValue ( 'this.ptr' , 'ExceptionInfoAttrs.TYPE_OFFSET' , '*' ) } } } ;
33+ return { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . exceptionType , '*' ) } } } ;
4834 } ;
4935
5036 this . set_destructor = function ( destructor ) {
51- { { { makeSetValue ( 'this.ptr' , 'ExceptionInfoAttrs.DESTRUCTOR_OFFSET' , 'destructor' , '*' ) } } } ;
37+ { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . exceptionDestructor , 'destructor' , '*' ) } } } ;
5238 } ;
5339
5440 this . get_destructor = function ( ) {
55- return { { { makeGetValue ( 'this.ptr' , 'ExceptionInfoAttrs.DESTRUCTOR_OFFSET' , '*' ) } } } ;
41+ return { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . exceptionDestructor , '*' ) } } } ;
5642 } ;
5743
5844 this . set_refcount = function ( refcount ) {
59- { { { makeSetValue ( 'this.ptr' , 'ExceptionInfoAttrs.REFCOUNT_OFFSET' , 'refcount' , 'i32' ) } } } ;
45+ { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'refcount' , 'i32' ) } } } ;
6046 } ;
6147
6248 this . set_caught = function ( caught ) {
6349 caught = caught ? 1 : 0 ;
64- { { { makeSetValue ( 'this.ptr' , 'ExceptionInfoAttrs.CAUGHT_OFFSET' , 'caught' , 'i8' ) } } } ;
50+ { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . caught , 'caught' , 'i8' ) } } } ;
6551 } ;
6652
6753 this . get_caught = function ( ) {
68- return { { { makeGetValue ( 'this.ptr' , 'ExceptionInfoAttrs.CAUGHT_OFFSET' , 'i8' ) } } } != 0 ;
54+ return { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . caught , 'i8' ) } } } != 0 ;
6955 } ;
7056
7157 this . set_rethrown = function ( rethrown ) {
7258 rethrown = rethrown ? 1 : 0 ;
73- { { { makeSetValue ( 'this.ptr' , 'ExceptionInfoAttrs.RETHROWN_OFFSET' , 'rethrown' , 'i8' ) } } } ;
59+ { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . rethrown , 'rethrown' , 'i8' ) } } } ;
7460 } ;
7561
7662 this . get_rethrown = function ( ) {
77- return { { { makeGetValue ( 'this.ptr' , 'ExceptionInfoAttrs.RETHROWN_OFFSET' , 'i8' ) } } } != 0 ;
63+ return { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . rethrown , 'i8' ) } } } != 0 ;
7864 } ;
7965
8066 // Initialize native structure fields. Should be called once after allocated.
@@ -88,20 +74,20 @@ var LibraryExceptions = {
8874
8975 this . add_ref = function ( ) {
9076#if USE_PTHREADS
91- Atomics . add ( HEAP32 , ( this . ptr + ExceptionInfoAttrs . REFCOUNT_OFFSET ) >> 2 , 1 ) ;
77+ Atomics . add ( HEAP32 , ( this . ptr + { { { C_STRUCTS . __cxa_exception . referenceCount } } } ) >> 2 , 1 ) ;
9278#else
93- var value = { { { makeGetValue ( 'this.ptr' , 'ExceptionInfoAttrs.REFCOUNT_OFFSET' , 'i32' ) } } } ;
94- { { { makeSetValue ( 'this.ptr' , 'ExceptionInfoAttrs.REFCOUNT_OFFSET' , 'value + 1' , 'i32' ) } } } ;
79+ var value = { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'i32' ) } } } ;
80+ { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'value + 1' , 'i32' ) } } } ;
9581#endif
9682 } ;
9783
9884 // Returns true if last reference released.
9985 this . release_ref = function ( ) {
10086#if USE_PTHREADS
101- var prev = Atomics . sub ( HEAP32 , ( this . ptr + ExceptionInfoAttrs . REFCOUNT_OFFSET ) >> 2 , 1 ) ;
87+ var prev = Atomics . sub ( HEAP32 , ( this . ptr + { { { C_STRUCTS . __cxa_exception . referenceCount } } } ) >> 2 , 1 ) ;
10288#else
103- var prev = { { { makeGetValue ( 'this.ptr' , 'ExceptionInfoAttrs.REFCOUNT_OFFSET' , 'i32' ) } } } ;
104- { { { makeSetValue ( 'this.ptr' , 'ExceptionInfoAttrs.REFCOUNT_OFFSET' , 'prev - 1' , 'i32' ) } } } ;
89+ var prev = { { { makeGetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'i32' ) } } } ;
90+ { { { makeSetValue ( 'this.ptr' , C_STRUCTS . __cxa_exception . referenceCount , 'prev - 1' , 'i32' ) } } } ;
10591#endif
10692#if ASSERTIONS
10793 assert ( prev > 0 ) ;
@@ -205,11 +191,10 @@ var LibraryExceptions = {
205191 } ,
206192
207193 // Exceptions
208- __cxa_allocate_exception__deps : [ '$ExceptionInfoAttrs' ] ,
209194 __cxa_allocate_exception__sig : 'vi' ,
210195 __cxa_allocate_exception : function ( size ) {
211196 // Thrown object is prepended by exception metadata block
212- return _malloc ( size + ExceptionInfoAttrs . SIZE ) + ExceptionInfoAttrs . SIZE ;
197+ return _malloc ( size + { { { C_STRUCTS . __cxa_exception . __size__ } } } ) + { { { C_STRUCTS . __cxa_exception . __size__ } } } ;
213198 } ,
214199
215200 __cxa_free_exception__deps: [ '$ExceptionInfo' ] ,
0 commit comments