Commit f43e8845 authored by Suraj Sharma's avatar Suraj Sharma Committed by Commit Bot

[parser] Improve parse error message for missing name in FunctionDeclaration

Added a new Error Message for Missing Function Name.

The program:

function(){}

...now produces:
	SyntaxError: Function statements require a valid function name.

...instead of:
	SyntaxError: Unexpected Token (

Bug: v8:3698, v8:6513
Change-Id: I3c12dfcfe80b94209aa9af434ae1d212970cf362
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1500914
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60376}
parent d54644de
......@@ -417,6 +417,7 @@ namespace internal {
T(MalformedRegExp, "Invalid regular expression: /%/: %") \
T(MalformedRegExpFlags, "Invalid regular expression flags") \
T(ModuleExportUndefined, "Export '%' is not defined in module") \
T(MissingFunctionName, "Function statements require a function name") \
T(HtmlCommentInModule, "HTML comments are not allowed in modules") \
T(MultipleDefaultsInSwitch, \
"More than one default clause in switch statement") \
......
......@@ -3737,9 +3737,14 @@ ParserBase<Impl>::ParseHoistableDeclaration(
IdentifierT name;
FunctionNameValidity name_validity;
IdentifierT variable_name;
if (default_export && peek() == Token::LPAREN) {
impl()->GetDefaultStrings(&name, &variable_name);
name_validity = kSkipFunctionNameCheck;
if (peek() == Token::LPAREN) {
if (default_export) {
impl()->GetDefaultStrings(&name, &variable_name);
name_validity = kSkipFunctionNameCheck;
} else {
ReportMessage(MessageTemplate::kMissingFunctionName);
return impl()->NullStatement();
}
} else {
bool is_strict_reserved = Token::IsStrictReservedWord(peek());
name = ParseIdentifier();
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function (){}
*%(basename)s:5: SyntaxError: Function statements require a function name
function (){}
^^^^^^^^
SyntaxError: Function statements require a function name
......@@ -28,7 +28,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS eval('function f(){return true;}') is undefined.
PASS eval('function f(){return true;};f')() is true
PASS eval('function(){return false;}')() threw exception SyntaxError: Unexpected token (.
PASS eval('function(){return false;}')() threw exception SyntaxError: Function statements require a function name.
PASS successfullyParsed is true
TEST COMPLETE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment