Chromium Code Reviews| 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 testWithMirrorHeplerLibrary(minify: true); | |
|
Johnni Winther
2013/08/23 09:25:19
Hepler -> Helper
zarah
2013/08/23 16:16:37
Done.
| |
| 24 testWithMirrorHeplerLibrary(minify: false); | |
|
Johnni Winther
2013/08/23 09:25:19
Ditto.
zarah
2013/08/23 16:16:37
Done.
| |
| 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 testWithMirrorHeplerLibrary({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 if (minify) { | |
| 71 Expect.equals(1, i.length); | |
| 72 } else { | |
| 73 // Referenced twice in code and twice in renames map. | |
|
Johnni Winther
2013/08/23 09:25:19
Why twice? There is only one call to MirrorSystem.
zarah
2013/08/23 16:16:37
The function getNameHelper from _mirror_helper.dar
| |
| 74 Expect.equals(4, i.length); | |
| 75 } | |
| 76 | |
| 77 String mapMatch = 'const<String,SourceString>'; | |
| 78 i = mapMatch.allMatches(output); | |
| 79 Expect.equals(1, i.length); | |
| 80 } | |
| 81 | |
| 82 void testWithoutMirrorHelperLibrary({bool minify}) { | |
| 83 Compiler compiler = | |
| 84 runCompiler(useMirrorHelperLibrary: false, minify: minify); | |
| 85 DartBackend backend = compiler.backend; | |
| 86 | |
| 87 Expect.equals(null, backend.mirrorHelperLibrary); | |
| 88 Expect.equals(null, backend.mirrorHelperGetNameFunction); | |
| 89 Expect.equals(null, backend.mirrorRenamer); | |
| 90 } | |
| 91 | |
| 92 const MEMORY_SOURCE_FILES = const <String, String> { | |
| 93 'main.dart': """ | |
| 94 import 'dart:mirrors'; | |
| 95 | |
| 96 | |
|
Johnni Winther
2013/08/23 09:25:19
Remove extra empty line.
zarah
2013/08/23 16:16:37
Done.
| |
| 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 |