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

Unified Diff: pkg/kernel/lib/transformations/closure/info.dart

Issue 2939043002: Remove unnecessary contexts in closure conversion (Closed)
Patch Set: Don't treat constructor parameters in initializers as captured Created 3 years, 6 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: pkg/kernel/lib/transformations/closure/info.dart
diff --git a/pkg/kernel/lib/transformations/closure/info.dart b/pkg/kernel/lib/transformations/closure/info.dart
index 2d9c2ca3c90f6f38ea3b78201741b63a3eaa7c94..83f981423f51b612bd1d2be229324d0a791a9636 100644
--- a/pkg/kernel/lib/transformations/closure/info.dart
+++ b/pkg/kernel/lib/transformations/closure/info.dart
@@ -9,13 +9,17 @@ import '../../ast.dart'
Class,
Constructor,
Field,
+ FieldInitializer,
FunctionDeclaration,
FunctionNode,
+ LocalInitializer,
Member,
Name,
Procedure,
ProcedureKind,
PropertyGet,
+ RedirectingInitializer,
+ SuperInitializer,
ThisExpression,
TypeParameter,
TypeParameterType,
@@ -209,4 +213,38 @@ class ClosureInfo extends RecursiveVisitor {
invokedGetters.add(node.name);
super.visitPropertyGet(node);
}
+
+ visitFieldInitializer(FieldInitializer node) {
karlklose 2017/06/16 07:54:43 Consider adding a helper and move the comment ther
Dmitry Stefantsov 2017/06/16 08:30:00 Thanks! I agree, an example could help with under
+ // Set [currentFunction] to [currentMemberFunction] during visiting the
+ // initializer. Effectively it means that [currentFunction] is set to
+ // [function] field of the constructor, and constructor parameters
+ // encountered in the initializer won't be treated as captured.
+ // Same trick is used in [visitSuperInitializer],
+ // [visitRedirectingInitializer], and [visitLocalInitializer].
+ var saved = currentFunction;
+ currentFunction = currentMemberFunction;
+ super.visitFieldInitializer(node);
+ currentFunction = saved;
+ }
+
+ visitSuperInitializer(SuperInitializer node) {
+ var saved = currentFunction;
+ currentFunction = currentMemberFunction;
+ super.visitSuperInitializer(node);
+ currentFunction = saved;
+ }
+
+ visitRedirectingInitializer(RedirectingInitializer node) {
+ var saved = currentFunction;
+ currentFunction = currentMemberFunction;
+ super.visitRedirectingInitializer(node);
+ currentFunction = saved;
+ }
+
+ visitLocalInitializer(LocalInitializer node) {
+ var saved = currentFunction;
+ currentFunction = currentMemberFunction;
+ super.visitLocalInitializer(node);
+ currentFunction = saved;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698