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

Unified Diff: runtime/vm/ast.cc

Issue 10050022: Fix lazy initialization of static fields (issue 2472). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/ast.cc
===================================================================
--- runtime/vm/ast.cc (revision 6437)
+++ runtime/vm/ast.cc (working copy)
@@ -406,7 +406,28 @@
AstNode* StaticGetterNode::MakeAssignmentNode(AstNode* rhs) {
- return new StaticSetterNode(token_index(), cls(), field_name(), rhs);
+ // If no setter exist, set the field directly.
+ const String& setter_name = String::Handle(Field::SetterName(field_name()));
+ const Function& setter =
+ Function::ZoneHandle(cls().LookupStaticFunction(setter_name));
+ if (setter.IsNull()) {
+ // Access to a lazily initialized static field that has not yet been
+ // initialized is compiled to a static implicit getter.
+ // A setter may not exist for such a field.
+#if defined(DEBUG)
+ const String& getter_name = String::Handle(Field::GetterName(field_name()));
+ const Function& getter =
+ Function::ZoneHandle(cls().LookupStaticFunction(getter_name));
+ ASSERT(!getter.IsNull() &&
+ (getter.kind() == RawFunction::kConstImplicitGetter));
+#endif
+ const Field& field = Field::ZoneHandle(
+ cls().LookupStaticField(field_name()));
+ ASSERT(!field.IsNull());
+ return new StoreStaticFieldNode(token_index(), field, rhs);
+ } else {
+ return new StaticSetterNode(token_index(), cls(), field_name(), rhs);
+ }
}
« no previous file with comments | « no previous file | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698