Index: src/parsing/preparser.cc |
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc |
index 5bf5eb423200e80099d055dc5fd765a7f7698b16..b09488715464d470988788edc0d7ffde93a49509 100644 |
--- a/src/parsing/preparser.cc |
+++ b/src/parsing/preparser.cc |
@@ -193,6 +193,15 @@ PreParser::Statement PreParser::ParseStatementListItem(bool* ok) { |
return ParseVariableStatement(kStatementListItem, ok); |
} |
break; |
+ case Token::IDENTIFIER: |
+ if (allow_harmony_async_await() && |
+ PeekContextualKeyword(CStrVector("async")) && |
+ PeekAhead() == Token::FUNCTION && |
+ !scanner()->HasAnyLineTerminatorAfterNext()) { |
+ Consume(Token::IDENTIFIER); |
+ return ParseAsyncFunctionDeclaration(ok); |
+ } |
+ /* falls through */ |
default: |
break; |
} |
@@ -397,6 +406,31 @@ PreParser::Statement PreParser::ParseHoistableDeclaration( |
return Statement::FunctionDeclaration(); |
} |
+PreParser::Statement PreParser::ParseAsyncFunctionDeclaration(bool* ok) { |
+ // AsyncFunctionDeclaration :: |
+ // async [no LineTerminator here] function BindingIdentifier[Await] |
+ // ( FormalParameters[Await] ) { AsyncFunctionBody } |
+ DCHECK_EQ(scanner()->current_token(), Token::IDENTIFIER); |
+ DCHECK(scanner()->is_literal_contextual_keyword(CStrVector("async"))); |
+ int pos = position(); |
+ Expect(Token::FUNCTION, CHECK_OK); |
+ bool is_strict_reserved = false; |
+ Identifier name = |
+ ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
+ if (V8_UNLIKELY(is_async_function() && this->IsAwait(name))) { |
+ ReportMessageAt(scanner()->location(), |
+ MessageTemplate::kAwaitBindingIdentifier); |
+ *ok = false; |
+ return Statement::Default(); |
+ } |
+ ParseFunctionLiteral(name, scanner()->location(), |
+ is_strict_reserved ? kFunctionNameIsStrictReserved |
+ : kFunctionNameValidityUnknown, |
+ FunctionKind::kAsyncFunction, pos, |
+ FunctionLiteral::kDeclaration, language_mode(), |
+ CHECK_OK); |
+ return Statement::FunctionDeclaration(); |
+} |
PreParser::Statement PreParser::ParseHoistableDeclaration(bool* ok) { |
// FunctionDeclaration :: |
@@ -1111,6 +1145,37 @@ PreParser::Expression PreParser::ParseFunctionLiteral( |
return Expression::Default(); |
} |
+PreParser::Expression PreParser::ParseAsyncFunctionExpression(bool* ok) { |
+ // AsyncFunctionDeclaration :: |
+ // async [no LineTerminator here] function ( FormalParameters[Await] ) |
+ // { AsyncFunctionBody } |
+ // |
+ // async [no LineTerminator here] function BindingIdentifier[Await] |
+ // ( FormalParameters[Await] ) { AsyncFunctionBody } |
+ int pos = position(); |
+ Expect(Token::FUNCTION, CHECK_OK); |
+ bool is_strict_reserved = false; |
+ Identifier name; |
+ FunctionLiteral::FunctionType type = FunctionLiteral::kAnonymousExpression; |
+ |
+ if (peek_any_identifier()) { |
+ type = FunctionLiteral::kNamedExpression; |
+ name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
+ if (this->IsAwait(name)) { |
+ ReportMessageAt(scanner()->location(), |
+ MessageTemplate::kAwaitBindingIdentifier); |
+ *ok = false; |
+ return Expression::Default(); |
+ } |
+ } |
+ |
+ ParseFunctionLiteral(name, scanner()->location(), |
+ is_strict_reserved ? kFunctionNameIsStrictReserved |
+ : kFunctionNameValidityUnknown, |
+ FunctionKind::kAsyncFunction, pos, type, language_mode(), |
+ CHECK_OK); |
+ return Expression::Default(); |
+} |
void PreParser::ParseLazyFunctionLiteralBody(bool* ok, |
Scanner::BookmarkScope* bookmark) { |
@@ -1172,12 +1237,11 @@ PreParserExpression PreParser::ParseClassLiteral( |
while (peek() != Token::RBRACE) { |
if (Check(Token::SEMICOLON)) continue; |
const bool in_class = true; |
- const bool is_static = false; |
bool is_computed_name = false; // Classes do not care about computed |
// property names here. |
Identifier name; |
ExpressionClassifier property_classifier(this); |
- ParsePropertyDefinition(&checker, in_class, has_extends, is_static, |
+ ParsePropertyDefinition(&checker, in_class, has_extends, MethodKind::None, |
&is_computed_name, &has_seen_constructor, |
&property_classifier, &name, CHECK_OK); |
ValidateExpression(&property_classifier, CHECK_OK); |