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

Unified Diff: runtime/vm/scopes.cc

Issue 1314993002: Use correct scope to lookup saved async context variable. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/scopes.cc
diff --git a/runtime/vm/scopes.cc b/runtime/vm/scopes.cc
index a06bca391bb114d8fa048e942a5281758d8e7c36..e11fc166824a221e77870d896328f312cb0eb0ab 100644
--- a/runtime/vm/scopes.cc
+++ b/runtime/vm/scopes.cc
@@ -432,12 +432,19 @@ bool LocalScope::CaptureVariable(const String& name) {
LocalVariable* var = current_scope->LocalLookupVariable(name);
if (var != NULL) {
var->set_is_captured();
- // Insert aliases of the variable in intermediate scopes.
- LocalScope* intermediate_scope = this;
- while (intermediate_scope != current_scope) {
- intermediate_scope->variables_.Add(var);
- ASSERT(var->owner() != intermediate_scope); // Item is an alias.
- intermediate_scope = intermediate_scope->parent();
+ LocalScope* scope = this;
+ while (var->owner()->function_level() != scope->function_level()) {
+ // Insert an alias of the variable in the top scope of each function
+ // level so that the variable is found in the context.
+ LocalScope* parent_scope = scope->parent();
+ while ((parent_scope != NULL) &&
+ (parent_scope->function_level() == scope->function_level())) {
+ scope = parent_scope;
+ parent_scope = scope->parent();
+ }
+ scope->variables_.Add(var);
+ ASSERT(var->owner() != scope); // Item is an alias.
+ scope = parent_scope;
}
return true;
}
« no previous file with comments | « runtime/vm/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698