1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibJS: Intercept returns through finally blocks in Bytecode

This is still not perfect, as we now actually crash in the
`try-finally-continue` tests, while we now succeed all
`try-catch-finally-*` tests.

Note that we do not yet go through the finally block when exiting the
unwind context through a break or continue.
This commit is contained in:
Hendiadyoin1 2022-11-13 20:56:53 +01:00 committed by Ali Mohammad Pur
parent c2108489a5
commit fcc3348bc8
5 changed files with 81 additions and 9 deletions

View file

@ -169,6 +169,7 @@ public:
Break,
Continue,
Unwind,
ReturnToFinally,
LeaveLexicalEnvironment,
LeaveVariableEnvironment,
};
@ -188,12 +189,27 @@ public:
auto boundary = m_boundaries[i - 1];
if (boundary_to_stop_at.has_value() && boundary == *boundary_to_stop_at)
break;
if (boundary == BlockBoundaryType::Unwind)
using enum BlockBoundaryType;
switch (boundary) {
case Unwind:
emit<Bytecode::Op::LeaveUnwindContext>();
else if (boundary == BlockBoundaryType::LeaveLexicalEnvironment)
break;
case LeaveLexicalEnvironment:
emit<Bytecode::Op::LeaveEnvironment>(Bytecode::Op::EnvironmentMode::Lexical);
else if (boundary == BlockBoundaryType::LeaveVariableEnvironment)
break;
case LeaveVariableEnvironment:
emit<Bytecode::Op::LeaveEnvironment>(Bytecode::Op::EnvironmentMode::Var);
break;
case Break:
case Continue:
break;
case ReturnToFinally:
// FIXME: In the case of breaks/continues we need to tell the `finally` to break/continue
// For now let's ignore the finally to avoid a crash
if (IsSame<OpType, Bytecode::Op::Jump>)
break;
return;
};
}
}