1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

LibJS/JIT: Propagate exceptions in the simplest case :^)

We now establish a stack of "unwind contexts" similar to what the
bytecode interpreter does, but here, it's a stack of structs with
addresses to the catch and finally blocks.

Unwind contexts also have a "valid" flag, and the root unwind context
(always present, pushed on JIT code entry) has valid=false, which we
interpret in check_exception() as "return and let our caller deal with
the exception".

Anything in Compiler that may generate an exception should now also
call check_exception() ASAP to emit the code for handling this.
This commit is contained in:
Andreas Kling 2023-10-17 18:06:25 +02:00
parent 3523f9f722
commit e3560c2545
2 changed files with 100 additions and 2 deletions

View file

@ -24,8 +24,10 @@ private:
static constexpr auto ARG1 = Assembler::Reg::RSI;
static constexpr auto ARG2 = Assembler::Reg::RDX;
static constexpr auto RET = Assembler::Reg::RAX;
static constexpr auto STACK_POINTER = Assembler::Reg::RSP;
static constexpr auto REGISTER_ARRAY_BASE = Assembler::Reg::R8;
static constexpr auto LOCALS_ARRAY_BASE = Assembler::Reg::R9;
static constexpr auto UNWIND_CONTEXT_BASE = Assembler::Reg::R10;
void compile_load_immediate(Bytecode::Op::LoadImmediate const&);
void compile_load(Bytecode::Op::Load const&);
@ -45,6 +47,11 @@ private:
void compile_to_boolean(Assembler::Reg dst, Assembler::Reg src);
void check_exception();
void push_unwind_context(bool valid, Optional<Bytecode::Label> const& handler, Optional<Bytecode::Label> const& finalizer);
void pop_unwind_context();
Vector<u8> m_output;
Assembler m_assembler { m_output };
};