Skip to content

Commit af8e829

Browse files
committed
.
1 parent 9aca4d4 commit af8e829

File tree

2 files changed

+51
-83
lines changed

2 files changed

+51
-83
lines changed

src/library_exceptions.js

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -62,70 +62,6 @@ var LibraryExceptions = {
6262
}
6363
},
6464

65-
$CatchInfo__deps: ['$ExceptionInfo', '__cxa_is_pointer_type'],
66-
// This native structure is returned from __cxa_find_matching_catch, and serves as catching
67-
// context, i.e. stores information required to proceed with a specific selected catch. It stores
68-
// base and adjusted pointers of a thrown object. It is allocated dynamically and should be freed
69-
// when it is done with a specific catch (i.e. either in __cxa_end_catch when caught or in
70-
// __resumeException when no catch clause matched). The class itself is just a native pointer
71-
// wrapper, and contains all the necessary accessors for the fields in the native structure.
72-
// ptr - Native structure pointer to wrap, the structure is allocated when not specified.
73-
$CatchInfo: function(ptr) {
74-
75-
this.free = function() {
76-
_free(this.ptr);
77-
this.ptr = 0;
78-
};
79-
80-
this.set_base_ptr = function(basePtr) {
81-
{{{ makeSetValue('this.ptr', '0', 'basePtr', '*') }}};
82-
};
83-
84-
this.get_base_ptr = function() {
85-
return {{{ makeGetValue('this.ptr', '0', '*') }}};
86-
};
87-
88-
this.set_adjusted_ptr = function(adjustedPtr) {
89-
{{{ makeSetValue('this.ptr', Runtime.POINTER_SIZE, 'adjustedPtr', '*') }}};
90-
};
91-
92-
this.get_adjusted_ptr_addr = function() {
93-
return this.ptr + {{{ Runtime.POINTER_SIZE }}};
94-
}
95-
96-
this.get_adjusted_ptr = function() {
97-
return {{{ makeGetValue('this.ptr', Runtime.POINTER_SIZE, '*') }}};
98-
};
99-
100-
// Get pointer which is expected to be received by catch clause in C++ code. It may be adjusted
101-
// when the pointer is casted to some of the exception object base classes (e.g. when virtual
102-
// inheritance is used). When a pointer is thrown this method should return the thrown pointer
103-
// itself.
104-
this.get_exception_ptr = function() {
105-
// Work around a fastcomp bug, this code is still included for some reason in a build without
106-
// exceptions support.
107-
var isPointer = {{{ exportedAsmFunc('___cxa_is_pointer_type') }}}(
108-
this.get_exception_info().get_type());
109-
if (isPointer) {
110-
return {{{ makeGetValue('this.get_base_ptr()', '0', '*') }}};
111-
}
112-
var adjusted = this.get_adjusted_ptr();
113-
if (adjusted !== 0) return adjusted;
114-
return this.get_base_ptr();
115-
};
116-
117-
this.get_exception_info = function() {
118-
return new ExceptionInfo(this.get_base_ptr());
119-
};
120-
121-
if (ptr === undefined) {
122-
this.ptr = _malloc({{{ Runtime.POINTER_SIZE * 2 }}});
123-
this.set_adjusted_ptr(0);
124-
} else {
125-
this.ptr = ptr;
126-
}
127-
},
128-
12965
// Here, we throw an exception after recording a couple of values that we need to remember
13066
// We also remember that it was the last exception thrown as we need to know that later.
13167
__cxa_throw__sig: 'viii',
@@ -175,25 +111,6 @@ var LibraryExceptions = {
175111
return type;
176112
},
177113

178-
__cxa_begin_catch__deps: ['$CatchInfo', '$exceptionCaught',
179-
'$uncaughtExceptionCount',
180-
'__cxa_increment_exception_refcount'],
181-
__cxa_begin_catch: function(ptr) {
182-
var catchInfo = new CatchInfo(ptr);
183-
var info = catchInfo.get_exception_info();
184-
if (!info.get_caught()) {
185-
info.set_caught(true);
186-
uncaughtExceptionCount--;
187-
}
188-
info.set_rethrown(false);
189-
exceptionCaught.push(catchInfo);
190-
#if EXCEPTION_DEBUG
191-
err('cxa_begin_catch ' + [ptr, 'stack', exceptionCaught]);
192-
#endif
193-
___cxa_increment_exception_refcount(catchInfo.get_base_ptr());
194-
return catchInfo.get_exception_ptr();
195-
},
196-
197114
// We're done with a catch. Now, we can run the destructor if there is one
198115
// and free the exception. Note that if the dynCall on the destructor fails
199116
// due to calling apply on undefined, that means that the destructor is

system/lib/libcxxabi/src/cxa_exception_emscripten.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,57 @@ _LIBCXXABI_NO_CFI void __cxa_decrement_exception_refcount(void *thrown_object) _
5454
}
5555
}
5656
}
57+
58+
// This native structure is returned from __cxa_find_matching_catch, and serves as catching
59+
// context, i.e. stores information required to proceed with a specific selected catch. It stores
60+
// base and adjusted pointers of a thrown object. It is allocated dynamically and should be freed
61+
// when it is done with a specific catch (i.e. either in __cxa_end_catch when caught or in
62+
// __resumeException when no catch clause matched). The class itself is just a native pointer
63+
// wrapper, and contains all the necessary accessors for the fields in the native structure.
64+
// ptr - Native structure pointer to wrap, the structure is allocated when not specified.
65+
struct __catch_info {
66+
void* basePtr;
67+
void* adjustedPtr;
68+
};
69+
70+
static __cxa_exception* get_exception_info(__catch_info* info) {
71+
return (__cxa_exception*)info->basePtr;
72+
}
73+
74+
// Get pointer which is expected to be received by catch clause in C++ code. It may be adjusted
75+
// when the pointer is casted to some of the exception object base classes (e.g. when virtual
76+
// inheritance is used). When a pointer is thrown this method should return the thrown pointer
77+
// itself.
78+
static void* get_thrown_object(__catch_info* info) {
79+
bool isPointer = ___cxa_is_pointer_type(get_exception_info(info)->exceptionType);
80+
if (isPointer) {
81+
return *this.basePtr;
82+
}
83+
void* adjusted = get_adjusted_ptr(info);
84+
if (adjusted) {
85+
return adjusted;
86+
}
87+
return info.basePtr;
88+
}
89+
90+
static int uncaughtExceptionCount;
91+
static std::vector<__catch_info*> exceptionCaught;
92+
93+
void* __cxa_begin_catch(void* unwind_arg) _NOEXCEPT
94+
__catch_info* info = (__catch_info*)unwind_arg;
95+
__cxa_exception* ex = get_exception_info(info);
96+
if (!ex->caught()) {
97+
ex->caught = true;
98+
uncaughtExceptionCount--;
99+
}
100+
info->rethrown = false;
101+
exceptionCaught.push_back(info);
102+
#if 0
103+
err('cxa_begin_catch ' + [ptr, 'stack', exceptionCaught]);
104+
#endif
105+
__cxa_increment_exception_refcount(info->basePtr);
106+
return get_thrown_object(info);
107+
}
57108
#endif
58109

59110
}

0 commit comments

Comments
 (0)