| 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:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 import 'memory_source_file_helper.dart'; | 10 import 'memory_source_file_helper.dart'; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 55 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); | 58 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); |
| 59 Expect.isNotNull(main, "Could not find 'main'"); | 59 Expect.isNotNull(main, "Could not find 'main'"); |
| 60 compiler.deferredLoadTask.onResolutionComplete(main); | 60 compiler.deferredLoadTask.onResolutionComplete(main); |
| 61 | 61 |
| 62 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 62 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
| 63 | 63 |
| 64 var lib1 = lookupLibrary("memory:lib1.dart"); | 64 var lib1 = lookupLibrary("memory:lib1.dart"); |
| 65 var foo1 = lib1.find("foo"); | 65 var foo1 = lib1.find("finalVar"); |
| 66 var ou_lib1 = outputUnitForElement(foo1); | 66 var ou_lib1 = outputUnitForElement(foo1); |
| 67 | 67 |
| 68 var lib2 = lookupLibrary("memory:lib2.dart"); | |
| 69 var foo2 = lib2.find("foo"); | |
| 70 var ou_lib2 = outputUnitForElement(foo2); | |
| 71 | |
| 72 var fooMain = compiler.mainApp.find("foo"); | |
| 73 var ou_lib1_lib2 = outputUnitForElement(fooMain); | |
| 74 | |
| 75 String mainOutput = outputs["main.js"].mem.toString(); | 68 String mainOutput = outputs["main.js"].mem.toString(); |
| 76 String lib1Output = outputs["out_${ou_lib1.name}.part.js"].mem.toString(); | 69 String lib1Output = outputs["out_${ou_lib1.name}.part.js"].mem.toString(); |
| 77 String lib2Output = outputs["out_${ou_lib2.name}.part.js"].mem.toString(); | 70 // Test that the deferred globals are not inlined into the main file. |
| 78 String lib12Output = | |
| 79 outputs["out_${ou_lib1_lib2.name}.part.js"].mem.toString(); | |
| 80 // Test that the deferred constants are not inlined into the main file. | |
| 81 RegExp re1 = new RegExp(r"= .string1"); | 71 RegExp re1 = new RegExp(r"= .string1"); |
| 82 RegExp re2 = new RegExp(r"= .string2"); | 72 RegExp re2 = new RegExp(r"= .string2"); |
| 83 RegExp re3 = new RegExp(r"= 1010"); | |
| 84 Expect.isTrue(re1.hasMatch(lib1Output)); | 73 Expect.isTrue(re1.hasMatch(lib1Output)); |
| 85 Expect.isTrue(re2.hasMatch(lib1Output)); | 74 Expect.isTrue(re2.hasMatch(lib1Output)); |
| 86 Expect.isTrue(re3.hasMatch(lib1Output)); | |
| 87 Expect.isFalse(re1.hasMatch(mainOutput)); | 75 Expect.isFalse(re1.hasMatch(mainOutput)); |
| 88 Expect.isFalse(re2.hasMatch(mainOutput)); | 76 Expect.isFalse(re2.hasMatch(mainOutput)); |
| 89 Expect.isFalse(re3.hasMatch(mainOutput)); | |
| 90 // Test that the non-deferred constant is inlined. | |
| 91 Expect.isTrue(new RegExp(r"print\(.string3.\)").hasMatch(mainOutput)); | |
| 92 Expect.isFalse(new RegExp(r"= .string3").hasMatch(mainOutput)); | |
| 93 Expect.isTrue(new RegExp(r"print\(.string4.\)").hasMatch(mainOutput)); | |
| 94 | |
| 95 // C(1) is shared between main, lib1 and lib2. Test that lib1 and lib2 each | |
| 96 // has a reference to it. It is defined in the main output file. | |
| 97 Expect.isTrue(new RegExp(r"C.C_1 =").hasMatch(mainOutput)); | |
| 98 Expect.isFalse(new RegExp(r"= C.C_1").hasMatch(mainOutput)); | |
| 99 | |
| 100 Expect.isTrue(new RegExp(r"= C.C_1").hasMatch(lib1Output)); | |
| 101 Expect.isTrue(new RegExp(r"= C.C_1").hasMatch(lib2Output)); | |
| 102 | |
| 103 // C(2) is shared between lib1 and lib2, each of them has their own | |
| 104 // reference to it. | |
| 105 Expect.isFalse(new RegExp(r"= C.C_2").hasMatch(mainOutput)); | |
| 106 | |
| 107 Expect.isTrue(new RegExp(r"= C.C_2").hasMatch(lib1Output)); | |
| 108 Expect.isTrue(new RegExp(r"= C.C_2").hasMatch(lib2Output)); | |
| 109 Expect.isTrue(new RegExp(r"C.C_2 =").hasMatch(lib12Output)); | |
| 110 | |
| 111 // "string4" is shared between lib1 and lib2, but it can be inlined. | |
| 112 Expect.isTrue(new RegExp(r"= .string4").hasMatch(lib1Output)); | |
| 113 Expect.isTrue(new RegExp(r"= .string4").hasMatch(lib2Output)); | |
| 114 Expect.isFalse(new RegExp(r"= .string4").hasMatch(lib12Output)); | |
| 115 })); | 77 })); |
| 116 } | 78 } |
| 117 | 79 |
| 118 // Make sure that deferred constants are not inlined into the main hunk. | 80 // Make sure that deferred constants are not inlined into the main hunk. |
| 119 const Map MEMORY_SOURCE_FILES = const {"main.dart": """ | 81 const Map MEMORY_SOURCE_FILES = const {"main.dart": """ |
| 120 import "dart:async"; | 82 import "dart:async"; |
| 121 | 83 |
| 122 import 'lib1.dart' deferred as lib1; | 84 import 'lib1.dart' deferred as lib1; |
| 123 import 'lib2.dart' deferred as lib2; | |
| 124 | |
| 125 const c = "string3"; | |
| 126 | |
| 127 class C { | |
| 128 final p; | |
| 129 const C(this.p); | |
| 130 } | |
| 131 | |
| 132 foo() => print("main"); | |
| 133 | 85 |
| 134 void main() { | 86 void main() { |
| 135 lib1.loadLibrary().then((_) { | 87 lib1.loadLibrary().then((_) { |
| 136 lib2.loadLibrary().then((_) { | 88 print(lib1.finalVar); |
| 137 lib1.foo(); | 89 print(lib1.globalVar); |
| 138 lib2.foo(); | 90 lib1.globalVar = "foobar"; |
| 139 print(lib1.C1); | 91 print(lib1.globalVar); |
| 140 print(lib1.C2); | |
| 141 print(lib1.C.C3); | |
| 142 print(c); | |
| 143 print(lib1.C4); | |
| 144 print(lib2.C4); | |
| 145 print(lib1.C5); | |
| 146 print(lib2.C5); | |
| 147 print(lib1.C6); | |
| 148 print(lib2.C6); | |
| 149 print("string4"); | |
| 150 print(const C(1)); | |
| 151 }); | |
| 152 }); | 92 }); |
| 153 } | 93 } |
| 154 """, "lib1.dart": """ | 94 """, "lib1.dart": """ |
| 155 import "main.dart" as main; | 95 import "main.dart" as main; |
| 156 const C1 = "string1"; | 96 final finalVar = "string1"; |
| 157 const C2 = 1010; | 97 var globalVar = "string2"; |
| 158 class C { | |
| 159 static const C3 = "string2"; | |
| 160 } | |
| 161 const C4 = "string4"; | |
| 162 const C5 = const main.C(1); | |
| 163 const C6 = const main.C(2); | |
| 164 foo() { | |
| 165 print("lib1"); | |
| 166 main.foo(); | |
| 167 } | |
| 168 """, "lib2.dart": """ | |
| 169 import "main.dart" as main; | |
| 170 const C4 = "string4"; | |
| 171 const C5 = const main.C(1); | |
| 172 const C6 = const main.C(2); | |
| 173 foo() { | |
| 174 print("lib2"); | |
| 175 main.foo(); | |
| 176 } | |
| 177 """}; | 98 """}; |
| OLD | NEW |