1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:47:43 +00:00

LibJS/JIT: Compile the DeleteByValueWithThis instruction

This commit is contained in:
Jakub Berkop 2023-10-29 21:37:52 +01:00 committed by Andreas Kling
parent 0776404e03
commit 6a7b9b85a4
6 changed files with 35 additions and 8 deletions

View file

@ -646,4 +646,15 @@ ThrowCompletionOr<Value> delete_by_value(Bytecode::Interpreter& interpreter, Val
return Value(TRY(reference.delete_(vm)));
}
ThrowCompletionOr<Value> 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)));
}
}

View file

@ -41,5 +41,6 @@ ThrowCompletionOr<NonnullGCPtr<Array>> iterator_to_array(VM&, Value iterator);
ThrowCompletionOr<void> append(VM& vm, Value lhs, Value rhs, bool is_spread);
ThrowCompletionOr<Value> delete_by_id(Bytecode::Interpreter&, Value base, IdentifierTableIndex identifier);
ThrowCompletionOr<Value> delete_by_value(Bytecode::Interpreter&, Value base, Value property_key_value);
ThrowCompletionOr<Value> delete_by_value_with_this(Bytecode::Interpreter&, Value base, Value property_key_value, Value this_value);
}

View file

@ -1117,16 +1117,12 @@ ThrowCompletionOr<void> DeleteByValue::execute_impl(Bytecode::Interpreter& inter
ThrowCompletionOr<void> 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 {};
}

View file

@ -850,6 +850,9 @@ public:
{
}
Register base() const { return m_base; }
Register this_value() const { return m_this_value; }
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;

View file

@ -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);

View file

@ -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&);