diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp index a3b03f9357..495e8911ab 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp @@ -646,4 +646,15 @@ ThrowCompletionOr delete_by_value(Bytecode::Interpreter& interpreter, Val return Value(TRY(reference.delete_(vm))); } +ThrowCompletionOr delete_by_value_with_this(Bytecode::Interpreter& interpreter, Value base, Value property_key_value, Value this_value) +{ + auto& vm = interpreter.vm(); + + auto property_key = TRY(property_key_value.to_property_key(vm)); + bool strict = vm.in_strict_mode(); + auto reference = Reference { base, property_key, this_value, strict }; + + return Value(TRY(reference.delete_(vm))); +} + } diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index deb3658dde..031adc9e2b 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -41,5 +41,6 @@ ThrowCompletionOr> iterator_to_array(VM&, Value iterator); ThrowCompletionOr append(VM& vm, Value lhs, Value rhs, bool is_spread); ThrowCompletionOr delete_by_id(Bytecode::Interpreter&, Value base, IdentifierTableIndex identifier); ThrowCompletionOr delete_by_value(Bytecode::Interpreter&, Value base, Value property_key_value); +ThrowCompletionOr delete_by_value_with_this(Bytecode::Interpreter&, Value base, Value property_key_value, Value this_value); } diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 013f3dacef..66e88b06dc 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1117,16 +1117,12 @@ ThrowCompletionOr DeleteByValue::execute_impl(Bytecode::Interpreter& inter ThrowCompletionOr DeleteByValueWithThis::execute_impl(Bytecode::Interpreter& interpreter) const { - auto& vm = interpreter.vm(); - // NOTE: Get the property key from the accumulator before side effects have a chance to overwrite it. auto property_key_value = interpreter.accumulator(); - auto base_value = interpreter.reg(m_base); - auto property_key = TRY(property_key_value.to_property_key(vm)); - bool strict = vm.in_strict_mode(); - auto reference = Reference { base_value, property_key, interpreter.reg(m_this_value), strict }; - interpreter.accumulator() = Value(TRY(reference.delete_(vm))); + auto this_value = interpreter.reg(m_this_value); + interpreter.accumulator() = TRY(delete_by_value_with_this(interpreter, base_value, property_key_value, this_value)); + return {}; } diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 99c7e09423..55718fee81 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -850,6 +850,9 @@ public: { } + Register base() const { return m_base; } + Register this_value() const { return m_this_value; } + ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index b6b00a8222..af465187bf 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1366,6 +1366,21 @@ void Compiler::compile_delete_by_value(Bytecode::Op::DeleteByValue const& op) check_exception(); } +static Value cxx_delete_by_value_with_this(VM& vm, Value base_value, Value property_key_value, Value this_value) +{ + return TRY_OR_SET_EXCEPTION(Bytecode::delete_by_value_with_this(vm.bytecode_interpreter(), base_value, property_key_value, this_value)); +} + +void Compiler::compile_delete_by_value_with_this(Bytecode::Op::DeleteByValueWithThis const& op) +{ + load_vm_register(ARG1, op.base()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + load_vm_register(ARG3, op.this_value()); + native_call((void*)cxx_delete_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 942f39d91a..f46980ace3 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -116,7 +116,8 @@ private: O(IteratorToArray, iterator_to_array) \ O(Append, append) \ O(DeleteById, delete_by_id) \ - O(DeleteByValue, delete_by_value) + O(DeleteByValue, delete_by_value) \ + O(DeleteByValueWithThis, delete_by_value_with_this) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);