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 :: |