| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 List<Element> nativeClasses = [ | 82 List<Element> nativeClasses = [ |
| 83 compiler.intClass, compiler.doubleClass, compiler.numClass, | 83 compiler.intClass, compiler.doubleClass, compiler.numClass, |
| 84 compiler.stringClass, compiler.boolClass, compiler.nullClass, | 84 compiler.stringClass, compiler.boolClass, compiler.nullClass, |
| 85 compiler.listClass | 85 compiler.listClass |
| 86 ]; | 86 ]; |
| 87 JavaScriptBackend backend = compiler.backend; | 87 JavaScriptBackend backend = compiler.backend; |
| 88 Iterable<String> nativeNames = nativeClasses.map(backend.namer.className); | 88 Iterable<String> nativeNames = nativeClasses.map(backend.namer.className); |
| 89 expectedNames = expectedNames.map(backend.namer.asName).toList(); | 89 expectedNames = expectedNames.map(backend.namer.asName).toList(); |
| 90 expectedNames.addAll(nativeNames); | 90 expectedNames.addAll(nativeNames); |
| 91 | 91 |
| 92 // Mirrors only work in the full emitter. We can thus be certain that the |
| 93 // emitter is the full emitter. |
| 94 OldEmitter fullEmitter = backend.emitter.emitter; |
| 92 Set recordedNames = new Set() | 95 Set recordedNames = new Set() |
| 93 ..addAll(backend.emitter.oldEmitter.recordedMangledNames) | 96 ..addAll(fullEmitter.recordedMangledNames) |
| 94 ..addAll(backend.emitter.oldEmitter.mangledFieldNames.keys) | 97 ..addAll(fullEmitter.mangledFieldNames.keys) |
| 95 ..addAll(backend.emitter.oldEmitter.mangledGlobalFieldNames.keys); | 98 ..addAll(fullEmitter.mangledGlobalFieldNames.keys); |
| 96 Expect.setEquals(new Set.from(expectedNames), recordedNames); | 99 Expect.setEquals(new Set.from(expectedNames), recordedNames); |
| 97 | 100 |
| 98 for (var library in compiler.libraryLoader.libraries) { | 101 for (var library in compiler.libraryLoader.libraries) { |
| 99 library.forEachLocalMember((member) { | 102 library.forEachLocalMember((member) { |
| 100 if (library == compiler.mainApp && member.name == 'Foo') { | 103 if (library == compiler.mainApp && member.name == 'Foo') { |
| 101 Expect.isTrue( | 104 Expect.isTrue( |
| 102 compiler.backend.isAccessibleByReflection(member), '$member'); | 105 compiler.backend.isAccessibleByReflection(member), '$member'); |
| 103 member.forEachLocalMember((classMember) { | 106 member.forEachLocalMember((classMember) { |
| 104 Expect.isTrue( | 107 Expect.isTrue( |
| 105 compiler.backend.isAccessibleByReflection(classMember), | 108 compiler.backend.isAccessibleByReflection(classMember), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 library lib; | 169 library lib; |
| 167 | 170 |
| 168 import 'dart:mirrors'; | 171 import 'dart:mirrors'; |
| 169 | 172 |
| 170 useReflect(type) { | 173 useReflect(type) { |
| 171 print(new Symbol('Foo')); | 174 print(new Symbol('Foo')); |
| 172 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 175 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
| 173 } | 176 } |
| 174 """, | 177 """, |
| 175 }; | 178 }; |
| OLD | NEW |