diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2021-06-17 10:14:45 -0700 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-19 00:04:57 +0100 |
commit | 7f97e337787e4773ad4da2ae6d321afb7a277fda (patch) | |
tree | e1b35b4dfbe7c57e1527c71974357c818a45890c /Userland | |
parent | 9253fa1bad736404fd15e7cccd7c60de3c19ee73 (diff) | |
download | serenity-7f97e337787e4773ad4da2ae6d321afb7a277fda.zip |
LibJS: Disallow 'yield' identifier initializer in GeneratorFunctions
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Parser.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 482aea2c33..80ec1be7ac 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1409,8 +1409,10 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u8 parse_options) consume(TokenType::Function); if (!is_generator) { is_generator = match(TokenType::Asterisk); - if (is_generator) + if (is_generator) { consume(TokenType::Asterisk); + parse_options = parse_options | FunctionNodeParseOptions::IsGeneratorFunction; + } } if (FunctionNodeType::must_have_name() || match(TokenType::Identifier)) @@ -1499,6 +1501,10 @@ Vector<FunctionNode::Parameter> Parser::parse_formal_parameters(int& function_le has_default_parameter = true; function_length = parameters.size(); default_value = parse_expression(2); + + bool is_generator = parse_options & FunctionNodeParseOptions::IsGeneratorFunction; + if (is_generator && default_value && default_value->fast_is<Identifier>() && static_cast<Identifier&>(*default_value).string() == "yield"sv) + 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)) |