mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 03:08:13 +00:00
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.
This commit is contained in:
parent
11aac6fdce
commit
65343388b8
2 changed files with 152 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue