| OLD | NEW |
| (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 import "package:expect/expect.dart"; |
| 6 import 'memory_compiler.dart' show compilerFor; |
| 7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show |
| 8 Compiler; |
| 9 import |
| 10 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart' |
| 11 show |
| 12 Node; |
| 13 import |
| 14 '../../../sdk/lib/_internal/compiler/implementation/dart_backend/dart_backen
d.dart'; |
| 15 import |
| 16 '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_re
namer.dart'; |
| 17 import |
| 18 '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart' |
| 19 show |
| 20 SourceString; |
| 21 |
| 22 main() { |
| 23 testWithMirrorHelperLibrary(minify: true); |
| 24 testWithMirrorHelperLibrary(minify: false); |
| 25 testWithoutMirrorHelperLibrary(minify: true); |
| 26 testWithoutMirrorHelperLibrary(minify: false); |
| 27 } |
| 28 |
| 29 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { |
| 30 List<String> options = ['--output-type=dart']; |
| 31 if (minify) { |
| 32 options.add('--minify'); |
| 33 } |
| 34 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); |
| 35 DartBackend backend = compiler.backend; |
| 36 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
| 37 compiler.runCompiler(Uri.parse('memory:main.dart')); |
| 38 return compiler; |
| 39 } |
| 40 |
| 41 void testWithMirrorHelperLibrary({bool minify}) { |
| 42 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify); |
| 43 |
| 44 DartBackend backend = compiler.backend; |
| 45 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; |
| 46 Map<Node, String> renames = backend.renames; |
| 47 Map<String, SourceString> symbols = mirrorRenamer.symbols; |
| 48 |
| 49 Expect.isFalse(null == backend.mirrorHelperLibrary); |
| 50 Expect.isFalse(null == backend.mirrorHelperGetNameFunction); |
| 51 Expect.isTrue(symbols.containsValue( |
| 52 const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION))); |
| 53 |
| 54 for (Node n in renames.keys) { |
| 55 if (symbols.containsKey(renames[n])) { |
| 56 if(n.toString() == 'getName') { |
| 57 Expect.equals( |
| 58 const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION), |
| 59 symbols[renames[n]]); |
| 60 } else { |
| 61 Expect.equals(n.toString(), symbols[renames[n]].stringValue); |
| 62 } |
| 63 } |
| 64 } |
| 65 |
| 66 String output = compiler.assembledCode; |
| 67 String getNameMatch = MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION; |
| 68 Iterable i = getNameMatch.allMatches(output); |
| 69 |
| 70 |
| 71 if (minify) { |
| 72 Expect.equals(1, i.length); |
| 73 } else { |
| 74 // Appears twice in code (defined & called) and twice in renames map. |
| 75 Expect.equals(4, i.length); |
| 76 } |
| 77 |
| 78 String mapMatch = 'const<String,SourceString>'; |
| 79 i = mapMatch.allMatches(output); |
| 80 Expect.equals(1, i.length); |
| 81 } |
| 82 |
| 83 void testWithoutMirrorHelperLibrary({bool minify}) { |
| 84 Compiler compiler = |
| 85 runCompiler(useMirrorHelperLibrary: false, minify: minify); |
| 86 DartBackend backend = compiler.backend; |
| 87 |
| 88 Expect.equals(null, backend.mirrorHelperLibrary); |
| 89 Expect.equals(null, backend.mirrorHelperGetNameFunction); |
| 90 Expect.equals(null, backend.mirrorRenamer); |
| 91 } |
| 92 |
| 93 const MEMORY_SOURCE_FILES = const <String, String> { |
| 94 'main.dart': """ |
| 95 import 'dart:mirrors'; |
| 96 |
| 97 class Foo { |
| 98 noSuchMethod(Invocation invocation) { |
| 99 MirrorSystem.getName(invocation.memberName); |
| 100 } |
| 101 } |
| 102 |
| 103 void main() { |
| 104 new Foo().fisk(); |
| 105 } |
| 106 """}; |
| OLD | NEW |