1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:28:11 +00:00

LibJS: Implement parsing and evaluation for AssignmentPatterns

e.g. `[...foo] = bar` can now be evaluated :^)
This commit is contained in:
Ali Mohammad Pur 2021-07-11 01:16:17 +04:30 committed by Linus Groh
parent 7fc6cd6b20
commit 1a9518ebe3
7 changed files with 104 additions and 40 deletions

View file

@ -272,8 +272,10 @@ void Identifier::generate_bytecode(Bytecode::Generator& generator) const
void AssignmentExpression::generate_bytecode(Bytecode::Generator& generator) const
{
if (is<Identifier>(*m_lhs)) {
auto& identifier = static_cast<Identifier const&>(*m_lhs);
// FIXME: Implement this for BindingPatterns too.
auto& lhs = m_lhs.get<NonnullRefPtr<Expression>>();
if (is<Identifier>(*lhs)) {
auto& identifier = static_cast<Identifier const&>(*lhs);
if (m_op == AssignmentOp::Assignment) {
m_rhs->generate_bytecode(generator);
@ -281,7 +283,7 @@ void AssignmentExpression::generate_bytecode(Bytecode::Generator& generator) con
return;
}
m_lhs->generate_bytecode(generator);
lhs->generate_bytecode(generator);
Bytecode::BasicBlock* rhs_block_ptr { nullptr };
Bytecode::BasicBlock* end_block_ptr { nullptr };
@ -377,8 +379,8 @@ void AssignmentExpression::generate_bytecode(Bytecode::Generator& generator) con
return;
}
if (is<MemberExpression>(*m_lhs)) {
auto& expression = static_cast<MemberExpression const&>(*m_lhs);
if (is<MemberExpression>(*lhs)) {
auto& expression = static_cast<MemberExpression const&>(*lhs);
expression.object().generate_bytecode(generator);
auto object_reg = generator.allocate_register();
generator.emit<Bytecode::Op::Store>(object_reg);