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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/program_builder/field_visitor.dart

Issue 1408043002: Move native and js interop properties from the element model to the JS backend (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart2js.js_emitter.program_builder; 5 part of dart2js.js_emitter.program_builder;
6 6
7 /** 7 /**
8 * [member] is a field (instance, static, or top level). 8 * [member] is a field (instance, static, or top level).
9 * 9 *
10 * [name] is the field name that the [Namer] has picked for this field's 10 * [name] is the field name that the [Namer] has picked for this field's
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // inheritance purposes, but we can simplify its JavaScript constructor. 73 // inheritance purposes, but we can simplify its JavaScript constructor.
74 bool isInstantiated = 74 bool isInstantiated =
75 compiler.codegenWorld.directlyInstantiatedClasses.contains(element); 75 compiler.codegenWorld.directlyInstantiatedClasses.contains(element);
76 76
77 void visitField(Element holder, FieldElement field) { 77 void visitField(Element holder, FieldElement field) {
78 assert(invariant(element, field.isDeclaration)); 78 assert(invariant(element, field.isDeclaration));
79 79
80 // Keep track of whether or not we're dealing with a field mixin 80 // Keep track of whether or not we're dealing with a field mixin
81 // into a native class. 81 // into a native class.
82 bool isMixinNativeField = 82 bool isMixinNativeField =
83 isClass && element.isNative && holder.isMixinApplication; 83 isClass && backend.isNative(element) && holder.isMixinApplication;
84 84
85 // See if we can dynamically create getters and setters. 85 // See if we can dynamically create getters and setters.
86 // We can only generate getters and setters for [element] since 86 // We can only generate getters and setters for [element] since
87 // the fields of super classes could be overwritten with getters or 87 // the fields of super classes could be overwritten with getters or
88 // setters. 88 // setters.
89 bool needsGetter = false; 89 bool needsGetter = false;
90 bool needsSetter = false; 90 bool needsSetter = false;
91 if (isLibrary || isMixinNativeField || holder == element) { 91 if (isLibrary || isMixinNativeField || holder == element) {
92 needsGetter = fieldNeedsGetter(field); 92 needsGetter = fieldNeedsGetter(field);
93 needsSetter = fieldNeedsSetter(field); 93 needsSetter = fieldNeedsSetter(field);
94 } 94 }
95 95
96 if ((isInstantiated && !holder.isNative) 96 if ((isInstantiated && !backend.isNative(holder))
97 || needsGetter 97 || needsGetter
98 || needsSetter) { 98 || needsSetter) {
99 js.Name accessorName = namer.fieldAccessorName(field); 99 js.Name accessorName = namer.fieldAccessorName(field);
100 js.Name fieldName = namer.fieldPropertyName(field); 100 js.Name fieldName = namer.fieldPropertyName(field);
101 bool needsCheckedSetter = false; 101 bool needsCheckedSetter = false;
102 if (compiler.enableTypeAssertions 102 if (compiler.enableTypeAssertions
103 && needsSetter 103 && needsSetter
104 && !canAvoidGeneratedCheckedSetter(field)) { 104 && !canAvoidGeneratedCheckedSetter(field)) {
105 needsCheckedSetter = true; 105 needsCheckedSetter = true;
106 needsSetter = false; 106 needsSetter = false;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 field is ClosureFieldElement; 161 field is ClosureFieldElement;
162 } 162 }
163 163
164 bool canAvoidGeneratedCheckedSetter(VariableElement member) { 164 bool canAvoidGeneratedCheckedSetter(VariableElement member) {
165 // We never generate accessors for top-level/static fields. 165 // We never generate accessors for top-level/static fields.
166 if (!member.isInstanceMember) return true; 166 if (!member.isInstanceMember) return true;
167 DartType type = member.type; 167 DartType type = member.type;
168 return type.treatAsDynamic || (type.element == compiler.objectClass); 168 return type.treatAsDynamic || (type.element == compiler.objectClass);
169 } 169 }
170 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698