From 65343388b845bd61dd513493fbbaed1f56f10d5a Mon Sep 17 00:00:00 2001 From: 0xtechnobabble <0xtechnobabble@protonmail.com> Date: Sun, 8 Mar 2020 23:27:18 +0200 Subject: LibJS: Add new bitwise and relational operators Do note that when it comes to evaluating binary expressions, we are asserting in multiple contexts that the values we're operating on are numbers, we should probably handle other value types to be more tolerant in the future, since for example, adding a number and a string, in which case the number is converted to a string implicitly which is then concatenated, although ugly, is valid javascript. --- Libraries/LibJS/AST.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'Libraries/LibJS/AST.h') diff --git a/Libraries/LibJS/AST.h b/Libraries/LibJS/AST.h index a5ce6571cc..8d00fa15e6 100644 --- a/Libraries/LibJS/AST.h +++ b/Libraries/LibJS/AST.h @@ -176,6 +176,14 @@ enum class BinaryOp { Plus, Minus, TypedEquals, + TypedInequals, + Greater, + Smaller, + BitAnd, + BitOr, + BitXor, + BitLeftShift, + BitRightShift, }; class BinaryExpression : public Expression { @@ -231,6 +239,28 @@ private: OwnPtr m_rhs; }; +enum class UnaryOp { + BitNot, +}; + +class UnaryExpression : public Expression { +public: + UnaryExpression(UnaryOp op, NonnullOwnPtr lhs) + : m_op(op) + , m_lhs(move(lhs)) + { + } + + virtual Value execute(Interpreter&) const override; + virtual void dump(int indent) const override; + +private: + virtual const char* class_name() const override { return "UnaryExpression"; } + + UnaryOp m_op; + NonnullOwnPtr m_lhs; +}; + class Literal : public Expression { public: explicit Literal(Value value) -- cgit v1.2.3