From 9494fbe670d3b923a7a719c9d4607b61df364a3a Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Mon, 30 Oct 2023 01:32:20 +0100 Subject: [PATCH] LibJS/JIT: Compile the PutByValueWithThis instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 5 +++++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 27 +++++++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index f93dfc511f..8d124774a4 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -844,6 +844,11 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + Register base() const { return m_base; } + Register property() const { return m_property; } + Register this_value() const { return m_this_value; } + PropertyKind kind() const { return m_kind; } + private: Register m_base; Register m_property; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 714b491a89..bb319f01d2 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1652,6 +1652,33 @@ void Compiler::compile_has_private_id(Bytecode::Op::HasPrivateId const& op) JS_ENUMERATE_NEW_BUILTIN_ERROR_BYTECODE_OPS(COMPILE_NEW_BUILTIN_ERROR_OP) # undef COMPILE_NEW_BUILTIN_ERROR_OP +static Value cxx_put_by_value_with_this(VM& vm, Value base, Value value, Value name, Value this_value, Bytecode::Op::PropertyKind kind) +{ + auto property_key = kind != Bytecode::Op::PropertyKind::Spread ? TRY_OR_SET_EXCEPTION(name.to_property_key(vm)) : PropertyKey {}; + TRY_OR_SET_EXCEPTION(Bytecode::put_by_property_key(vm, base, this_value, value, property_key, kind)); + return value; +} + +void Compiler::compile_put_by_value_with_this(Bytecode::Op::PutByValueWithThis const& op) +{ + load_vm_register(ARG1, op.base()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + if (op.kind() != Bytecode::Op::PropertyKind::Spread) { + load_vm_register(ARG3, op.property()); + } else { + m_assembler.mov( + Assembler::Operand::Register(ARG3), + Assembler::Operand::Imm(Value().encoded())); + } + load_vm_register(ARG4, op.this_value()); + m_assembler.mov( + Assembler::Operand::Register(ARG5), + Assembler::Operand::Imm(to_underlying(op.kind()))); + native_call((void*)cxx_put_by_value_with_this); + 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 7f9ff10680..4fa03fadd1 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -137,7 +137,8 @@ private: O(DeleteVariable, delete_variable) \ O(GetMethod, get_method) \ O(GetNewTarget, get_new_target) \ - O(HasPrivateId, has_private_id) + O(HasPrivateId, has_private_id) \ + O(PutByValueWithThis, put_by_value_with_this) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case, ...) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);