mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +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:
parent
dc9a702aa8
commit
8557bc56f7
Notes:
sideshowbarker
2024-07-19 08:20:54 +09:00
Author: https://github.com/0xtechnobabble
Commit: 8557bc56f7
Pull-request: https://github.com/SerenityOS/serenity/pull/1427
Reviewed-by: https://github.com/awesomekling ✅
3 changed files with 69 additions and 1 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue