diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-12 21:19:48 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-13 01:15:29 +0200 |
commit | d69ed91790d3acc48f050a9e0fb991d5ab25de63 (patch) | |
tree | 3bdfb583dd928cd6a915914980c6e31167a43695 /Libraries/LibJS/Parser.cpp | |
parent | 063228c02ec0dd337cd412dad34baea93d3aca70 (diff) | |
download | serenity-d69ed91790d3acc48f050a9e0fb991d5ab25de63.zip |
LibJS: Check AssignmentExpression LHS in parser
There are many cases which shouldn't even parse, like
null = ...
true = ...
false = ...
123 = ...
"foo" = ...
However this *is* valid syntax:
foo() = ...
So we still have to keep the current code doing a runtime check if the
LHS value is a resolvable reference. I believe this was declared valid
syntax to *in theory* allow functions returning references - though in
practice that isn't a thing.
Fixes #2204.
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index d7cb24a16a..1622220c81 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -755,6 +755,10 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre return parse_call_expression(move(lhs)); case TokenType::Equals: consume(); + if (!lhs->is_identifier() && !lhs->is_member_expression() && !lhs->is_call_expression()) { + syntax_error("Invalid left-hand side in assignment"); + return create_ast_node<ErrorExpression>(); + } return create_ast_node<AssignmentExpression>(AssignmentOp::Assignment, move(lhs), parse_expression(min_precedence, associativity)); case TokenType::Period: consume(); |