From f0b2179bd79c4cd952ccad81e571307a6606b84e Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 15 Jan 2022 17:10:20 +0100 Subject: [PATCH] LibJS: Don't require ParenClose in Parser::parse_formal_parameters() The parentheses are dealt with outside this function, so we shouldn't use the (non)existence of one as the condition for consuming another comma and then parameter. Just check for a comma instead. This becomes relevant when parsing standalone function parameters as per the spec in the CreateDynamicFunction AO. --- Userland/Libraries/LibJS/Parser.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 2908258289..a30f7fd473 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -2612,12 +2612,16 @@ Vector Parser::parse_formal_parameters(int& function_le syntax_error("Generator function parameter initializer cannot contain a reference to an identifier named \"yield\""); } parameters.append({ move(parameter), default_value, is_rest }); - if (match(TokenType::ParenClose) || is_rest) + if (!match(TokenType::Comma) || is_rest) break; consume(TokenType::Comma); } if (parse_options & FunctionNodeParseOptions::IsSetterFunction && parameters.is_empty()) syntax_error("Setter function must have one argument"); + // If we're parsing the parameters standalone, e.g. via CreateDynamicFunction, we must have reached EOF here. + // Otherwise, we need a closing parenthesis (which is consumed elsewhere). If we get neither, it's an error. + if (!match(TokenType::Eof) && !match(TokenType::ParenClose)) + expected(Token::name(TokenType::ParenClose)); return parameters; }