1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:17:35 +00:00

LibJS/JIT: Compile the DeleteByValue instruction

This commit is contained in:
Jakub Berkop 2023-10-29 21:20:25 +01:00 committed by Andreas Kling
parent f5fcd4596c
commit 0776404e03
6 changed files with 33 additions and 10 deletions

View file

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

View file

@ -40,5 +40,6 @@ IteratorRecord object_to_iterator(VM&, Object&);
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);
}

View file

@ -1108,16 +1108,10 @@ ThrowCompletionOr<void> PutByValueWithThis::execute_impl(Bytecode::Interpreter&
ThrowCompletionOr<void> 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 {};
}

View file

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