Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: dart/tests/compiler/dart2js/mirrors_used_test.dart

Issue 21110003: Implement MirrorUsed.targets for libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r25609 and added test. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Test that the @MirrorsUsed annotation suppress hints and that only
6 /// requested elements are retained for reflection.
7 library dart2js.test.mirrors_used_test;
8
9 import 'package:expect/expect.dart';
10
11 import 'memory_compiler.dart' show
12 compilerFor;
13
14 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show
15 Compiler;
16
17 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show
18 SourceString;
19
20 import
21 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart'
22 show
23 Elements;
24
25 void expectOnlyVerboseInfo(Uri uri, int begin, int end, String message, kind) {
26 if (kind.name == 'verbose info') {
27 print(message);
28 return;
29 }
30 throw '$uri:$begin:$end: $kind: $message';
31 }
32
33 void main() {
34 Compiler compiler = compilerFor(
35 MEMORY_SOURCE_FILES, diagnosticHandler: expectOnlyVerboseInfo);
36 compiler.runCompiler(Uri.parse('memory:main.dart'));
37
38 print('');
39 List generatedCode =
40 Elements.sortedByPosition(compiler.enqueuer.codegen.generatedCode.keys);
41 for (var element in generatedCode) {
42 print(element);
43 }
44 print('');
45
46 // This assertion can fail for two reasons:
47 // 1. Too many elements retained for reflection.
48 // 2. Some code was refactored, and there are more methods.
49 // Either situation could be problematic, but in situation 2, it is often
50 // acceptable to increase [expectedMethodCount] a little.
51 int expectedMethodCount = 315;
52 Expect.isTrue(
53 generatedCode.length <= expectedMethodCount,
54 'Too many compiled methods: '
55 '${generatedCode.length} > $expectedMethodCount');
56
57 for (var library in compiler.libraries.values) {
58 library.forEachLocalMember((member) {
59 if (library == compiler.mainApp) {
60 // TODO(ahe): We currently retain the entire library. Update this test
61 // to test that only Foo is retained.
62 Expect.isTrue(
63 compiler.backend.isNeededForReflection(member), '$member');
64 } else {
65 Expect.isFalse(
66 compiler.backend.isNeededForReflection(member), '$member');
67 }
68 });
69 }
70 }
71
72 const MEMORY_SOURCE_FILES = const <String, String> {
73 'main.dart': """
74 @MirrorsUsed(targets: const [Foo], override: '*')
75 import 'dart:mirrors';
76
77 import 'library.dart';
78
79 class Foo {}
80
81 main() {
82 useReflect(Foo);
83 }
84 """,
85 'library.dart': """
86 library lib;
87
88 import 'dart:mirrors';
89
90 useReflect(type) {
91 print(new Symbol('Foo'));
92 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName));
93 }
94 """,
95 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698