diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-07 15:11:05 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-07 15:56:26 +0200 |
commit | 19cbfaee543ef46e660e30a7be2c0ac5b2297b66 (patch) | |
tree | 1f9237661910b6e426dfe7489123acc983004d27 | |
parent | f8942411ac68245edb8086186ccb45b91874e56b (diff) | |
download | serenity-19cbfaee543ef46e660e30a7be2c0ac5b2297b66.zip |
LibJS: Add SequenceExpression AST node (comma operator)
This patch only adds the AST node, the parser doesn't create them yet.
-rw-r--r-- | Libraries/LibJS/AST.cpp | 18 | ||||
-rw-r--r-- | Libraries/LibJS/AST.h | 16 |
2 files changed, 34 insertions, 0 deletions
diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 5f96c5f6d9..d11d6a6295 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -1133,4 +1133,22 @@ void ConditionalExpression::dump(int indent) const m_test->dump(indent + 1); } +void SequenceExpression::dump(int indent) const +{ + ASTNode::dump(indent); + for (auto& expression : m_expressions) + expression.dump(indent + 1); +} + +Value SequenceExpression::execute(Interpreter& interpreter) const +{ + Value last_value; + for (auto& expression : m_expressions) { + last_value = expression.execute(interpreter); + if (interpreter.exception()) + return {}; + } + return last_value; +} + } diff --git a/Libraries/LibJS/AST.h b/Libraries/LibJS/AST.h index 2770d9af77..1f58b4c4c0 100644 --- a/Libraries/LibJS/AST.h +++ b/Libraries/LibJS/AST.h @@ -403,6 +403,22 @@ private: NonnullRefPtr<Expression> m_lhs; }; +class SequenceExpression final : public Expression { +public: + SequenceExpression(NonnullRefPtrVector<Expression> expressions) + : m_expressions(move(expressions)) + { + } + + virtual void dump(int indent) const override; + virtual Value execute(Interpreter&) const override; + +private: + virtual const char* class_name() const override { return "SequenceExpression"; } + + NonnullRefPtrVector<Expression> m_expressions; +}; + class Literal : public Expression { protected: explicit Literal() {} |