From f1f338edcdc98b3b8ea8f676b33d701981d6b53e Mon Sep 17 00:00:00 2001 From: davidot Date: Thu, 29 Jul 2021 01:47:36 +0200 Subject: LibJS: Tighten default values in formal parameter parsing Disallow default parameter for rest parameters. Disallow yield expressions as default values. --- Userland/Libraries/LibJS/Parser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Userland/Libraries') 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 Parser::parse_formal_parameters(int& function_le RefPtr 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 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() && static_cast(*default_value).string() == "yield"sv) syntax_error("Generator function parameter initializer cannot contain a reference to an identifier named \"yield\""); + if (default_value && is(*default_value)) + syntax_error("Yield expression not allowed in formal parameter"); } parameters.append({ move(parameter), default_value, is_rest }); if (match(TokenType::ParenClose)) -- cgit v1.2.3