Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Unified Diff: src/parsing/preparser.cc

Issue 1808373003: Implement ES2015 labelled function declaration restrictions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/parsing/preparser.cc
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc
index df97c4dbd71234f6b618ea2735f993b806525baa..46258aea165d3aa0534f47422e935189916f2912 100644
--- a/src/parsing/preparser.cc
+++ b/src/parsing/preparser.cc
@@ -194,7 +194,7 @@ PreParser::Statement PreParser::ParseStatementListItem(bool* ok) {
default:
break;
}
- return ParseStatement(ok);
+ return ParseStatement(kAllowLabelledFunctionStatement, ok);
}
@@ -263,8 +263,9 @@ void PreParser::ParseStatementList(int end_token, bool* ok,
#define DUMMY ) // to make indentation work
#undef DUMMY
-
-PreParser::Statement PreParser::ParseStatement(bool* ok) {
+PreParser::Statement PreParser::ParseStatement(
+ AllowLabelledFunctionStatement allow_labelled_function_statement,
+ bool* ok) {
// Statement ::
// EmptyStatement
// ...
@@ -273,19 +274,21 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) {
Next();
return Statement::Default();
}
- return ParseSubStatement(ok);
+ return ParseSubStatement(allow_labelled_function_statement, ok);
}
PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) {
if (is_strict(language_mode()) || peek() != Token::FUNCTION ||
(legacy && allow_harmony_restrictive_declarations())) {
- return ParseSubStatement(ok);
+ return ParseSubStatement(kDisallowLabelledFunctionStatement, ok);
} else {
return ParseFunctionDeclaration(CHECK_OK);
}
}
-PreParser::Statement PreParser::ParseSubStatement(bool* ok) {
+PreParser::Statement PreParser::ParseSubStatement(
+ AllowLabelledFunctionStatement allow_labelled_function_statement,
+ bool* ok) {
// Statement ::
// Block
// VariableStatement
@@ -381,7 +384,8 @@ PreParser::Statement PreParser::ParseSubStatement(bool* ok) {
// Fall through.
default:
- return ParseExpressionOrLabelledStatement(ok);
+ return ParseExpressionOrLabelledStatement(
+ allow_labelled_function_statement, ok);
}
}
@@ -565,8 +569,9 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
return Statement::Default();
}
-
-PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
+PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(
+ AllowLabelledFunctionStatement allow_labelled_function_statement,
+ bool* ok) {
// ExpressionStatement | LabelledStatement ::
// Expression ';'
// Identifier ':' Statement
@@ -601,9 +606,15 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
Consume(Token::COLON);
// ES#sec-labelled-function-declarations Labelled Function Declarations
if (peek() == Token::FUNCTION && is_sloppy(language_mode())) {
- return ParseFunctionDeclaration(ok);
+ if (allow_labelled_function_statement ==
+ kAllowLabelledFunctionStatement) {
+ return ParseFunctionDeclaration(ok);
+ } else {
+ return ParseScopedStatement(true, ok);
+ }
}
- Statement statement = ParseStatement(ok);
+ Statement statement =
+ ParseStatement(kDisallowLabelledFunctionStatement, ok);
return statement.IsJumpStatement() ? Statement::Default() : statement;
// Preparsing is disabled for extensions (because the extension details
// aren't passed to lazily compiled functions), so we don't

Powered by Google App Engine
This is Rietveld 408576698