OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Test that we do not accidentally leak code from deferred libraries but do | 5 // Test that we do not accidentally leak code from deferred libraries but do |
6 // allow inlining of empty functions and from main. | 6 // allow inlining of empty functions and from main. |
7 | 7 |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'package:compiler/compiler_new.dart'; | 9 import 'package:compiler/compiler_new.dart'; |
10 import 'package:compiler/src/compiler.dart'; | 10 import 'package:compiler/src/compiler.dart'; |
11 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
12 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
13 | 13 |
14 void main() { | 14 void main() { |
15 asyncTest(() async { | 15 asyncTest(() async { |
16 OutputCollector collector = new OutputCollector(); | 16 OutputCollector collector = new OutputCollector(); |
17 CompilationResult result = await runCompiler( | 17 CompilationResult result = await runCompiler( |
18 memorySourceFiles: MEMORY_SOURCE_FILES, outputProvider: collector); | 18 memorySourceFiles: MEMORY_SOURCE_FILES, outputProvider: collector); |
19 Compiler compiler = result.compiler; | 19 Compiler compiler = result.compiler; |
20 | 20 |
21 lookupLibrary(name) { | 21 lookupLibrary(name) { |
22 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 22 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
23 } | 23 } |
24 | 24 |
25 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 25 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
26 | 26 |
27 var lib1 = lookupLibrary("memory:lib1.dart"); | 27 dynamic lib1 = lookupLibrary("memory:lib1.dart"); |
28 var inlineMeAway = lib1.find("inlineMeAway"); | 28 var inlineMeAway = lib1.find("inlineMeAway"); |
29 var ou_lib1 = outputUnitForElement(inlineMeAway); | 29 var ou_lib1 = outputUnitForElement(inlineMeAway); |
30 | 30 |
31 var lib3 = lookupLibrary("memory:lib3.dart"); | 31 dynamic lib3 = lookupLibrary("memory:lib3.dart"); |
32 var sameContextInline = lib3.find("sameContextInline"); | 32 var sameContextInline = lib3.find("sameContextInline"); |
33 var ou_lib3 = outputUnitForElement(sameContextInline); | 33 var ou_lib3 = outputUnitForElement(sameContextInline); |
34 | 34 |
35 // Test that we actually got different output units. | 35 // Test that we actually got different output units. |
36 Expect.notEquals(ou_lib1.name, ou_lib3.name); | 36 Expect.notEquals(ou_lib1.name, ou_lib3.name); |
37 | 37 |
38 String mainOutput = collector.getOutput("", OutputType.js); | 38 String mainOutput = collector.getOutput("", OutputType.js); |
39 String lib1Output = | 39 String lib1Output = |
40 collector.getOutput("out_${ou_lib1.name}", OutputType.jsPart); | 40 collector.getOutput("out_${ou_lib1.name}", OutputType.jsPart); |
41 String lib3Output = | 41 String lib3Output = |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 import "lib3.dart" as lib3; | 102 import "lib3.dart" as lib3; |
103 | 103 |
104 test() { | 104 test() { |
105 print(lib3.sameContextInline("should be inlined")); | 105 print(lib3.sameContextInline("should be inlined")); |
106 } | 106 } |
107 """, | 107 """, |
108 "lib3.dart": """ | 108 "lib3.dart": """ |
109 sameContextInline(x) => "inline same context" + x; | 109 sameContextInline(x) => "inline same context" + x; |
110 """ | 110 """ |
111 }; | 111 }; |
OLD | NEW |