diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp index f0bb6ddf26..a3b03f9357 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp @@ -635,4 +635,15 @@ ThrowCompletionOr delete_by_id(Bytecode::Interpreter& interpreter, Value return TRY(reference.delete_(vm)); } +ThrowCompletionOr delete_by_value(Bytecode::Interpreter& interpreter, Value base, Value property_key_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, {}, strict }; + + return Value(TRY(reference.delete_(vm))); +} + } diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index 3b48b623c8..deb3658dde 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -40,5 +40,6 @@ IteratorRecord object_to_iterator(VM&, Object&); 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); } diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 59864ea9ac..013f3dacef 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1108,16 +1108,10 @@ ThrowCompletionOr PutByValueWithThis::execute_impl(Bytecode::Interpreter& ThrowCompletionOr DeleteByValue::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, {}, strict }; - interpreter.accumulator() = Value(TRY(reference.delete_(vm))); + auto property_key_value = interpreter.accumulator(); + interpreter.accumulator() = TRY(delete_by_value(interpreter, base_value, property_key_value)); + return {}; } diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 97c760517c..99c7e09423 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -835,6 +835,8 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + Register base() const { return m_base; } + private: Register m_base; }; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index eed427a85b..b6b00a8222 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1352,6 +1352,20 @@ void Compiler::compile_delete_by_id(Bytecode::Op::DeleteById const& op) check_exception(); } +static Value cxx_delete_by_value(VM& vm, Value base_value, Value property_key_value) +{ + return TRY_OR_SET_EXCEPTION(Bytecode::delete_by_value(vm.bytecode_interpreter(), base_value, property_key_value)); +} + +void Compiler::compile_delete_by_value(Bytecode::Op::DeleteByValue const& op) +{ + load_vm_register(ARG1, op.base()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + native_call((void*)cxx_delete_by_value); + 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 6a956238a4..942f39d91a 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -115,7 +115,8 @@ private: O(IteratorClose, iterator_close) \ O(IteratorToArray, iterator_to_array) \ O(Append, append) \ - O(DeleteById, delete_by_id) + O(DeleteById, delete_by_id) \ + O(DeleteByValue, delete_by_value) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);