From ac43d3f6db13f7dd2f95a51bfc612d8df53b2132 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sun, 29 Oct 2023 22:20:47 +0100 Subject: [PATCH] LibJS/JIT: Compile the PutPrivateById instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 3 +++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 20 ++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index c40207fa79..752595abe0 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -717,6 +717,9 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + Register base() const { return m_base; } + IdentifierTableIndex property() const { return m_property; } + private: Register m_base; IdentifierTableIndex m_property; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 2da08cc34a..53f29264b8 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1507,6 +1507,26 @@ void Compiler::compile_put_by_id_with_this(Bytecode::Op::PutByIdWithThis const& check_exception(); } +static Value cxx_put_private_by_id(VM& vm, Value base, Value value, DeprecatedFlyString const& name) +{ + auto object = TRY_OR_SET_EXCEPTION(base.to_object(vm)); + auto private_reference = make_private_reference(vm, object, name); + TRY_OR_SET_EXCEPTION(private_reference.put_value(vm, value)); + return value; +} + +void Compiler::compile_put_private_by_id(Bytecode::Op::PutPrivateById const& op) +{ + load_vm_register(ARG1, op.base()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + m_assembler.mov( + Assembler::Operand::Register(ARG3), + Assembler::Operand::Imm(bit_cast(&m_bytecode_executable.get_identifier(op.property())))); + native_call((void*)cxx_put_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 307ae911cf..39e8fb84be 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -125,7 +125,8 @@ private: O(GetByIdWithThis, get_by_id_with_this) \ O(GetByValueWithThis, get_by_value_with_this) \ O(DeleteByIdWithThis, delete_by_id_with_this) \ - O(PutByIdWithThis, put_by_id_with_this) + O(PutByIdWithThis, put_by_id_with_this) \ + O(PutPrivateById, put_private_by_id) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);