| OLD | NEW |
| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // allowed on fields that are in [element] we don't need to visit | 133 // allowed on fields that are in [element] we don't need to visit |
| 134 // superclasses for non-instantiated classes. | 134 // superclasses for non-instantiated classes. |
| 135 cls.implementation.forEachInstanceField(visitField, | 135 cls.implementation.forEachInstanceField(visitField, |
| 136 includeSuperAndInjectedMembers: isInstantiated); | 136 includeSuperAndInjectedMembers: isInstantiated); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool fieldNeedsGetter(VariableElement field) { | 140 bool fieldNeedsGetter(VariableElement field) { |
| 141 assert(field.isField); | 141 assert(field.isField); |
| 142 if (fieldAccessNeverThrows(field)) return false; | 142 if (fieldAccessNeverThrows(field)) return false; |
| 143 if (backend.shouldRetainGetter(field)) return true; | 143 if (backend.mirrorsData.shouldRetainGetter(field)) return true; |
| 144 return field.isClassMember && | 144 return field.isClassMember && |
| 145 compiler.codegenWorldBuilder.hasInvokedGetter(field, closedWorld); | 145 compiler.codegenWorldBuilder.hasInvokedGetter(field, closedWorld); |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool fieldNeedsSetter(VariableElement field) { | 148 bool fieldNeedsSetter(VariableElement field) { |
| 149 assert(field.isField); | 149 assert(field.isField); |
| 150 if (fieldAccessNeverThrows(field)) return false; | 150 if (fieldAccessNeverThrows(field)) return false; |
| 151 if (field.isFinal || field.isConst) return false; | 151 if (field.isFinal || field.isConst) return false; |
| 152 if (backend.shouldRetainSetter(field)) return true; | 152 if (backend.mirrorsData.shouldRetainSetter(field)) return true; |
| 153 return field.isClassMember && | 153 return field.isClassMember && |
| 154 compiler.codegenWorldBuilder.hasInvokedSetter(field, closedWorld); | 154 compiler.codegenWorldBuilder.hasInvokedSetter(field, closedWorld); |
| 155 } | 155 } |
| 156 | 156 |
| 157 static bool fieldAccessNeverThrows(VariableElement field) { | 157 static bool fieldAccessNeverThrows(VariableElement field) { |
| 158 return | 158 return |
| 159 // We never access a field in a closure (a captured variable) without | 159 // We never access a field in a closure (a captured variable) without |
| 160 // knowing that it is there. Therefore we don't need to use a getter | 160 // knowing that it is there. Therefore we don't need to use a getter |
| 161 // (that will throw if the getter method is missing), but can always | 161 // (that will throw if the getter method is missing), but can always |
| 162 // access the field directly. | 162 // access the field directly. |
| 163 field is ClosureFieldElement; | 163 field is ClosureFieldElement; |
| 164 } | 164 } |
| 165 | 165 |
| 166 bool canAvoidGeneratedCheckedSetter(VariableElement member) { | 166 bool canAvoidGeneratedCheckedSetter(VariableElement member) { |
| 167 // We never generate accessors for top-level/static fields. | 167 // We never generate accessors for top-level/static fields. |
| 168 if (!member.isInstanceMember) return true; | 168 if (!member.isInstanceMember) return true; |
| 169 ResolutionDartType type = member.type; | 169 ResolutionDartType type = member.type; |
| 170 return type.treatAsDynamic || type.isObject; | 170 return type.treatAsDynamic || type.isObject; |
| 171 } | 171 } |
| 172 } | 172 } |
| OLD | NEW |