| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 throw '$uri:$begin:$end: $kind: $message'; | 43 throw '$uri:$begin:$end: $kind: $message'; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void main() { | 46 void main() { |
| 47 asyncTest(() async { | 47 asyncTest(() async { |
| 48 var result = await runCompiler( | 48 var result = await runCompiler( |
| 49 memorySourceFiles: MEMORY_SOURCE_FILES, | 49 memorySourceFiles: MEMORY_SOURCE_FILES, |
| 50 diagnosticHandler: new LegacyCompilerDiagnostics(expectOnlyVerboseInfo), | 50 diagnosticHandler: new LegacyCompilerDiagnostics(expectOnlyVerboseInfo), |
| 51 options: ['--enable-experimental-mirrors']); | 51 options: ['--enable-experimental-mirrors']); |
| 52 CompilerImpl compiler = result.compiler; | 52 CompilerImpl compiler = result.compiler; |
| 53 JavaScriptBackend backend = compiler.backend; |
| 53 print(''); | 54 print(''); |
| 54 List generatedCode = | 55 List generatedCode = Elements.sortedByPosition(backend.generatedCode.keys); |
| 55 Elements.sortedByPosition(compiler.enqueuer.codegen.processedEntities); | |
| 56 for (var element in generatedCode) { | 56 for (var element in generatedCode) { |
| 57 print(element); | 57 print(element); |
| 58 } | 58 } |
| 59 print(''); | 59 print(''); |
| 60 | 60 |
| 61 // This assertion can fail for two reasons: | 61 // This assertion can fail for two reasons: |
| 62 // 1. Too many elements retained for reflection. | 62 // 1. Too many elements retained for reflection. |
| 63 // 2. Some code was refactored, and there are more methods. | 63 // 2. Some code was refactored, and there are more methods. |
| 64 // Either situation could be problematic, but in situation 2, it is often | 64 // Either situation could be problematic, but in situation 2, it is often |
| 65 // acceptable to increase [expectedMethodCount] a little. | 65 // acceptable to increase [expectedMethodCount] a little. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 // We always include the names of some native classes. | 85 // We always include the names of some native classes. |
| 86 List<Element> nativeClasses = [ | 86 List<Element> nativeClasses = [ |
| 87 compiler.coreClasses.intClass, | 87 compiler.coreClasses.intClass, |
| 88 compiler.coreClasses.doubleClass, | 88 compiler.coreClasses.doubleClass, |
| 89 compiler.coreClasses.numClass, | 89 compiler.coreClasses.numClass, |
| 90 compiler.coreClasses.stringClass, | 90 compiler.coreClasses.stringClass, |
| 91 compiler.coreClasses.boolClass, | 91 compiler.coreClasses.boolClass, |
| 92 compiler.coreClasses.nullClass, | 92 compiler.coreClasses.nullClass, |
| 93 compiler.coreClasses.listClass | 93 compiler.coreClasses.listClass |
| 94 ]; | 94 ]; |
| 95 JavaScriptBackend backend = compiler.backend; | |
| 96 Iterable<String> nativeNames = nativeClasses.map(backend.namer.className); | 95 Iterable<String> nativeNames = nativeClasses.map(backend.namer.className); |
| 97 expectedNames = expectedNames.map(backend.namer.asName).toList(); | 96 expectedNames = expectedNames.map(backend.namer.asName).toList(); |
| 98 expectedNames.addAll(nativeNames); | 97 expectedNames.addAll(nativeNames); |
| 99 | 98 |
| 100 // Mirrors only work in the full emitter. We can thus be certain that the | 99 // Mirrors only work in the full emitter. We can thus be certain that the |
| 101 // emitter is the full emitter. | 100 // emitter is the full emitter. |
| 102 full.Emitter fullEmitter = backend.emitter.emitter; | 101 full.Emitter fullEmitter = backend.emitter.emitter; |
| 103 Set recordedNames = new Set() | 102 Set recordedNames = new Set() |
| 104 ..addAll(fullEmitter.recordedMangledNames) | 103 ..addAll(fullEmitter.recordedMangledNames) |
| 105 ..addAll(fullEmitter.mangledFieldNames.keys) | 104 ..addAll(fullEmitter.mangledFieldNames.keys) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 library lib; | 179 library lib; |
| 181 | 180 |
| 182 import 'dart:mirrors'; | 181 import 'dart:mirrors'; |
| 183 | 182 |
| 184 useReflect(type) { | 183 useReflect(type) { |
| 185 print(new Symbol('Foo')); | 184 print(new Symbol('Foo')); |
| 186 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 185 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
| 187 } | 186 } |
| 188 """, | 187 """, |
| 189 }; | 188 }; |
| OLD | NEW |