From a16082c6a5f473b2a5290f85088ce721f2eba931 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Mon, 30 Oct 2023 00:28:13 +0100 Subject: [PATCH] LibJS/JIT: Compile the HasPrivateId instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 2 ++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 22 ++++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 56f12737f5..8eee7b7c11 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -645,6 +645,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 3bcb184850..9bf2d278d9 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1596,6 +1596,28 @@ void Compiler::compile_get_new_target(Bytecode::Op::GetNewTarget const&) store_vm_register(Bytecode::Register::accumulator(), RET); } +static Value cxx_has_private_id(VM& vm, Value object, DeprecatedFlyString const& identifier) +{ + if (!object.is_object()) + TRY_OR_SET_EXCEPTION(vm.throw_completion(ErrorType::InOperatorWithObject)); + + auto private_environment = vm.running_execution_context().private_environment; + VERIFY(private_environment); + auto private_name = private_environment->resolve_private_identifier(identifier); + return Value(object.as_object().private_element_find(private_name) != nullptr); +} + +void Compiler::compile_has_private_id(Bytecode::Op::HasPrivateId 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_has_private_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 852662714f..932dd01aca 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -131,7 +131,8 @@ private: O(GetImportMeta, get_import_meta) \ O(DeleteVariable, delete_variable) \ O(GetMethod, get_method) \ - O(GetNewTarget, get_new_target) + O(GetNewTarget, get_new_target) \ + O(HasPrivateId, has_private_id) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);