mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:57:45 +00:00
LibJS/Bytecode: Implement the delete unary expression
`delete` has to operate directly on Reference Records, so this introduces a new set of operations called DeleteByValue, DeleteVariable and DeleteById. They operate similarly to their Get counterparts, except they end in creating a (temporary) Reference and calling delete_ on it.
This commit is contained in:
parent
589c3771e9
commit
7cc53b7ef1
6 changed files with 146 additions and 4 deletions
|
@ -378,6 +378,22 @@ private:
|
|||
Optional<EnvironmentCoordinate> mutable m_cached_environment_coordinate;
|
||||
};
|
||||
|
||||
class DeleteVariable final : public Instruction {
|
||||
public:
|
||||
explicit DeleteVariable(IdentifierTableIndex identifier)
|
||||
: Instruction(Type::DeleteVariable)
|
||||
, m_identifier(identifier)
|
||||
{
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
||||
String to_string_impl(Bytecode::Executable const&) const;
|
||||
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
||||
|
||||
private:
|
||||
IdentifierTableIndex m_identifier;
|
||||
};
|
||||
|
||||
class GetById final : public Instruction {
|
||||
public:
|
||||
explicit GetById(IdentifierTableIndex property)
|
||||
|
@ -412,6 +428,22 @@ private:
|
|||
IdentifierTableIndex m_property;
|
||||
};
|
||||
|
||||
class DeleteById final : public Instruction {
|
||||
public:
|
||||
explicit DeleteById(IdentifierTableIndex property)
|
||||
: Instruction(Type::DeleteById)
|
||||
, m_property(property)
|
||||
{
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
||||
String to_string_impl(Bytecode::Executable const&) const;
|
||||
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
||||
|
||||
private:
|
||||
IdentifierTableIndex m_property;
|
||||
};
|
||||
|
||||
class GetByValue final : public Instruction {
|
||||
public:
|
||||
explicit GetByValue(Register base)
|
||||
|
@ -446,6 +478,22 @@ private:
|
|||
Register m_property;
|
||||
};
|
||||
|
||||
class DeleteByValue final : public Instruction {
|
||||
public:
|
||||
DeleteByValue(Register base)
|
||||
: Instruction(Type::DeleteByValue)
|
||||
, m_base(base)
|
||||
{
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
||||
String to_string_impl(Bytecode::Executable const&) const;
|
||||
void replace_references_impl(BasicBlock const&, BasicBlock const&) { }
|
||||
|
||||
private:
|
||||
Register m_base;
|
||||
};
|
||||
|
||||
class Jump : public Instruction {
|
||||
public:
|
||||
constexpr static bool IsTerminator = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue