mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibJS/JIT: Compile the DeleteByValue instruction
This commit is contained in:
parent
f5fcd4596c
commit
0776404e03
6 changed files with 33 additions and 10 deletions
|
@ -635,4 +635,15 @@ ThrowCompletionOr<Value> delete_by_id(Bytecode::Interpreter& interpreter, Value
|
||||||
return TRY(reference.delete_(vm));
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,5 +40,6 @@ IteratorRecord object_to_iterator(VM&, Object&);
|
||||||
ThrowCompletionOr<NonnullGCPtr<Array>> iterator_to_array(VM&, Value iterator);
|
ThrowCompletionOr<NonnullGCPtr<Array>> iterator_to_array(VM&, Value iterator);
|
||||||
ThrowCompletionOr<void> append(VM& vm, Value lhs, Value rhs, bool is_spread);
|
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_id(Bytecode::Interpreter&, Value base, IdentifierTableIndex identifier);
|
||||||
|
ThrowCompletionOr<Value> delete_by_value(Bytecode::Interpreter&, Value base, Value property_key_value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1108,16 +1108,10 @@ ThrowCompletionOr<void> PutByValueWithThis::execute_impl(Bytecode::Interpreter&
|
||||||
|
|
||||||
ThrowCompletionOr<void> DeleteByValue::execute_impl(Bytecode::Interpreter& interpreter) const
|
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 base_value = interpreter.reg(m_base);
|
||||||
auto property_key = TRY(property_key_value.to_property_key(vm));
|
auto property_key_value = interpreter.accumulator();
|
||||||
bool strict = vm.in_strict_mode();
|
interpreter.accumulator() = TRY(delete_by_value(interpreter, base_value, property_key_value));
|
||||||
auto reference = Reference { base_value, property_key, {}, strict };
|
|
||||||
interpreter.accumulator() = Value(TRY(reference.delete_(vm)));
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -835,6 +835,8 @@ public:
|
||||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
||||||
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
||||||
|
|
||||||
|
Register base() const { return m_base; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Register m_base;
|
Register m_base;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1352,6 +1352,20 @@ void Compiler::compile_delete_by_id(Bytecode::Op::DeleteById const& op)
|
||||||
check_exception();
|
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()
|
void Compiler::jump_to_exit()
|
||||||
{
|
{
|
||||||
m_assembler.jump(m_exit_label);
|
m_assembler.jump(m_exit_label);
|
||||||
|
|
|
@ -115,7 +115,8 @@ private:
|
||||||
O(IteratorClose, iterator_close) \
|
O(IteratorClose, iterator_close) \
|
||||||
O(IteratorToArray, iterator_to_array) \
|
O(IteratorToArray, iterator_to_array) \
|
||||||
O(Append, append) \
|
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) \
|
# define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \
|
||||||
void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);
|
void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue