From 4e9edb8c534cf7d2ee86d7e82fa8ccaf8dca5488 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sun, 29 Oct 2023 21:24:50 +0100 Subject: [PATCH] LibJS/JIT: Compile the GetPrivateById instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 2 ++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 17 +++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 55718fee81..0da491dd4d 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -621,6 +621,8 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + IdentifierTableIndex property() const { return m_property; } + private: IdentifierTableIndex m_property; }; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 8643b98ad4..d12fbf92b3 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1395,6 +1395,23 @@ void Compiler::compile_get_object_property_iterator(Bytecode::Op::GetObjectPrope check_exception(); } +static Value cxx_get_private_by_id(VM& vm, Value base_value, DeprecatedFlyString& name) +{ + auto private_reference = make_private_reference(vm, base_value, name); + return TRY_OR_SET_EXCEPTION(private_reference.get_value(vm)); +} + +void Compiler::compile_get_private_by_id(Bytecode::Op::GetPrivateById const& op) +{ + load_vm_register(ARG1, Bytecode::Register::accumulator()); + m_assembler.mov( + Assembler::Operand::Register(ARG2), + Assembler::Operand::Imm(bit_cast(&m_bytecode_executable.get_identifier(op.property())))); + native_call((void*)cxx_get_private_by_id); + store_vm_register(Bytecode::Register::accumulator(), RET); + check_exception(); +} + void Compiler::jump_to_exit() { m_assembler.jump(m_exit_label); diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index ef6c0010c2..41f6cb21de 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -119,7 +119,8 @@ private: O(DeleteById, delete_by_id) \ O(DeleteByValue, delete_by_value) \ O(DeleteByValueWithThis, delete_by_value_with_this) \ - O(GetObjectPropertyIterator, get_object_property_iterator) + O(GetObjectPropertyIterator, get_object_property_iterator) \ + O(GetPrivateById, get_private_by_id) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);