diff options
author | 0xtechnobabble <0xtechnobabble@protonmail.com> | 2020-03-08 23:27:18 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-09 19:33:07 +0100 |
commit | 65343388b845bd61dd513493fbbaed1f56f10d5a (patch) | |
tree | 4aa3e5a2a5e1ce01c6c097fe84416fe6e9e770ff /Libraries/LibJS/AST.h | |
parent | 11aac6fdceb9a3904ad3eb51d887c63a6dc91b74 (diff) | |
download | serenity-65343388b845bd61dd513493fbbaed1f56f10d5a.zip |
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.
Diffstat (limited to 'Libraries/LibJS/AST.h')
-rw-r--r-- | Libraries/LibJS/AST.h | 30 |
1 files changed, 30 insertions, 0 deletions
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<Expression> m_rhs; }; +enum class UnaryOp { + BitNot, +}; + +class UnaryExpression : public Expression { +public: + UnaryExpression(UnaryOp op, NonnullOwnPtr<Expression> 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<Expression> m_lhs; +}; + class Literal : public Expression { public: explicit Literal(Value value) |