mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +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
Notes:
sideshowbarker
2024-07-18 12:42:18 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/14cfc448551
3 changed files with 44 additions and 0 deletions
|
@ -90,6 +90,20 @@ Optional<Bytecode::Register> AssignmentExpression::generate_bytecode(Bytecode::G
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,12 @@ void SetVariable::execute(Bytecode::Interpreter& interpreter) const
|
|||
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
|
||||
{
|
||||
interpreter.jump(m_target);
|
||||
|
@ -122,6 +128,11 @@ String SetVariable::to_string() const
|
|||
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
|
||||
{
|
||||
return String::formatted("Jump {}", m_target);
|
||||
|
|
|
@ -174,6 +174,25 @@ private:
|
|||
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 {
|
||||
public:
|
||||
explicit Jump(Label target)
|
||||
|
|
Loading…
Reference in a new issue