| 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 the additional runtime type support is output to the right | 5 // Test that the additional runtime type support is output to the right | 
| 6 // Files when using deferred loading. | 6 // Files when using deferred loading. | 
| 7 | 7 | 
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; | 
| 9 import 'package:compiler/src/compiler.dart'; | 9 import 'package:compiler/src/compiler.dart'; | 
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; | 
| 11 import 'memory_compiler.dart'; | 11 import 'memory_compiler.dart'; | 
| 12 import 'output_collector.dart'; | 12 import 'output_collector.dart'; | 
| 13 | 13 | 
| 14 void main() { | 14 void main() { | 
| 15   OutputCollector collector = new OutputCollector(); | 15   OutputCollector collector = new OutputCollector(); | 
| 16   asyncTest(() async { | 16   asyncTest(() async { | 
| 17     CompilationResult result = await runCompiler( | 17     CompilationResult result = await runCompiler( | 
| 18         memorySourceFiles: MEMORY_SOURCE_FILES, | 18         memorySourceFiles: MEMORY_SOURCE_FILES, outputProvider: collector); | 
| 19         outputProvider: collector); |  | 
| 20     Compiler compiler = result.compiler; | 19     Compiler compiler = result.compiler; | 
| 21     lookupLibrary(name) { | 20     lookupLibrary(name) { | 
| 22       return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 21       return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 
| 23     } | 22     } | 
| 24 | 23 | 
| 25     var main = compiler.mainFunction; | 24     var main = compiler.mainFunction; | 
| 26     Expect.isNotNull(main, "Could not find 'main'"); | 25     Expect.isNotNull(main, "Could not find 'main'"); | 
| 27     compiler.deferredLoadTask.onResolutionComplete(main); | 26     compiler.deferredLoadTask.onResolutionComplete(main); | 
| 28 | 27 | 
| 29     var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 28     var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 
| 30 | 29 | 
| 31     var lib1 = lookupLibrary("memory:lib1.dart"); | 30     var lib1 = lookupLibrary("memory:lib1.dart"); | 
| 32     var foo1 = lib1.find("finalVar"); | 31     var foo1 = lib1.find("finalVar"); | 
| 33     var ou_lib1 = outputUnitForElement(foo1); | 32     var ou_lib1 = outputUnitForElement(foo1); | 
| 34 | 33 | 
| 35     String mainOutput = collector.getOutput("", "js"); | 34     String mainOutput = collector.getOutput("", "js"); | 
| 36     String lib1Output = collector.getOutput("out_${ou_lib1.name}", "part.js"); | 35     String lib1Output = collector.getOutput("out_${ou_lib1.name}", "part.js"); | 
| 37     // Test that the deferred globals are not inlined into the main file. | 36     // Test that the deferred globals are not inlined into the main file. | 
| 38     RegExp re1 = new RegExp(r"= .string1"); | 37     RegExp re1 = new RegExp(r"= .string1"); | 
| 39     RegExp re2 = new RegExp(r"= .string2"); | 38     RegExp re2 = new RegExp(r"= .string2"); | 
| 40     Expect.isTrue(re1.hasMatch(lib1Output)); | 39     Expect.isTrue(re1.hasMatch(lib1Output)); | 
| 41     Expect.isTrue(re2.hasMatch(lib1Output)); | 40     Expect.isTrue(re2.hasMatch(lib1Output)); | 
| 42     Expect.isFalse(re1.hasMatch(mainOutput)); | 41     Expect.isFalse(re1.hasMatch(mainOutput)); | 
| 43     Expect.isFalse(re2.hasMatch(mainOutput)); | 42     Expect.isFalse(re2.hasMatch(mainOutput)); | 
| 44   }); | 43   }); | 
| 45 } | 44 } | 
| 46 | 45 | 
| 47 // Make sure that deferred constants are not inlined into the main hunk. | 46 // Make sure that deferred constants are not inlined into the main hunk. | 
| 48 const Map MEMORY_SOURCE_FILES = const {"main.dart": """ | 47 const Map MEMORY_SOURCE_FILES = const { | 
|  | 48   "main.dart": """ | 
| 49 import "dart:async"; | 49 import "dart:async"; | 
| 50 | 50 | 
| 51 import 'lib1.dart' deferred as lib1; | 51 import 'lib1.dart' deferred as lib1; | 
| 52 | 52 | 
| 53 void main() { | 53 void main() { | 
| 54   lib1.loadLibrary().then((_) { | 54   lib1.loadLibrary().then((_) { | 
| 55     print(lib1.finalVar); | 55     print(lib1.finalVar); | 
| 56     print(lib1.globalVar); | 56     print(lib1.globalVar); | 
| 57     lib1.globalVar = "foobar"; | 57     lib1.globalVar = "foobar"; | 
| 58     print(lib1.globalVar); | 58     print(lib1.globalVar); | 
| 59   }); | 59   }); | 
| 60 } | 60 } | 
| 61 """, "lib1.dart": """ | 61 """, | 
|  | 62   "lib1.dart": """ | 
| 62 import "main.dart" as main; | 63 import "main.dart" as main; | 
| 63 final finalVar = "string1"; | 64 final finalVar = "string1"; | 
| 64 var globalVar = "string2"; | 65 var globalVar = "string2"; | 
| 65 """}; | 66 """ | 
|  | 67 }; | 
| OLD | NEW | 
|---|