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 /// Test that the @MirrorsUsed annotation suppress hints and that only | 5 /// Test that the @MirrorsUsed annotation suppress hints and that only |
6 /// requested elements are retained for reflection. | 6 /// requested elements are retained for reflection. |
7 library dart2js.test.mirrors_used_test; | 7 library dart2js.test.mirrors_used_test; |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 Set recordedNames = new Set() | 91 Set recordedNames = new Set() |
92 ..addAll(backend.emitter.recordedMangledNames) | 92 ..addAll(backend.emitter.recordedMangledNames) |
93 ..addAll(backend.emitter.mangledFieldNames.keys) | 93 ..addAll(backend.emitter.mangledFieldNames.keys) |
94 ..addAll(backend.emitter.mangledGlobalFieldNames.keys); | 94 ..addAll(backend.emitter.mangledGlobalFieldNames.keys); |
95 Expect.setEquals(new Set.from(expectedNames), recordedNames); | 95 Expect.setEquals(new Set.from(expectedNames), recordedNames); |
96 | 96 |
97 for (var library in compiler.libraryLoader.libraries) { | 97 for (var library in compiler.libraryLoader.libraries) { |
98 library.forEachLocalMember((member) { | 98 library.forEachLocalMember((member) { |
99 if (library == compiler.mainApp && member.name == 'Foo') { | 99 if (library == compiler.mainApp && member.name == 'Foo') { |
100 Expect.isTrue( | 100 Expect.isTrue( |
101 compiler.backend.isNeededForReflection(member), '$member'); | 101 compiler.backend.isAccessibleByReflection(member), '$member'); |
102 member.forEachLocalMember((classMember) { | 102 member.forEachLocalMember((classMember) { |
103 Expect.isTrue( | 103 Expect.isTrue( |
104 compiler.backend.isNeededForReflection(classMember), | 104 compiler.backend.isAccessibleByReflection(classMember), |
105 '$classMember'); | 105 '$classMember'); |
106 }); | 106 }); |
107 } else { | 107 } else { |
108 Expect.isFalse( | 108 Expect.isFalse( |
109 compiler.backend.isNeededForReflection(member), '$member'); | 109 compiler.backend.isAccessibleByReflection(member), '$member'); |
110 } | 110 } |
111 }); | 111 }); |
112 } | 112 } |
113 | 113 |
114 // There should at least be one metadata constant: | 114 // There should at least be one metadata constant: |
115 // 1. The constructed constant for 'MirrorsUsed'. | 115 // 1. The constructed constant for 'MirrorsUsed'. |
116 Expect.isTrue(backend.metadataConstants.length >= 1); | 116 Expect.isTrue(backend.metadataConstants.length >= 1); |
117 | 117 |
118 Set<Constant> compiledConstants = backend.constants.compiledConstants; | 118 Set<Constant> compiledConstants = backend.constants.compiledConstants; |
119 // Make sure that most of the metadata constants aren't included in the | 119 // Make sure that most of the metadata constants aren't included in the |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 library lib; | 163 library lib; |
164 | 164 |
165 import 'dart:mirrors'; | 165 import 'dart:mirrors'; |
166 | 166 |
167 useReflect(type) { | 167 useReflect(type) { |
168 print(new Symbol('Foo')); | 168 print(new Symbol('Foo')); |
169 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 169 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
170 } | 170 } |
171 """, | 171 """, |
172 }; | 172 }; |
OLD | NEW |