mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47: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:
parent
c2108489a5
commit
fcc3348bc8
5 changed files with 81 additions and 9 deletions
|
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue