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

Unified Diff: runtime/vm/parser.cc

Issue 508643004: Fix scope/context behavior in await transformer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: addressed comments Created 6 years, 4 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
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index e2100454593513ff88c3821fd0702b90c74342f6..dbf903f6aee643c6d249a35cf6d36ac697050c75 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -286,6 +286,7 @@ Parser::Parser(const Script& script, const Library& library, intptr_t token_pos)
token_kind_(Token::kILLEGAL),
current_block_(NULL),
is_top_level_(false),
+ await_is_keyword_(false),
current_member_(NULL),
allow_function_literals_(true),
parsed_function_(NULL),
@@ -312,6 +313,7 @@ Parser::Parser(const Script& script,
token_kind_(Token::kILLEGAL),
current_block_(NULL),
is_top_level_(false),
+ await_is_keyword_(false),
current_member_(NULL),
allow_function_literals_(true),
parsed_function_(parsed_function),
@@ -3053,6 +3055,11 @@ SequenceNode* Parser::ParseFunc(const Function& func,
OpenAsyncClosure();
}
+ // For async functions and their inner closures parse "await" as a keyword.
+ if (func.IsAsyncFunction() || func.is_async_closure()) {
+ await_is_keyword_ = true;
+ }
+
intptr_t end_token_pos = 0;
if (CurrentToken() == Token::kLBRACE) {
ConsumeToken();
@@ -3121,6 +3128,7 @@ SequenceNode* Parser::ParseFunc(const Function& func,
current_block_->statements->Add(body);
innermost_function_ = saved_innermost_function.raw();
last_used_try_index_ = saved_try_index;
+ await_is_keyword_ = false;
return CloseBlock();
}
@@ -6351,9 +6359,14 @@ bool Parser::IsSimpleLiteral(const AbstractType& type, Instance* value) {
}
-// Returns true if the current token is kIDENT or a pseudo-keyword.
+// Returns true if the current token is
+// * kIDENT,
+// * or a pseudo-keyword,
+// * or is not the literal "await" in an async function.
bool Parser::IsIdentifier() {
- return Token::IsIdentifier(CurrentToken());
+ return Token::IsIdentifier(CurrentToken()) &&
+ (!await_is_keyword_ ||
+ (CurrentLiteral()->raw() != Symbols::Await().raw()));
}
@@ -8550,11 +8563,12 @@ AstNode* Parser::ParseAwaitableExpr(bool require_compiletime_const,
// function.
return expr;
}
- SequenceNode* intermediates_block = new(I) SequenceNode(
- Scanner::kNoSourcePos, current_block_->scope);
- AwaitTransformer at(intermediates_block, library_, parsed_function());
+ OpenBlock();
+ AwaitTransformer at(current_block_->statements,
+ library_,
+ parsed_function());
AstNode* result = at.Transform(expr);
- current_block_->statements->Add(intermediates_block);
+ current_block_->statements->Add(CloseBlock());
parsed_function()->reset_have_seen_await();
return result;
}
@@ -10939,7 +10953,7 @@ AstNode* Parser::ParsePrimary() {
OpenBlock();
primary = ParseFunctionStatement(true);
CloseBlock();
- } else if (IsLiteral("await") &&
+ } else if ((CurrentLiteral()->raw() == Symbols::Await().raw()) &&
(parsed_function()->function().IsAsyncFunction() ||
parsed_function()->function().is_async_closure())) {
// The body of an async function is parsed multiple times. The first time
« no previous file with comments | « runtime/vm/parser.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698