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

LibJS/JIT: Update "unwind context" stack in JIT code

Until now, the unwind context stack has not been maintained by jitted
code, which meant we were unable to support the `with` statement.
This is a first step towards supporting that by making jitted code
call out to C++ to update the unwind context stack when entering/leaving
unwind contexts.

We also introduce a new "Catch" bytecode instruction that moves the
current exception into the accumulator. It's always emitted at the start
of a "catch" block.
This commit is contained in:
Andreas Kling 2023-11-11 23:19:46 +01:00
parent 298dfa96a4
commit cfdb8a2756
7 changed files with 60 additions and 7 deletions

View file

@ -560,14 +560,25 @@ void Compiler::check_exception()
}
}
static void cxx_enter_unwind_context(VM& vm)
{
vm.bytecode_interpreter().enter_unwind_context();
}
void Compiler::compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const& op)
{
native_call((void*)cxx_enter_unwind_context);
m_assembler.jump(label_for(op.entry_point().block()));
}
static void cxx_leave_unwind_context(VM& vm)
{
vm.bytecode_interpreter().leave_unwind_context();
}
void Compiler::compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext const&)
{
/* Nothing */
native_call((void*)cxx_leave_unwind_context);
}
void Compiler::compile_throw(Bytecode::Op::Throw const&)
@ -577,6 +588,16 @@ void Compiler::compile_throw(Bytecode::Op::Throw const&)
check_exception();
}
static void cxx_catch(VM& vm)
{
vm.bytecode_interpreter().catch_exception();
}
void Compiler::compile_catch(Bytecode::Op::Catch const&)
{
native_call((void*)cxx_catch);
}
static ThrowCompletionOr<Value> loosely_inequals(VM& vm, Value src1, Value src2)
{
return Value(!TRY(is_loosely_equal(vm, src1, src2)));