summaryrefslogtreecommitdiff
path: root/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-09-16 20:03:06 +0100
committerAndreas Kling <kling@serenityos.org>2020-09-18 20:49:35 +0200
commit5fd87ccd169f5ed0d047f89744740e3fc0aed4eb (patch)
treecce2f7fb118b78a558174605fdb0ffe8deb51df4 /Libraries/LibJS
parentfd32f00839f064d2aad2ba53dd66ea4e3d6a2eff (diff)
downloadserenity-5fd87ccd169f5ed0d047f89744740e3fc0aed4eb.zip
LibJS: Add FIXMEs for parsing increment operators with function LHS/RHS
The parser considers it a syntax error at the moment, other engines throw a ReferenceError during runtime for ++foo(), --foo(), foo()++ and foo()--, so I assume the spec defines this.
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r--Libraries/LibJS/Parser.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp
index c8b70a874e..3448a197b5 100644
--- a/Libraries/LibJS/Parser.cpp
+++ b/Libraries/LibJS/Parser.cpp
@@ -653,6 +653,8 @@ NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()
auto rhs_start_line = m_parser_state.m_current_token.line_number();
auto rhs_start_column = m_parser_state.m_current_token.line_column();
auto rhs = parse_expression(precedence, associativity);
+ // FIXME: Apparently for functions this should also not be enforced on a parser level,
+ // other engines throw ReferenceError for ++foo()
if (!rhs->is_identifier() && !rhs->is_member_expression())
syntax_error(String::format("Right-hand side of prefix increment operator must be identifier or member expression, got %s", rhs->class_name()), rhs_start_line, rhs_start_column);
return create_ast_node<UpdateExpression>(UpdateOp::Increment, move(rhs), true);
@@ -662,6 +664,8 @@ NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()
auto rhs_start_line = m_parser_state.m_current_token.line_number();
auto rhs_start_column = m_parser_state.m_current_token.line_column();
auto rhs = parse_expression(precedence, associativity);
+ // FIXME: Apparently for functions this should also not be enforced on a parser level,
+ // other engines throw ReferenceError for --foo()
if (!rhs->is_identifier() && !rhs->is_member_expression())
syntax_error(String::format("Right-hand side of prefix decrement operator must be identifier or member expression, got %s", rhs->class_name()), rhs_start_line, rhs_start_column);
return create_ast_node<UpdateExpression>(UpdateOp::Decrement, move(rhs), true);
@@ -1096,11 +1100,15 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre
return expression;
}
case TokenType::PlusPlus:
+ // FIXME: Apparently for functions this should also not be enforced on a parser level,
+ // other engines throw ReferenceError for foo()++
if (!lhs->is_identifier() && !lhs->is_member_expression())
syntax_error(String::format("Left-hand side of postfix increment operator must be identifier or member expression, got %s", lhs->class_name()));
consume();
return create_ast_node<UpdateExpression>(UpdateOp::Increment, move(lhs));
case TokenType::MinusMinus:
+ // FIXME: Apparently for functions this should also not be enforced on a parser level,
+ // other engines throw ReferenceError for foo()--
if (!lhs->is_identifier() && !lhs->is_member_expression())
syntax_error(String::format("Left-hand side of postfix increment operator must be identifier or member expression, got %s", lhs->class_name()));
consume();