mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:57:42 +00:00
LibJS: Add PutById bytecode instruction for object property assignment
Note that this is only used for non-computed accesses. Computed access is not yet implemented. :^)
This commit is contained in:
parent
bea6e31ddc
commit
14cfc44855
3 changed files with 44 additions and 0 deletions
|
@ -90,6 +90,20 @@ Optional<Bytecode::Register> AssignmentExpression::generate_bytecode(Bytecode::G
|
||||||
return rhs_reg;
|
return rhs_reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is<MemberExpression>(*m_lhs)) {
|
||||||
|
auto& expression = static_cast<MemberExpression const&>(*m_lhs);
|
||||||
|
auto object_reg = expression.object().generate_bytecode(generator);
|
||||||
|
|
||||||
|
if (expression.is_computed()) {
|
||||||
|
TODO();
|
||||||
|
} else {
|
||||||
|
VERIFY(is<Identifier>(expression.property()));
|
||||||
|
auto rhs_reg = m_rhs->generate_bytecode(generator);
|
||||||
|
generator.emit<Bytecode::Op::PutById>(*object_reg, static_cast<Identifier const&>(expression.property()).string(), *rhs_reg);
|
||||||
|
return rhs_reg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,12 @@ void SetVariable::execute(Bytecode::Interpreter& interpreter) const
|
||||||
interpreter.vm().set_variable(m_identifier, interpreter.reg(m_src), interpreter.global_object());
|
interpreter.vm().set_variable(m_identifier, interpreter.reg(m_src), interpreter.global_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PutById::execute(Bytecode::Interpreter& interpreter) const
|
||||||
|
{
|
||||||
|
if (auto* object = interpreter.reg(m_base).to_object(interpreter.global_object()))
|
||||||
|
object->put(m_property, interpreter.reg(m_src));
|
||||||
|
}
|
||||||
|
|
||||||
void Jump::execute(Bytecode::Interpreter& interpreter) const
|
void Jump::execute(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
interpreter.jump(m_target);
|
interpreter.jump(m_target);
|
||||||
|
@ -122,6 +128,11 @@ String SetVariable::to_string() const
|
||||||
return String::formatted("SetVariable identifier:{}, src:{}", m_identifier, m_src);
|
return String::formatted("SetVariable identifier:{}, src:{}", m_identifier, m_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String PutById::to_string() const
|
||||||
|
{
|
||||||
|
return String::formatted("PutById base:{}, property:{}, src:{}", m_base, m_property, m_src);
|
||||||
|
}
|
||||||
|
|
||||||
String Jump::to_string() const
|
String Jump::to_string() const
|
||||||
{
|
{
|
||||||
return String::formatted("Jump {}", m_target);
|
return String::formatted("Jump {}", m_target);
|
||||||
|
|
|
@ -174,6 +174,25 @@ private:
|
||||||
FlyString m_identifier;
|
FlyString m_identifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PutById final : public Instruction {
|
||||||
|
public:
|
||||||
|
PutById(Register base, FlyString property, Register src)
|
||||||
|
: m_base(base)
|
||||||
|
, m_property(move(property))
|
||||||
|
, m_src(src)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~PutById() override { }
|
||||||
|
virtual void execute(Bytecode::Interpreter&) const override;
|
||||||
|
virtual String to_string() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Register m_base;
|
||||||
|
FlyString m_property;
|
||||||
|
Register m_src;
|
||||||
|
};
|
||||||
|
|
||||||
class Jump final : public Instruction {
|
class Jump final : public Instruction {
|
||||||
public:
|
public:
|
||||||
explicit Jump(Label target)
|
explicit Jump(Label target)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue