| 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"; |
| 11 | 11 |
| 12 import 'memory_compiler.dart' show | 12 import 'memory_compiler.dart' show |
| 13 compilerFor; | 13 compilerFor; |
| 14 | 14 |
| 15 import 'package:compiler/src/apiimpl.dart' show | 15 import 'package:compiler/src/apiimpl.dart' show |
| 16 Compiler; | 16 Compiler; |
| 17 | 17 |
| 18 import 'package:compiler/src/constants/values.dart' show | 18 import 'package:compiler/src/constants/values.dart' show |
| 19 ConstantValue, | 19 ConstantValue, |
| 20 TypeConstantValue; | 20 TypeConstantValue; |
| 21 | 21 |
| 22 import 'package:compiler/src/elements/elements.dart' show | 22 import 'package:compiler/src/elements/elements.dart' show |
| 23 Element, | 23 Element, |
| 24 Elements; | 24 Elements; |
| 25 | 25 |
| 26 import 'package:compiler/src/js_backend/js_backend.dart' show | 26 import 'package:compiler/src/js_backend/js_backend.dart' show |
| 27 JavaScriptBackend; | 27 JavaScriptBackend; |
| 28 | 28 |
| 29 import 'package:compiler/src/js_emitter/full_emitter/emitter.dart' |
| 30 as full show Emitter; |
| 31 |
| 29 void expectOnlyVerboseInfo(Uri uri, int begin, int end, String message, kind) { | 32 void expectOnlyVerboseInfo(Uri uri, int begin, int end, String message, kind) { |
| 30 if (kind.name == 'verbose info') { | 33 if (kind.name == 'verbose info') { |
| 31 print(message); | 34 print(message); |
| 32 return; | 35 return; |
| 33 } | 36 } |
| 34 if (message.contains('methods retained for use by dart:mirrors out of')) { | 37 if (message.contains('methods retained for use by dart:mirrors out of')) { |
| 35 print(message); | 38 print(message); |
| 36 return; | 39 return; |
| 37 } | 40 } |
| 38 if (kind.name == 'info') return; | 41 if (kind.name == 'info') return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 compiler.stringClass, compiler.boolClass, compiler.nullClass, | 87 compiler.stringClass, compiler.boolClass, compiler.nullClass, |
| 85 compiler.listClass | 88 compiler.listClass |
| 86 ]; | 89 ]; |
| 87 JavaScriptBackend backend = compiler.backend; | 90 JavaScriptBackend backend = compiler.backend; |
| 88 Iterable<String> nativeNames = nativeClasses.map(backend.namer.className); | 91 Iterable<String> nativeNames = nativeClasses.map(backend.namer.className); |
| 89 expectedNames = expectedNames.map(backend.namer.asName).toList(); | 92 expectedNames = expectedNames.map(backend.namer.asName).toList(); |
| 90 expectedNames.addAll(nativeNames); | 93 expectedNames.addAll(nativeNames); |
| 91 | 94 |
| 92 // Mirrors only work in the full emitter. We can thus be certain that the | 95 // Mirrors only work in the full emitter. We can thus be certain that the |
| 93 // emitter is the full emitter. | 96 // emitter is the full emitter. |
| 94 OldEmitter fullEmitter = backend.emitter.emitter; | 97 full.Emitter fullEmitter = backend.emitter.emitter; |
| 95 Set recordedNames = new Set() | 98 Set recordedNames = new Set() |
| 96 ..addAll(fullEmitter.recordedMangledNames) | 99 ..addAll(fullEmitter.recordedMangledNames) |
| 97 ..addAll(fullEmitter.mangledFieldNames.keys) | 100 ..addAll(fullEmitter.mangledFieldNames.keys) |
| 98 ..addAll(fullEmitter.mangledGlobalFieldNames.keys); | 101 ..addAll(fullEmitter.mangledGlobalFieldNames.keys); |
| 99 Expect.setEquals(new Set.from(expectedNames), recordedNames); | 102 Expect.setEquals(new Set.from(expectedNames), recordedNames); |
| 100 | 103 |
| 101 for (var library in compiler.libraryLoader.libraries) { | 104 for (var library in compiler.libraryLoader.libraries) { |
| 102 library.forEachLocalMember((member) { | 105 library.forEachLocalMember((member) { |
| 103 if (library == compiler.mainApp && member.name == 'Foo') { | 106 if (library == compiler.mainApp && member.name == 'Foo') { |
| 104 Expect.isTrue( | 107 Expect.isTrue( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 library lib; | 172 library lib; |
| 170 | 173 |
| 171 import 'dart:mirrors'; | 174 import 'dart:mirrors'; |
| 172 | 175 |
| 173 useReflect(type) { | 176 useReflect(type) { |
| 174 print(new Symbol('Foo')); | 177 print(new Symbol('Foo')); |
| 175 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 178 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
| 176 } | 179 } |
| 177 """, | 180 """, |
| 178 }; | 181 }; |
| OLD | NEW |