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

LibJS: Implement ConditionalExpression (ternary "?:" operator)

This commit is contained in:
Andreas Kling 2020-04-03 12:14:28 +02:00
parent 522d8c5d71
commit 0622181d1f
5 changed files with 83 additions and 1 deletions

View file

@ -639,6 +639,26 @@ private:
bool m_computed { false };
};
class ConditionalExpression final : public Expression {
public:
ConditionalExpression(NonnullRefPtr<Expression> test, NonnullRefPtr<Expression> consequent, NonnullRefPtr<Expression> alternate)
: m_test(move(test))
, m_consequent(move(consequent))
, m_alternate(move(alternate))
{
}
virtual void dump(int indent) const override;
virtual Value execute(Interpreter&) const override;
private:
virtual const char* class_name() const override { return "ConditionalExpression"; }
NonnullRefPtr<Expression> m_test;
NonnullRefPtr<Expression> m_consequent;
NonnullRefPtr<Expression> m_alternate;
};
class CatchClause final : public ASTNode {
public:
CatchClause(const FlyString& parameter, NonnullRefPtr<BlockStatement> body)