OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 class ClassEmitter extends CodeEmitterHelper { | 7 class ClassEmitter extends CodeEmitterHelper { |
8 | 8 |
9 ClassStubGenerator get _stubGenerator => | 9 ClassStubGenerator get _stubGenerator => |
10 new ClassStubGenerator(compiler, namer, backend); | 10 new ClassStubGenerator(compiler, namer, backend); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 154 } |
155 | 155 |
156 int code = field.getterFlags + (field.setterFlags << 2); | 156 int code = field.getterFlags + (field.setterFlags << 2); |
157 if (code == 0) { | 157 if (code == 0) { |
158 compiler.internalError(fieldElement, | 158 compiler.internalError(fieldElement, |
159 'Field code is 0 ($fieldElement).'); | 159 'Field code is 0 ($fieldElement).'); |
160 } else { | 160 } else { |
161 fieldCode = FIELD_CODE_CHARACTERS[code - FIRST_FIELD_CODE]; | 161 fieldCode = FIELD_CODE_CHARACTERS[code - FIRST_FIELD_CODE]; |
162 } | 162 } |
163 } | 163 } |
| 164 // Fields can only be reflected if their declaring class is reflectable |
| 165 // (as they are only accessible via [ClassMirror.declarations]). |
| 166 // However, set/get operations can be performed on them, so they are |
| 167 // reflectable in some sense, which leads to [isAccessibleByReflection] |
| 168 // reporting `true`. |
164 if (backend.isAccessibleByReflection(fieldElement)) { | 169 if (backend.isAccessibleByReflection(fieldElement)) { |
165 DartType type = fieldElement.type; | 170 if (fieldElement.isTopLevel || |
166 reflectionMarker = '-${task.metadataCollector.reifyType(type)}'; | 171 backend.isAccessibleByReflection(fieldElement.enclosingClass)) { |
| 172 DartType type = fieldElement.type; |
| 173 reflectionMarker = '-${task.metadataCollector.reifyType(type)}'; |
| 174 } else { |
| 175 reflectionMarker = '-'; |
| 176 } |
167 } | 177 } |
168 String builtFieldname = '$fieldName$fieldCode$reflectionMarker'; | 178 String builtFieldname = '$fieldName$fieldCode$reflectionMarker'; |
169 builder.addField(builtFieldname); | 179 builder.addField(builtFieldname); |
170 // Add 1 because adding a field to the class also requires a comma | 180 // Add 1 because adding a field to the class also requires a comma |
171 compiler.dumpInfoTask.recordFieldNameSize(fieldElement, | 181 compiler.dumpInfoTask.recordFieldNameSize(fieldElement, |
172 builtFieldname.length + 1); | 182 builtFieldname.length + 1); |
173 fieldsAdded = true; | 183 fieldsAdded = true; |
174 } | 184 } |
175 } | 185 } |
176 | 186 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 ? new Selector.getter(member.name, member.library) | 556 ? new Selector.getter(member.name, member.library) |
547 : new Selector.setter(member.name, member.library); | 557 : new Selector.setter(member.name, member.library); |
548 String reflectionName = emitter.getReflectionName(selector, name); | 558 String reflectionName = emitter.getReflectionName(selector, name); |
549 if (reflectionName != null) { | 559 if (reflectionName != null) { |
550 var reflectable = | 560 var reflectable = |
551 js(backend.isAccessibleByReflection(member) ? '1' : '0'); | 561 js(backend.isAccessibleByReflection(member) ? '1' : '0'); |
552 builder.addProperty('+$reflectionName', reflectable); | 562 builder.addProperty('+$reflectionName', reflectable); |
553 } | 563 } |
554 } | 564 } |
555 } | 565 } |
OLD | NEW |