summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-01-15 17:10:20 +0100
committerLinus Groh <mail@linusgroh.de>2022-01-16 01:54:48 +0100
commitf0b2179bd79c4cd952ccad81e571307a6606b84e (patch)
tree34710602a459e79d85dc529d510d72da388b016f
parente730ada07d6b68fdc4e76f1e9028a06f0c8f3c40 (diff)
downloadserenity-f0b2179bd79c4cd952ccad81e571307a6606b84e.zip
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.
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp6
1 files changed, 5 insertions, 1 deletions
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<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;
}