Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(830)

Unified Diff: src/parsing/preparser.cc

Issue 1841543003: [esnext] implement frontend changes for async/await proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: A bunch more tests, some fixes, ExpressionClassifier gets fatter :( Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698