1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

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.
This commit is contained in:
Linus Groh 2022-01-15 17:10:20 +01:00
parent e730ada07d
commit f0b2179bd7

View file

@ -2612,12 +2612,16 @@ Vector<FunctionNode::Parameter> 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;
}