Chromium Code Reviews| Index: src/parsing/parser.cc |
| diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc |
| index b63459e1556cf4d9a6afe4b7451d3a778ad20d3c..b0f6fd9bf03273feca7e6c6a2b0da4a6df4b73e1 100644 |
| --- a/src/parsing/parser.cc |
| +++ b/src/parsing/parser.cc |
| @@ -1275,6 +1275,7 @@ Statement* Parser::ParseStatementListItem(bool* ok) { |
| scope_->set_class_declaration_group_start( |
| scanner()->peek_location().beg_pos); |
| } |
| + Consume(Token::CLASS); |
| return ParseClassDeclaration(NULL, ok); |
| case Token::CONST: |
| if (allow_const()) { |
| @@ -1560,16 +1561,43 @@ Statement* Parser::ParseExportDefault(bool* ok) { |
| Scanner::Location default_loc = scanner()->location(); |
| ZoneList<const AstRawString*> names(1, zone()); |
| - Statement* result = NULL; |
| + Statement* result = nullptr; |
| + Expression* default_export = nullptr; |
| switch (peek()) { |
| - case Token::FUNCTION: |
| - // TODO(ES6): Support parsing anonymous function declarations here. |
| - result = ParseFunctionDeclaration(&names, CHECK_OK); |
| + case Token::FUNCTION: { |
| + Consume(Token::FUNCTION); |
| + int pos = position(); |
| + bool is_generator = Check(Token::MUL); |
| + if (peek() == Token::LPAREN) { |
| + // FunctionDeclaration[+Default] :: |
| + // 'function' '(' FormalParameters ')' '{' FunctionBody '}' |
| + // |
| + // GeneratorDeclaration[+Default] :: |
| + // 'function' '*' '(' FormalParameters ')' '{' FunctionBody '}' |
| + default_export = ParseFunctionLiteral( |
|
caitp (gmail)
2016/01/14 23:12:53
per 14.1.20, you probably want the SetFunctionName
adamk
2016/01/15 00:06:29
Done.
|
| + nullptr, scanner()->location(), kSkipFunctionNameCheck, |
| + is_generator ? FunctionKind::kGeneratorFunction |
| + : FunctionKind::kNormalFunction, |
| + pos, FunctionLiteral::kDeclaration, FunctionLiteral::kNormalArity, |
| + language_mode(), CHECK_OK); |
| + result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
| + } else { |
| + result = ParseFunctionDeclaration(pos, is_generator, &names, CHECK_OK); |
| + } |
| break; |
| + } |
| case Token::CLASS: |
| - // TODO(ES6): Support parsing anonymous class declarations here. |
| - result = ParseClassDeclaration(&names, CHECK_OK); |
| + Consume(Token::CLASS); |
| + if (peek() == Token::EXTENDS || peek() == Token::LBRACE) { |
| + // ClassDeclaration[+Default] :: |
| + // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}' |
| + default_export = ParseClassLiteral( |
|
caitp (gmail)
2016/01/14 23:12:53
here too, per 15.2.3.11
adamk
2016/01/15 00:06:29
Done.
|
| + nullptr, Scanner::Location::invalid(), false, position(), CHECK_OK); |
| + result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
| + } else { |
| + result = ParseClassDeclaration(&names, CHECK_OK); |
| + } |
| break; |
| default: { |
| @@ -1592,11 +1620,12 @@ Statement* Parser::ParseExportDefault(bool* ok) { |
| if (!*ok) { |
| ParserTraits::ReportMessageAt( |
| default_loc, MessageTemplate::kDuplicateExport, default_string); |
| - return NULL; |
| + return nullptr; |
| } |
| } else { |
| // TODO(ES6): Assign result to a const binding with the name "*default*" |
| // and add an export entry with "*default*" as the local name. |
| + USE(default_export); |
| } |
| return result; |
| @@ -1687,6 +1716,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { |
| break; |
| case Token::CLASS: |
| + Consume(Token::CLASS); |
| result = ParseClassDeclaration(&names, CHECK_OK); |
| break; |
| @@ -2090,14 +2120,22 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { |
| Statement* Parser::ParseFunctionDeclaration( |
| ZoneList<const AstRawString*>* names, 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 ParseFunctionDeclaration(pos, is_generator, names, ok); |
| +} |
| + |
| + |
| +Statement* Parser::ParseFunctionDeclaration( |
| + int pos, bool is_generator, ZoneList<const AstRawString*>* names, |
| + bool* ok) { |
| + // FunctionDeclaration :: |
| + // 'function' Identifier '(' FormalParameters ')' '{' FunctionBody '}' |
| + // GeneratorDeclaration :: |
| + // 'function' '*' Identifier '(' FormalParameters ')' '{' FunctionBody '}' |
| + // |
| + // 'function' and '*' (if present) have been consumed by the caller. |
| bool is_strict_reserved = false; |
| const AstRawString* name = ParseIdentifierOrStrictReservedWord( |
| &is_strict_reserved, CHECK_OK); |
| @@ -2148,6 +2186,8 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| // ClassDeclaration :: |
| // 'class' Identifier ('extends' LeftHandExpression)? '{' ClassBody '}' |
| // |
| + // 'class' is expected to be consumed by the caller. |
| + // |
| // A ClassDeclaration |
| // |
| // class C { ... } |
| @@ -2158,7 +2198,6 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| // |
| // so rewrite it as such. |
| - Expect(Token::CLASS, CHECK_OK); |
| if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
| ReportMessage(MessageTemplate::kSloppyLexical); |
| *ok = false; |