| 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 accidentially leak code from deferred libraries but do | 5 // Test that we do not accidentially 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/src/compiler.dart'; | 10 import 'package:compiler/src/compiler.dart'; |
| 10 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
| 11 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
| 12 | 13 |
| 13 void main() { | 14 void main() { |
| 14 asyncTest(() async { | 15 asyncTest(() async { |
| 15 OutputCollector collector = new OutputCollector(); | 16 OutputCollector collector = new OutputCollector(); |
| 16 CompilationResult result = await runCompiler( | 17 CompilationResult result = await runCompiler( |
| 17 memorySourceFiles: MEMORY_SOURCE_FILES, outputProvider: collector); | 18 memorySourceFiles: MEMORY_SOURCE_FILES, outputProvider: collector); |
| 18 Compiler compiler = result.compiler; | 19 Compiler compiler = result.compiler; |
| 19 | 20 |
| 20 lookupLibrary(name) { | 21 lookupLibrary(name) { |
| 21 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 22 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
| 22 } | 23 } |
| 23 | 24 |
| 24 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 25 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
| 25 | 26 |
| 26 var lib1 = lookupLibrary("memory:lib1.dart"); | 27 var lib1 = lookupLibrary("memory:lib1.dart"); |
| 27 var inlineMeAway = lib1.find("inlineMeAway"); | 28 var inlineMeAway = lib1.find("inlineMeAway"); |
| 28 var ou_lib1 = outputUnitForElement(inlineMeAway); | 29 var ou_lib1 = outputUnitForElement(inlineMeAway); |
| 29 | 30 |
| 30 var lib3 = lookupLibrary("memory:lib3.dart"); | 31 var lib3 = lookupLibrary("memory:lib3.dart"); |
| 31 var sameContextInline = lib3.find("sameContextInline"); | 32 var sameContextInline = lib3.find("sameContextInline"); |
| 32 var ou_lib3 = outputUnitForElement(sameContextInline); | 33 var ou_lib3 = outputUnitForElement(sameContextInline); |
| 33 | 34 |
| 34 // Test that we actually got differnt output units. | 35 // Test that we actually got differnt output units. |
| 35 Expect.notEquals(ou_lib1.name, ou_lib3.name); | 36 Expect.notEquals(ou_lib1.name, ou_lib3.name); |
| 36 | 37 |
| 37 String mainOutput = collector.getOutput("", "js"); | 38 String mainOutput = collector.getOutput("", OutputType.js); |
| 38 String lib1Output = collector.getOutput("out_${ou_lib1.name}", "part.js"); | 39 String lib1Output = |
| 39 String lib3Output = collector.getOutput("out_${ou_lib3.name}", "part.js"); | 40 collector.getOutput("out_${ou_lib1.name}", OutputType.jsPart); |
| 41 String lib3Output = |
| 42 collector.getOutput("out_${ou_lib3.name}", OutputType.jsPart); |
| 40 | 43 |
| 41 RegExp re1 = new RegExp(r"inlined as empty"); | 44 RegExp re1 = new RegExp(r"inlined as empty"); |
| 42 RegExp re2 = new RegExp(r"inlined from main"); | 45 RegExp re2 = new RegExp(r"inlined from main"); |
| 43 RegExp re3 = new RegExp(r"inlined from lib1"); | 46 RegExp re3 = new RegExp(r"inlined from lib1"); |
| 44 RegExp re4 = new RegExp(r"inline same context"); | 47 RegExp re4 = new RegExp(r"inline same context"); |
| 45 | 48 |
| 46 // Test that inlineMeAway was inlined and its argument thus dropped. | 49 // Test that inlineMeAway was inlined and its argument thus dropped. |
| 47 Expect.isFalse(re1.hasMatch(mainOutput)); | 50 Expect.isFalse(re1.hasMatch(mainOutput)); |
| 48 | 51 |
| 49 // Test that inlineFromMain was inlined and thus the string moved to lib1. | 52 // Test that inlineFromMain was inlined and thus the string moved to lib1. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 import "lib3.dart" as lib3; | 102 import "lib3.dart" as lib3; |
| 100 | 103 |
| 101 test() { | 104 test() { |
| 102 print(lib3.sameContextInline("should be inlined")); | 105 print(lib3.sameContextInline("should be inlined")); |
| 103 } | 106 } |
| 104 """, | 107 """, |
| 105 "lib3.dart": """ | 108 "lib3.dart": """ |
| 106 sameContextInline(x) => "inline same context" + x; | 109 sameContextInline(x) => "inline same context" + x; |
| 107 """ | 110 """ |
| 108 }; | 111 }; |
| OLD | NEW |