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