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

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: Fix style 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
« no previous file with comments | « src/parsing/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/preparser.cc
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc
index 5cfa8bd5e80a4f136ab7a0acfc40db7f3a74c2d5..613651a3b1aa8197d128e19fbc442df4b5ab713c 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,8 @@ 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_function, bool* ok) {
// Statement ::
// EmptyStatement
// ...
@@ -273,19 +273,20 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) {
Next();
return Statement::Default();
}
- return ParseSubStatement(ok);
+ return ParseSubStatement(allow_function, 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_function, bool* ok) {
// Statement ::
// Block
// VariableStatement
@@ -372,7 +373,7 @@ PreParser::Statement PreParser::ParseSubStatement(bool* ok) {
return ParseVariableStatement(kStatement, ok);
default:
- return ParseExpressionOrLabelledStatement(ok);
+ return ParseExpressionOrLabelledStatement(allow_function, ok);
}
}
@@ -555,8 +556,8 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
return Statement::Default();
}
-
-PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
+PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(
+ AllowLabelledFunctionStatement allow_function, bool* ok) {
// ExpressionStatement | LabelledStatement ::
// Expression ';'
// Identifier ':' Statement
@@ -591,9 +592,14 @@ 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_function == 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
« no previous file with comments | « src/parsing/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698