mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 01:12:44 +00:00 
			
		
		
		
	LibJS: Add SequenceExpression AST node (comma operator)
This patch only adds the AST node, the parser doesn't create them yet.
This commit is contained in:
		
							parent
							
								
									f8942411ac
								
							
						
					
					
						commit
						19cbfaee54
					
				
					 2 changed files with 34 additions and 0 deletions
				
			
		|  | @ -1133,4 +1133,22 @@ void ConditionalExpression::dump(int indent) const | ||||||
|     m_test->dump(indent + 1); |     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; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -403,6 +403,22 @@ private: | ||||||
|     NonnullRefPtr<Expression> m_lhs; |     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 { | class Literal : public Expression { | ||||||
| protected: | protected: | ||||||
|     explicit Literal() {} |     explicit Literal() {} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling