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

Unified Diff: src/parsing/preparser.cc

Issue 1900033003: Disallow generator declarations in certain locations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 8 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 3f7adedd931c74fa475666f8ef2296ea76c4d99d..c0db7ef9dd72c0dd02e41491229bce6fdbf74e4c 100644
--- a/src/parsing/preparser.cc
+++ b/src/parsing/preparser.cc
@@ -179,7 +179,7 @@ PreParser::Statement PreParser::ParseStatementListItem(bool* ok) {
switch (peek()) {
case Token::FUNCTION:
- return ParseFunctionDeclaration(ok);
+ return ParseHoistableDeclaration(ok);
case Token::CLASS:
return ParseClassDeclaration(ok);
case Token::CONST:
@@ -378,15 +378,8 @@ PreParser::Statement PreParser::ParseSubStatement(
}
-PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
- // FunctionDeclaration ::
- // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
- // GeneratorDeclaration ::
- // 'function' '*' Identifier '(' FormalParameterListopt ')'
- // '{' FunctionBody '}'
- Expect(Token::FUNCTION, CHECK_OK);
- int pos = position();
- bool is_generator = Check(Token::MUL);
+PreParser::Statement PreParser::ParseHoistableDeclaration(
+ int pos, bool is_generator, bool* ok) {
bool is_strict_reserved = false;
Identifier name = ParseIdentifierOrStrictReservedWord(
&is_strict_reserved, CHECK_OK);
@@ -401,6 +394,19 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
}
+PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) {
+ // FunctionDeclaration ::
+ // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
+ // GeneratorDeclaration ::
+ // 'function' '*' Identifier '(' FormalParameterListopt ')'
+ // '{' FunctionBody '}'
+ Expect(Token::FUNCTION, CHECK_OK);
+ int pos = position();
+ bool is_generator = Check(Token::MUL);
+ return ParseHoistableDeclaration(pos, is_generator, CHECK_OK);
+}
+
+
PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) {
Expect(Token::CLASS, CHECK_OK);
@@ -553,6 +559,20 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
return Statement::Default();
}
+PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
+ Consume(Token::FUNCTION);
+ int pos = position();
+ bool is_generator = Check(Token::MUL);
+ if (allow_harmony_restrictive_declarations() && is_generator) {
+ PreParserTraits::ReportMessageAt(
+ scanner()->location(),
+ MessageTemplate::kGeneratorInLegacyContext);
+ *ok = false;
+ return Statement::Default();
+ }
+ return ParseHoistableDeclaration(pos, is_generator, ok);
+}
+
PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(
AllowLabelledFunctionStatement allow_function, bool* ok) {
// ExpressionStatement | LabelledStatement ::
« 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