| 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 of the graph segmentation algorithm used by deferred loading | 5 // Test of the graph segmentation algorithm used by deferred loading |
| 6 // to determine which elements can be deferred and which libraries | 6 // to determine which elements can be deferred and which libraries |
| 7 // much be included in the initial download (loaded eagerly). | 7 // much be included in the initial download (loaded eagerly). |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 11 import 'package:async_helper/async_helper.dart'; | 11 import 'package:async_helper/async_helper.dart'; |
| 12 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
| 13 import 'package:compiler/src/compiler.dart' | 13 import 'package:compiler/src/compiler.dart' as dart2js; |
| 14 as dart2js; | |
| 15 | 14 |
| 16 Future runTest(String mainScript, test) async { | 15 Future runTest(String mainScript, test) async { |
| 17 CompilationResult result = await runCompiler( | 16 CompilationResult result = await runCompiler( |
| 18 entryPoint: Uri.parse(mainScript), | 17 entryPoint: Uri.parse(mainScript), |
| 19 memorySourceFiles: MEMORY_SOURCE_FILES); | 18 memorySourceFiles: MEMORY_SOURCE_FILES); |
| 20 test(result.compiler); | 19 test(result.compiler); |
| 21 } | 20 } |
| 22 | 21 |
| 23 lookupLibrary(compiler, name) { | 22 lookupLibrary(compiler, name) { |
| 24 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 23 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 95 |
| 97 void main() { | 96 void main() { |
| 98 lib1.loadLibrary().then((_) { | 97 lib1.loadLibrary().then((_) { |
| 99 lib1.foo1(); | 98 lib1.foo1(); |
| 100 }); | 99 }); |
| 101 lib2.loadLibrary().then((_) { | 100 lib2.loadLibrary().then((_) { |
| 102 lib2.foo2(); | 101 lib2.foo2(); |
| 103 }); | 102 }); |
| 104 } | 103 } |
| 105 """, | 104 """, |
| 106 "lib1.dart":""" | 105 "lib1.dart": """ |
| 107 library lib1; | 106 library lib1; |
| 108 import "dart:mirrors"; | 107 import "dart:mirrors"; |
| 109 | 108 |
| 110 const field1 = 42; | 109 const field1 = 42; |
| 111 | 110 |
| 112 void foo1() { | 111 void foo1() { |
| 113 var mirror = reflect(field1); | 112 var mirror = reflect(field1); |
| 114 mirror.invoke(null, null); | 113 mirror.invoke(null, null); |
| 115 } | 114 } |
| 116 """, | 115 """, |
| 117 "lib2.dart":""" | 116 "lib2.dart": """ |
| 118 library lib2; | 117 library lib2; |
| 119 @MirrorsUsed(targets: "field2") import "dart:mirrors"; | 118 @MirrorsUsed(targets: "field2") import "dart:mirrors"; |
| 120 | 119 |
| 121 const field2 = 42; | 120 const field2 = 42; |
| 122 | 121 |
| 123 void foo2() { | 122 void foo2() { |
| 124 var mirror = reflect(field2); | 123 var mirror = reflect(field2); |
| 125 mirror.invoke(null, null); | 124 mirror.invoke(null, null); |
| 126 } | 125 } |
| 127 """, | 126 """, |
| 128 // The elements C and f are named as targets, but there is no actual use of | 127 // The elements C and f are named as targets, but there is no actual use of |
| 129 // mirrors. | 128 // mirrors. |
| 130 "main2.dart": """ | 129 "main2.dart": """ |
| 131 import "lib.dart" deferred as lib; | 130 import "lib.dart" deferred as lib; |
| 132 | 131 |
| 133 @MirrorsUsed(targets: const ["C", "f"]) | 132 @MirrorsUsed(targets: const ["C", "f"]) |
| 134 import "dart:mirrors"; | 133 import "dart:mirrors"; |
| 135 | 134 |
| 136 class C {} | 135 class C {} |
| 137 | 136 |
| 138 var f = 3; | 137 var f = 3; |
| 139 | 138 |
| 140 void main() { | 139 void main() { |
| 141 | 140 |
| 142 } | 141 } |
| 143 """, | 142 """, |
| 144 "lib.dart": """ """, | 143 "lib.dart": """ """, |
| 145 // Lib3 has a MirrorsUsed annotation with a library. | 144 // Lib3 has a MirrorsUsed annotation with a library. |
| 146 // Check that that is handled correctly. | 145 // Check that that is handled correctly. |
| 147 "main3.dart": """ | 146 "main3.dart": """ |
| 148 library main3; | 147 library main3; |
| 149 | 148 |
| 150 import "lib3.dart" deferred as lib; | 149 import "lib3.dart" deferred as lib; |
| 151 | 150 |
| 152 class C {} | 151 class C {} |
| 153 | 152 |
| 154 class D {} | 153 class D {} |
| 155 | 154 |
| 156 f() {} | 155 f() {} |
| 157 | 156 |
| 158 void main() { | 157 void main() { |
| 159 lib.loadLibrary().then((_) { | 158 lib.loadLibrary().then((_) { |
| 160 lib.foo(); | 159 lib.foo(); |
| 161 }); | 160 }); |
| 162 } | 161 } |
| 163 """, | 162 """, |
| 164 "lib3.dart": """ | 163 "lib3.dart": """ |
| 165 @MirrorsUsed(targets: const ["main3.C"]) | 164 @MirrorsUsed(targets: const ["main3.C"]) |
| 166 import "dart:mirrors"; | 165 import "dart:mirrors"; |
| 167 | 166 |
| 168 foo() { | 167 foo() { |
| 169 currentMirrorSystem().findLibrary(#main3); | 168 currentMirrorSystem().findLibrary(#main3); |
| 170 } | 169 } |
| 171 """, | 170 """, |
| 172 // Check that exports and imports are handled correctly with mirrors. | 171 // Check that exports and imports are handled correctly with mirrors. |
| 173 "main4.dart": """ | 172 "main4.dart": """ |
| 174 library main3; | 173 library main3; |
| 175 | 174 |
| 176 @MirrorsUsed(targets: const ["lib5.foo","lib6.foo"]) | 175 @MirrorsUsed(targets: const ["lib5.foo","lib6.foo"]) |
| 177 import "dart:mirrors"; | 176 import "dart:mirrors"; |
| 178 | 177 |
| 179 import "lib4.dart" deferred as lib; | 178 import "lib4.dart" deferred as lib; |
| 180 | 179 |
| 181 void main() { | 180 void main() { |
| 182 lib.loadLibrary().then((_) { | 181 lib.loadLibrary().then((_) { |
| 183 currentMirrorSystem().findLibrary(#lib5); | 182 currentMirrorSystem().findLibrary(#lib5); |
| 184 }); | 183 }); |
| 185 } | 184 } |
| 186 """, | 185 """, |
| 187 "lib4.dart": """ | 186 "lib4.dart": """ |
| 188 import "lib5.dart"; | 187 import "lib5.dart"; |
| 189 export "lib6.dart"; | 188 export "lib6.dart"; |
| 190 | 189 |
| 191 """, | 190 """, |
| 192 "lib5.dart": """ | 191 "lib5.dart": """ |
| 193 library lib5; | 192 library lib5; |
| 194 | 193 |
| 195 foo() {} | 194 foo() {} |
| 196 """, | 195 """, |
| 197 "lib6.dart": """ | 196 "lib6.dart": """ |
| 198 library lib6; | 197 library lib6; |
| 199 | 198 |
| 200 foo() {} | 199 foo() {} |
| 201 """, | 200 """, |
| 202 }; | 201 }; |
| OLD | NEW |