diff options
author | davidot <david.tuin@gmail.com> | 2021-07-29 01:47:36 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-16 23:20:04 +0100 |
commit | f1f338edcdc98b3b8ea8f676b33d701981d6b53e (patch) | |
tree | 3ab7cbb13f6e330a5a54340bb347bb1b4a4b0467 /Userland/Libraries/LibJS | |
parent | 4989e79c456b73ee418175e288acf548082ac1bd (diff) | |
download | serenity-f1f338edcdc98b3b8ea8f676b33d701981d6b53e.zip |
LibJS: Tighten default values in formal parameter parsing
Disallow default parameter for rest parameters.
Disallow yield expressions as default values.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Parser.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 811bad23a5..80a8ef869e 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1891,6 +1891,10 @@ Vector<FunctionNode::Parameter> Parser::parse_formal_parameters(int& function_le RefPtr<Expression> default_value; if (match(TokenType::Equals)) { consume(); + + if (is_rest) + syntax_error("Rest parameter may not have a default initializer"); + TemporaryChange change(m_state.in_function_context, true); has_default_parameter = true; function_length = parameters.size(); @@ -1899,6 +1903,8 @@ Vector<FunctionNode::Parameter> Parser::parse_formal_parameters(int& function_le bool is_generator = parse_options & FunctionNodeParseOptions::IsGeneratorFunction; if ((is_generator || m_state.strict_mode) && 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\""); + if (default_value && is<YieldExpression>(*default_value)) + syntax_error("Yield expression not allowed in formal parameter"); } parameters.append({ move(parameter), default_value, is_rest }); if (match(TokenType::ParenClose)) |