From 82c057391ea59358f9a291bce661f80284a86e04 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Mon, 30 Oct 2023 09:55:50 +0100 Subject: [PATCH] LibJS/JIT: Handle uninitialized bindings in GetLocal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test262: +78 ✅ -72 ❌ -4 💥️ --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index b6101ac2ae..87e620dda4 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -93,9 +93,32 @@ void Compiler::compile_store(Bytecode::Op::Store const& op) store_vm_register(op.dst(), GPR0); } +static Value cxx_throw_binding_not_initialized(VM& vm, size_t index) +{ + auto const& variable_name = vm.running_execution_context().function->local_variables_names()[index]; + TRY_OR_SET_EXCEPTION(vm.throw_completion(ErrorType::BindingNotInitialized, variable_name)); + return {}; +} + void Compiler::compile_get_local(Bytecode::Op::GetLocal const& op) { load_vm_local(GPR0, op.index()); + + // if (GPR0 == ) throw ReferenceError(BindingNotInitialized) + Assembler::Label not_empty {}; + m_assembler.mov( + Assembler::Operand::Register(GPR1), + Assembler::Operand::Imm(Value().encoded())); + m_assembler.jump_if( + Assembler::Operand::Register(GPR0), + Assembler::Condition::NotEqualTo, + Assembler::Operand::Register(GPR1), + not_empty); + m_assembler.mov(Assembler::Operand::Register(ARG1), Assembler::Operand::Imm(op.index())); + native_call((void*)cxx_throw_binding_not_initialized); + check_exception(); + not_empty.link(m_assembler); + store_vm_register(Bytecode::Register::accumulator(), GPR0); }