Chromium Code Reviews| Index: src/parsing/parser.cc |
| diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc |
| index e2e8f92ad9f922a5838b96ddea114da2c24e5c79..c3e43e11f1835f64ea987e594187ce23363c57f1 100644 |
| --- a/src/parsing/parser.cc |
| +++ b/src/parsing/parser.cc |
| @@ -1248,7 +1248,7 @@ Statement* Parser::ParseStatementListItem(bool* ok) { |
| switch (peek()) { |
| case Token::FUNCTION: |
| - return ParseFunctionDeclaration(NULL, ok); |
| + return ParseHoistableDeclaration(NULL, ok); |
| case Token::CLASS: |
| Consume(Token::CLASS); |
| return ParseClassDeclaration(NULL, ok); |
| @@ -1550,7 +1550,7 @@ Statement* Parser::ParseExportDefault(bool* ok) { |
| pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); |
| result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
| } else { |
| - result = ParseFunctionDeclaration(pos, is_generator, &names, CHECK_OK); |
| + result = ParseHoistableDeclaration(pos, is_generator, &names, CHECK_OK); |
| } |
| break; |
| } |
| @@ -1679,7 +1679,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { |
| } |
| case Token::FUNCTION: |
| - result = ParseFunctionDeclaration(&names, CHECK_OK); |
| + result = ParseHoistableDeclaration(&names, CHECK_OK); |
| break; |
| case Token::CLASS: |
| @@ -2048,16 +2048,16 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { |
| } |
| -Statement* Parser::ParseFunctionDeclaration( |
| +Statement* Parser::ParseHoistableDeclaration( |
| ZoneList<const AstRawString*>* names, bool* ok) { |
| Expect(Token::FUNCTION, CHECK_OK); |
| int pos = position(); |
| bool is_generator = Check(Token::MUL); |
| - return ParseFunctionDeclaration(pos, is_generator, names, ok); |
| + return ParseHoistableDeclaration(pos, is_generator, names, ok); |
| } |
| -Statement* Parser::ParseFunctionDeclaration( |
| +Statement* Parser::ParseHoistableDeclaration( |
| int pos, bool is_generator, ZoneList<const AstRawString*>* names, |
| bool* ok) { |
| // FunctionDeclaration :: |
| @@ -2387,6 +2387,20 @@ static bool ContainsLabel(ZoneList<const AstRawString*>* labels, |
| return false; |
| } |
| +Statement* Parser::ParseHoistableDeclaration(bool* ok) { |
|
adamk
2016/04/26 23:55:57
I was suggesting that this should be called ParseF
Dan Ehrenberg
2016/04/27 00:18:10
No, you were clear; overzealous find/replace. Fixe
|
| + Consume(Token::FUNCTION); |
| + int pos = position(); |
| + bool is_generator = Check(Token::MUL); |
| + if (allow_harmony_restrictive_declarations() && is_generator) { |
| + ParserTraits::ReportMessageAt( |
| + scanner()->location(), |
| + MessageTemplate::kGeneratorInLegacyContext); |
| + *ok = false; |
| + return nullptr; |
| + } |
| + return ParseHoistableDeclaration(pos, is_generator, nullptr, CHECK_OK); |
| +} |
| + |
| Statement* Parser::ParseExpressionOrLabelledStatement( |
| ZoneList<const AstRawString*>* labels, |
| AllowLabelledFunctionStatement allow_function, bool* ok) { |
| @@ -2443,7 +2457,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement( |
| // ES#sec-labelled-function-declarations Labelled Function Declarations |
| if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { |
| if (allow_function == kAllowLabelledFunctionStatement) { |
| - return ParseFunctionDeclaration(labels, ok); |
| + return ParseHoistableDeclaration(ok); |
| } else { |
| return ParseScopedStatement(labels, true, ok); |
| } |
| @@ -3437,7 +3451,7 @@ Statement* Parser::ParseScopedStatement(ZoneList<const AstRawString*>* labels, |
| Scope* body_scope = NewScope(scope_, BLOCK_SCOPE); |
| BlockState block_state(&scope_, body_scope); |
| Block* block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); |
| - Statement* body = ParseFunctionDeclaration(NULL, CHECK_OK); |
| + Statement* body = ParseHoistableDeclaration(CHECK_OK); |
| block->statements()->Add(body, zone()); |
| body_scope->set_end_position(scanner()->location().end_pos); |
| body_scope = body_scope->FinalizeBlockScope(); |