From 085c7df895a2c9b0c42a112823bb7570747f0b1e Mon Sep 17 00:00:00 2001 From: davidot Date: Wed, 28 Jul 2021 23:09:57 +0200 Subject: [PATCH] LibJS: Be more strict about the lhs of a for in/of loop This is not entirely correct as really Object- and ArrayExpressions are not allowed but that requires a bigger refactoring of for statement parsing. --- Userland/Libraries/LibJS/Parser.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index cd9949d7dd..7cc7ef11b9 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -2516,8 +2516,19 @@ NonnullRefPtr Parser::parse_for_in_of_statement(NonnullRefPtris_identifier() && !is(*lhs) && !is(*lhs) && !is(*lhs)) { + syntax_error(String::formatted("Invalid left-hand side in for-loop ('{}')", lhs->class_name())); } auto in_or_of = consume(); + + if (in_or_of.type() != TokenType::In) { + if (is(*lhs)) { + auto& member = static_cast(*lhs); + if (member.object().is_identifier() && static_cast(member.object()).string() == "let"sv) + syntax_error("For of statement may not start with let."); + } + } + auto rhs = parse_expression(0); consume(TokenType::ParenClose);