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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; |
| 7 import '../../async_helper.dart'; |
6 import 'memory_compiler.dart' show compilerFor; | 8 import 'memory_compiler.dart' show compilerFor; |
7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show | 9 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show |
8 Compiler; | 10 Compiler; |
9 import | 11 import |
10 '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backen
d.dart' | 12 '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backen
d.dart' |
11 show | 13 show |
12 DartBackend; | 14 DartBackend; |
13 import | 15 import |
14 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart' | 16 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart' |
15 show | 17 show |
16 Node; | 18 Node; |
17 | 19 |
18 main() { | 20 main() { |
19 testUniqueMinification(); | 21 testUniqueMinification(); |
20 testNoUniqueMinification(); | 22 testNoUniqueMinification(); |
21 } | 23 } |
22 | 24 |
23 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { | 25 Future<Compiler> runCompiler({useMirrorHelperLibrary: false, minify: false}) { |
24 List<String> options = ['--output-type=dart']; | 26 List<String> options = ['--output-type=dart']; |
25 if (minify) { | 27 if (minify) { |
26 options.add('--minify'); | 28 options.add('--minify'); |
27 } | 29 } |
28 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); | 30 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); |
29 DartBackend backend = compiler.backend; | 31 DartBackend backend = compiler.backend; |
30 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; | 32 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
31 compiler.runCompiler(Uri.parse('memory:main.dart')); | 33 return |
32 return compiler; | 34 compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler); |
33 } | 35 } |
34 | 36 |
35 void testUniqueMinification() { | 37 void testUniqueMinification() { |
36 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: true); | 38 asyncTest(() => runCompiler(useMirrorHelperLibrary: true, minify: true). |
37 DartBackend backend = compiler.backend; | 39 then((Compiler compiler) { |
38 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; | 40 DartBackend backend = compiler.backend; |
39 Map<Node, String> renames = backend.renames; | 41 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; |
40 Map<String, SourceString> symbols = mirrorRenamer.symbols; | 42 Map<Node, String> renames = backend.renames; |
| 43 Map<String, SourceString> symbols = mirrorRenamer.symbols; |
41 | 44 |
42 // Check that no two different source code names get the same mangled name, | 45 // Check that no two different source code names get the same mangled name, |
43 // with the exception of MirrorSystem.getName that gets renamed to the same | 46 // with the exception of MirrorSystem.getName that gets renamed to the same |
44 // mangled name as the getNameHelper from _mirror_helper.dart. | 47 // mangled name as the getNameHelper from _mirror_helper.dart. |
45 for (Node node in renames.keys) { | 48 for (Node node in renames.keys) { |
46 Identifier identifier = node.asIdentifier(); | 49 Identifier identifier = node.asIdentifier(); |
47 if (identifier != null) { | 50 if (identifier != null) { |
48 SourceString source = identifier.source; | 51 SourceString source = identifier.source; |
49 if (mirrorRenamer.mirrorSystemGetNameNodes.first.selector == node) | 52 if (mirrorRenamer.mirrorSystemGetNameNodes.first.selector == node) |
50 continue; | 53 continue; |
51 if (symbols.containsKey(renames[node])) { | 54 if (symbols.containsKey(renames[node])) { |
52 print(node); | 55 print(node); |
53 Expect.equals(source, symbols[renames[node]]); | 56 Expect.equals(source, symbols[renames[node]]); |
| 57 } |
54 } | 58 } |
55 } | 59 } |
56 } | 60 })); |
57 } | 61 } |
58 | 62 |
59 void testNoUniqueMinification() { | 63 void testNoUniqueMinification() { |
60 Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: true); | 64 asyncTest(() => runCompiler(useMirrorHelperLibrary: false, minify: true). |
61 DartBackend backend = compiler.backend; | 65 then((Compiler compiler) { |
62 Map<Node, String> renames = backend.renames; | 66 DartBackend backend = compiler.backend; |
| 67 Map<Node, String> renames = backend.renames; |
63 | 68 |
64 // 'Foo' appears twice and 'invocation' and 'hest' get the same mangled name. | 69 // 'Foo' appears twice and 'invocation' and 'hest' get the same mangled |
65 Expect.equals(renames.values.toSet().length, renames.values.length - 2); | 70 // name. |
| 71 Expect.equals(renames.values.toSet().length, renames.values.length - 2); |
| 72 })); |
66 } | 73 } |
67 | 74 |
68 const MEMORY_SOURCE_FILES = const <String, String> { | 75 const MEMORY_SOURCE_FILES = const <String, String> { |
69 'main.dart': """ | 76 'main.dart': """ |
70 import 'dart:mirrors'; | 77 import 'dart:mirrors'; |
71 | 78 |
72 class Foo { | 79 class Foo { |
73 noSuchMethod(invocation) { | 80 noSuchMethod(invocation) { |
74 MirrorSystem.getName(null); | 81 MirrorSystem.getName(null); |
75 } | 82 } |
76 } | 83 } |
77 | 84 |
78 main() { | 85 main() { |
79 new Foo().fisk(); | 86 new Foo().fisk(); |
80 var hest; | 87 var hest; |
81 } | 88 } |
82 """}; | 89 """}; |
OLD | NEW |