| 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 cls.implementation.forEachInstanceField(visitField, | 133 cls.implementation.forEachInstanceField(visitField, |
| 134 includeSuperAndInjectedMembers: isInstantiated); | 134 includeSuperAndInjectedMembers: isInstantiated); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool fieldNeedsGetter(VariableElement field) { | 138 bool fieldNeedsGetter(VariableElement field) { |
| 139 assert(field.isField); | 139 assert(field.isField); |
| 140 if (fieldAccessNeverThrows(field)) return false; | 140 if (fieldAccessNeverThrows(field)) return false; |
| 141 if (backend.shouldRetainGetter(field)) return true; | 141 if (backend.shouldRetainGetter(field)) return true; |
| 142 return field.isClassMember && | 142 return field.isClassMember && |
| 143 compiler.codegenWorld.hasInvokedGetter(field, compiler.world); | 143 compiler.codegenWorld.hasInvokedGetter(field, compiler.closedWorld); |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool fieldNeedsSetter(VariableElement field) { | 146 bool fieldNeedsSetter(VariableElement field) { |
| 147 assert(field.isField); | 147 assert(field.isField); |
| 148 if (fieldAccessNeverThrows(field)) return false; | 148 if (fieldAccessNeverThrows(field)) return false; |
| 149 if (field.isFinal || field.isConst) return false; | 149 if (field.isFinal || field.isConst) return false; |
| 150 if (backend.shouldRetainSetter(field)) return true; | 150 if (backend.shouldRetainSetter(field)) return true; |
| 151 return field.isClassMember && | 151 return field.isClassMember && |
| 152 compiler.codegenWorld.hasInvokedSetter(field, compiler.world); | 152 compiler.codegenWorld.hasInvokedSetter(field, compiler.closedWorld); |
| 153 } | 153 } |
| 154 | 154 |
| 155 static bool fieldAccessNeverThrows(VariableElement field) { | 155 static bool fieldAccessNeverThrows(VariableElement field) { |
| 156 return | 156 return |
| 157 // We never access a field in a closure (a captured variable) without | 157 // We never access a field in a closure (a captured variable) without |
| 158 // knowing that it is there. Therefore we don't need to use a getter | 158 // knowing that it is there. Therefore we don't need to use a getter |
| 159 // (that will throw if the getter method is missing), but can always | 159 // (that will throw if the getter method is missing), but can always |
| 160 // access the field directly. | 160 // access the field directly. |
| 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.isObject; | 168 return type.treatAsDynamic || type.isObject; |
| 169 } | 169 } |
| 170 } | 170 } |
| OLD | NEW |