| 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 'memory_compiler.dart' show compilerFor; | 6 import 'memory_compiler.dart' show compilerFor; |
| 7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show | 7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show |
| 8 Compiler; | 8 Compiler; |
| 9 import | 9 import |
| 10 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart' | 10 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart' |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_re
namer.dart' | 22 '../../../sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_re
namer.dart' |
| 23 show | 23 show |
| 24 MirrorRenamer; | 24 MirrorRenamer; |
| 25 import | 25 import |
| 26 '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart' | 26 '../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart' |
| 27 show | 27 show |
| 28 SourceString; | 28 SourceString; |
| 29 | 29 |
| 30 | 30 |
| 31 main() { | 31 main() { |
| 32 testWithMirrorRenaming(); | 32 testWithMirrorRenaming(minify: true); |
| 33 testWithoutMirrorRenaming(); | 33 testWithMirrorRenaming(minify: false); |
| 34 testWithMirrorRenamingMinify(); | 34 testWithoutMirrorRenaming(minify: true); |
| 35 testWithoutMirrorRenamingMinify(); | 35 testWithoutMirrorRenaming(minify: false); |
| 36 } | 36 } |
| 37 | 37 |
| 38 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { | 38 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { |
| 39 List<String> options = ['--output-type=dart']; | 39 List<String> options = ['--output-type=dart']; |
| 40 if (minify) { | 40 if (minify) { |
| 41 options.add('--minify'); | 41 options.add('--minify'); |
| 42 } | 42 } |
| 43 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); | 43 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); |
| 44 DartBackend backend = compiler.backend; | 44 DartBackend backend = compiler.backend; |
| 45 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; | 45 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
| 46 compiler.runCompiler(Uri.parse('memory:main.dart')); | 46 compiler.runCompiler(Uri.parse('memory:main.dart')); |
| 47 return compiler; | 47 return compiler; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void testWithMirrorRenaming() { | 50 void testWithMirrorRenaming({bool minify}) { |
| 51 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: false); | 51 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify); |
| 52 | 52 |
| 53 DartBackend backend = compiler.backend; | 53 DartBackend backend = compiler.backend; |
| 54 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; |
| 54 Map<Node, String> renames = backend.renames; | 55 Map<Node, String> renames = backend.renames; |
| 55 Map<LibraryElement, String> imports = backend.imports; | 56 Map<LibraryElement, String> imports = backend.imports; |
| 56 | 57 |
| 57 Node getNameFunctionNode = | 58 Node getNameFunctionNode = |
| 58 backend.memberNodes.values.first.first.body.statements.nodes.head; | 59 backend.memberNodes.values.first.first.body.statements.nodes.head; |
| 59 | 60 |
| 60 Expect.equals(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION, | 61 Expect.equals( |
| 61 renames[getNameFunctionNode.expression.selector]); | 62 const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION), |
| 62 Expect.equals(MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME, | 63 mirrorRenamer.symbols[renames[getNameFunctionNode.expression.selector]]); |
| 64 Expect.equals("", |
| 63 renames[getNameFunctionNode.expression.receiver]); | 65 renames[getNameFunctionNode.expression.receiver]); |
| 64 Expect.equals(2, imports.keys.length); | 66 Expect.equals(1, imports.keys.length); |
| 65 Expect.isTrue(imports.keys.any((library) => | |
| 66 library.canonicalUri == | |
| 67 new Uri(path: MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME))); | |
| 68 } | 67 } |
| 69 | 68 |
| 70 void testWithMirrorRenamingMinify() { | 69 void testWithoutMirrorRenaming({bool minify}) { |
| 71 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: true); | 70 Compiler compiler = |
| 71 runCompiler(useMirrorHelperLibrary: false, minify: minify); |
| 72 | 72 |
| 73 DartBackend backend = compiler.backend; | 73 DartBackend backend = compiler.backend; |
| 74 Map<Node, String> renames = backend.renames; | 74 Map<Node, String> renames = backend.renames; |
| 75 Map<LibraryElement, String> imports = backend.imports; | |
| 76 | |
| 77 Node getNameFunctionNode = | |
| 78 backend.memberNodes.values.first.first.body.statements.nodes.head; | |
| 79 | |
| 80 Expect.equals(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION, | |
| 81 renames[getNameFunctionNode.expression.selector]); | |
| 82 Expect.equals(MirrorRenamer.MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME, | |
| 83 renames[getNameFunctionNode.expression.receiver]); | |
| 84 Expect.equals(2, imports.keys.length); | |
| 85 Expect.isTrue(imports.keys.any((library) => | |
| 86 library.canonicalUri == | |
| 87 new Uri(path: MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME))); | |
| 88 } | |
| 89 | |
| 90 void testWithoutMirrorRenaming() { | |
| 91 Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: false); | |
| 92 | |
| 93 DartBackend backend = compiler.backend; | |
| 94 Map<Node, String> renames = backend.renames; | |
| 95 Map<LibraryElement, String> imports = backend.imports; | |
| 96 | |
| 97 Node getNameFunctionNode = | |
| 98 backend.memberNodes.values.first.first.body.statements.nodes.head; | |
| 99 | |
| 100 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector)); | |
| 101 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver)); | |
| 102 Expect.equals(1, imports.keys.length); | |
| 103 } | |
| 104 | |
| 105 void testWithoutMirrorRenamingMinify() { | |
| 106 Compiler compiler = runCompiler(useMirrorHelperLibrary: false, minify: true); | |
| 107 | |
| 108 DartBackend backend = compiler.backend; | |
| 109 Map<Node, String> renames = backend.renames; | |
| 110 Map<LibraryElement, String> imports = backend.imports; | 75 Map<LibraryElement, String> imports = backend.imports; |
| 111 | 76 |
| 112 Node getNameFunctionNode = | 77 Node getNameFunctionNode = |
| 113 backend.memberNodes.values.first.first.body.statements.nodes.head; | 78 backend.memberNodes.values.first.first.body.statements.nodes.head; |
| 114 | 79 |
| 115 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector)); | 80 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector)); |
| 116 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver)); | 81 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver)); |
| 117 Expect.equals(1, imports.keys.length); | 82 Expect.equals(1, imports.keys.length); |
| 118 } | 83 } |
| 119 | 84 |
| 120 const MEMORY_SOURCE_FILES = const <String, String> { | 85 const MEMORY_SOURCE_FILES = const <String, String> { |
| 121 'main.dart': """ | 86 'main.dart': """ |
| 122 import 'dart:mirrors'; | 87 import 'dart:mirrors'; |
| 123 | 88 |
| 124 | |
| 125 class Foo { | 89 class Foo { |
| 126 noSuchMethod(Invocation invocation) { | 90 noSuchMethod(Invocation invocation) { |
| 127 MirrorSystem.getName(invocation.memberName); | 91 MirrorSystem.getName(invocation.memberName); |
| 128 } | 92 } |
| 129 } | 93 } |
| 130 | 94 |
| 131 void main() { | 95 void main() { |
| 132 new Foo().fisk(); | 96 new Foo().fisk(); |
| 133 } | 97 } |
| 134 """}; | 98 """}; |
| OLD | NEW |