diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-28 16:56:54 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-28 16:56:54 +0100 |
commit | a3d92b1210bad42a7563b6a7d9a8787d6d2586ed (patch) | |
tree | 81e9ccca06853492b4cc8ddd20ba85b555288b8f /Libraries/LibJS/Parser.cpp | |
parent | 37fe16a99cd9ce31d6dba0b916be67929ae010a3 (diff) | |
download | serenity-a3d92b1210bad42a7563b6a7d9a8787d6d2586ed.zip |
LibJS: Implement the "instanceof" operator
This operator walks the prototype chain of the RHS value and looks for
a "prototype" property with the same value as the prototype of the LHS.
This is pretty cool. :^)
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 4552e22cdb..9bb4001f84 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -393,6 +393,9 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre case TokenType::ExclamationMarkEquals: consume(); return create_ast_node<BinaryExpression>(BinaryOp::AbstractInequals, move(lhs), parse_expression(min_precedence, associativity)); + case TokenType::Instanceof: + consume(); + return create_ast_node<BinaryExpression>(BinaryOp::InstanceOf, move(lhs), parse_expression(min_precedence, associativity)); case TokenType::ParenOpen: return parse_call_expression(move(lhs)); case TokenType::Equals: @@ -722,7 +725,8 @@ bool Parser::match_secondary_expression() const || type == TokenType::Period || type == TokenType::BracketOpen || type == TokenType::PlusPlus - || type == TokenType::MinusMinus; + || type == TokenType::MinusMinus + || type == TokenType::Instanceof; } bool Parser::match_statement() const |