1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:07:35 +00:00

LibJS: Implement update expressions

Note that currently only the non-prefixed variant is supported (i.e i++
not ++i), this variant returns the value of the argument before the
update.
This commit is contained in:
0xtechnobabble 2020-03-12 13:45:45 +02:00 committed by Andreas Kling
parent dc9a702aa8
commit 8557bc56f7
3 changed files with 69 additions and 1 deletions

View file

@ -444,6 +444,29 @@ private:
NonnullOwnPtr<Expression> m_rhs;
};
enum class UpdateOp {
Increment,
Decrement,
};
class UpdateExpression : public Expression {
public:
UpdateExpression(UpdateOp op, NonnullOwnPtr<Expression> argument)
: m_op(op)
, m_argument(move(argument))
{
}
virtual Value execute(Interpreter&) const override;
virtual void dump(int indent) const override;
private:
virtual const char* class_name() const override { return "UpdateExpression"; }
UpdateOp m_op;
NonnullOwnPtr<Identifier> m_argument;
};
enum class DeclarationType {
Var,
Let,