Skip to content

Remove a static allocation in C++ exceptions support code in JS #12039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/library_exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var LibraryExceptions = {
$exceptionLast: '0',
$exceptionCaught: ' []',
$exceptionThrowBuf: '0',

// Static fields for ExceptionInfo class.
$ExceptionInfoAttrs: {
Expand Down Expand Up @@ -395,7 +396,7 @@ var LibraryExceptions = {
// unwinding using 'if' blocks around each function, so the remaining
// functionality boils down to picking a suitable 'catch' block.
// We'll do that here, instead, to keep things simpler.
__cxa_find_matching_catch__deps: ['$exceptionLast', '$ExceptionInfo', '$CatchInfo', '__resumeException'],
__cxa_find_matching_catch__deps: ['$exceptionLast', '$ExceptionInfo', '$CatchInfo', '__resumeException', '$exceptionThrowBuf'],
__cxa_find_matching_catch: function() {
var thrown = exceptionLast;
if (!thrown) {
Expand All @@ -416,12 +417,10 @@ var LibraryExceptions = {
#if EXCEPTION_DEBUG
out("can_catch on " + [thrown]);
#endif
#if DISABLE_EXCEPTION_CATCHING == 1
var thrownBuf = 0;
#else
var thrownBuf = {{{ makeStaticAlloc(4) }}};
#endif
{{{ makeSetValue('thrownBuf', '0', 'thrown', '*') }}};
if (!exceptionThrowBuf) {
exceptionThrowBuf = _malloc(4);
}
{{{ makeSetValue('exceptionThrowBuf', '0', 'thrown', '*') }}};
// The different catch blocks are denoted by different types.
// Due to inheritance, those types may not precisely match the
// type of the thrown object. Find one which matches, and
Expand All @@ -432,8 +431,8 @@ var LibraryExceptions = {
// Catch all clause matched or exactly the same type is caught
break;
}
if ({{{ exportedAsmFunc('___cxa_can_catch') }}}(caughtType, thrownType, thrownBuf)) {
var adjusted = {{{ makeGetValue('thrownBuf', '0', '*') }}};
if ({{{ exportedAsmFunc('___cxa_can_catch') }}}(caughtType, thrownType, exceptionThrowBuf)) {
var adjusted = {{{ makeGetValue('exceptionThrowBuf', '0', '*') }}};
if (thrown !== adjusted) {
catchInfo.set_adjusted_ptr(adjusted);
}
Expand Down