Index: src/parsing/preparser.cc |
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc |
index 68372f841a7ea7811129db20ff93046c174dbbf2..2912d13ad927078ccb3d66821389d8927d4dafa7 100644 |
--- a/src/parsing/preparser.cc |
+++ b/src/parsing/preparser.cc |
@@ -67,6 +67,12 @@ PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { |
if (scanner->LiteralMatches("constructor", 11)) { |
return PreParserIdentifier::Constructor(); |
} |
+ if (scanner->LiteralMatches("async", 5)) { |
+ return PreParserIdentifier::Async(); |
+ } |
Dan Ehrenberg
2016/05/06 00:08:56
My hunch is that the parser and preparser would wo
caitp (gmail)
2016/05/06 00:31:03
Im not entirely sure this change is really needed
|
+ if (scanner->LiteralMatches("await", 5)) { |
+ return PreParserIdentifier::Await(); |
+ } |
Dan Ehrenberg
2016/05/06 00:08:56
This looks like dead code. I think this case is ha
caitp (gmail)
2016/05/06 00:31:03
yes, its no longer needed since Mikes CL, will del
|
return PreParserIdentifier::Default(); |
} |
@@ -193,6 +199,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 +412,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 +1151,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) { |