| 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/elements/elements.dart' | 12 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart' |
| 11 show | 13 show |
| 12 Element, LibraryElement, ClassElement; | 14 Element, LibraryElement, ClassElement; |
| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 28 SourceString; | 30 SourceString; |
| 29 | 31 |
| 30 | 32 |
| 31 main() { | 33 main() { |
| 32 testWithMirrorRenaming(minify: true); | 34 testWithMirrorRenaming(minify: true); |
| 33 testWithMirrorRenaming(minify: false); | 35 testWithMirrorRenaming(minify: false); |
| 34 testWithoutMirrorRenaming(minify: true); | 36 testWithoutMirrorRenaming(minify: true); |
| 35 testWithoutMirrorRenaming(minify: false); | 37 testWithoutMirrorRenaming(minify: false); |
| 36 } | 38 } |
| 37 | 39 |
| 38 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { | 40 Future<Compiler> runCompiler({useMirrorHelperLibrary: false, minify: false}) { |
| 39 List<String> options = ['--output-type=dart']; | 41 List<String> options = ['--output-type=dart']; |
| 40 if (minify) { | 42 if (minify) { |
| 41 options.add('--minify'); | 43 options.add('--minify'); |
| 42 } | 44 } |
| 43 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); | 45 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); |
| 44 DartBackend backend = compiler.backend; | 46 DartBackend backend = compiler.backend; |
| 45 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; | 47 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
| 46 compiler.runCompiler(Uri.parse('memory:main.dart')); | 48 return |
| 47 return compiler; | 49 compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler); |
| 48 } | 50 } |
| 49 | 51 |
| 50 void testWithMirrorRenaming({bool minify}) { | 52 void testWithMirrorRenaming({bool minify}) { |
| 51 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify); | 53 asyncTest(() => runCompiler(useMirrorHelperLibrary: true, minify: minify). |
| 54 then((Compiler compiler) { |
| 52 | 55 |
| 53 DartBackend backend = compiler.backend; | 56 DartBackend backend = compiler.backend; |
| 54 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; | 57 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; |
| 55 Map<Node, String> renames = backend.renames; | 58 Map<Node, String> renames = backend.renames; |
| 56 Map<LibraryElement, String> imports = backend.imports; | 59 Map<LibraryElement, String> imports = backend.imports; |
| 57 | 60 |
| 58 Node getNameFunctionNode = | 61 Node getNameFunctionNode = |
| 59 backend.memberNodes.values.first.first.body.statements.nodes.head; | 62 backend.memberNodes.values.first.first.body.statements.nodes.head; |
| 60 | 63 |
| 61 Expect.equals( | 64 Expect.equals( |
| 62 const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION), | 65 const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION), |
| 63 mirrorRenamer.symbols[renames[getNameFunctionNode.expression.selector]]); | 66 mirrorRenamer.symbols[renames[getNameFunctionNode.expression.selector]])
; |
| 64 Expect.equals("", | 67 Expect.equals("", |
| 65 renames[getNameFunctionNode.expression.receiver]); | 68 renames[getNameFunctionNode.expression.receiver]); |
| 66 Expect.equals(1, imports.keys.length); | 69 Expect.equals(1, imports.keys.length); |
| 70 })); |
| 67 } | 71 } |
| 68 | 72 |
| 69 void testWithoutMirrorRenaming({bool minify}) { | 73 void testWithoutMirrorRenaming({bool minify}) { |
| 70 Compiler compiler = | 74 asyncTest(() => runCompiler(useMirrorHelperLibrary: false, minify: minify). |
| 71 runCompiler(useMirrorHelperLibrary: false, minify: minify); | 75 then((Compiler compiler) { |
| 72 | 76 |
| 73 DartBackend backend = compiler.backend; | 77 DartBackend backend = compiler.backend; |
| 74 Map<Node, String> renames = backend.renames; | 78 Map<Node, String> renames = backend.renames; |
| 75 Map<LibraryElement, String> imports = backend.imports; | 79 Map<LibraryElement, String> imports = backend.imports; |
| 76 | 80 |
| 77 Node getNameFunctionNode = | 81 Node getNameFunctionNode = |
| 78 backend.memberNodes.values.first.first.body.statements.nodes.head; | 82 backend.memberNodes.values.first.first.body.statements.nodes.head; |
| 79 | 83 |
| 80 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector)); | 84 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector))
; |
| 81 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver)); | 85 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver))
; |
| 82 Expect.equals(1, imports.keys.length); | 86 Expect.equals(1, imports.keys.length); |
| 87 })); |
| 83 } | 88 } |
| 84 | 89 |
| 85 const MEMORY_SOURCE_FILES = const <String, String> { | 90 const MEMORY_SOURCE_FILES = const <String, String> { |
| 86 'main.dart': """ | 91 'main.dart': """ |
| 87 import 'dart:mirrors'; | 92 import 'dart:mirrors'; |
| 88 | 93 |
| 89 class Foo { | 94 class Foo { |
| 90 noSuchMethod(Invocation invocation) { | 95 noSuchMethod(Invocation invocation) { |
| 91 MirrorSystem.getName(invocation.memberName); | 96 MirrorSystem.getName(invocation.memberName); |
| 92 } | 97 } |
| 93 } | 98 } |
| 94 | 99 |
| 95 void main() { | 100 void main() { |
| 96 new Foo().fisk(); | 101 new Foo().fisk(); |
| 97 } | 102 } |
| 98 """}; | 103 """}; |
| OLD | NEW |