OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 'package:async_helper/async_helper.dart'; |
| 10 import 'package:compiler/src/dart2jslib.dart'; |
| 11 import 'package:compiler/src/deferred_load.dart'; |
9 import 'package:expect/expect.dart'; | 12 import 'package:expect/expect.dart'; |
10 import "package:async_helper/async_helper.dart"; | 13 import 'memory_compiler.dart'; |
11 import 'memory_source_file_helper.dart'; | |
12 import "dart:async"; | |
13 | |
14 import 'package:compiler/src/dart2jslib.dart' | |
15 as dart2js; | |
16 | |
17 import 'package:compiler/src/deferred_load.dart'; | |
18 | |
19 class FakeOutputStream<T> extends EventSink<T> { | |
20 void add(T event) {} | |
21 void addError(T event, [StackTrace stackTrace]) {} | |
22 void close() {} | |
23 } | |
24 | 14 |
25 void main() { | 15 void main() { |
26 Uri script = currentDirectory.resolveUri(Platform.script); | 16 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES); |
27 Uri libraryRoot = script.resolve('../../../sdk/'); | |
28 Uri packageRoot = script.resolve('./packages/'); | |
29 | |
30 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); | |
31 var handler = new FormattingDiagnosticHandler(provider); | |
32 | |
33 Compiler compiler = new Compiler(provider.readStringFromUri, | |
34 (name, extension) => new FakeOutputStream(), | |
35 handler.diagnosticHandler, | |
36 libraryRoot, | |
37 packageRoot, | |
38 [], | |
39 {}); | |
40 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { | 17 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { |
41 lookupLibrary(name) { | 18 lookupLibrary(name) { |
42 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 19 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
43 } | 20 } |
44 | 21 |
45 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); | 22 var main = compiler.mainApp.find(Compiler.MAIN); |
46 Expect.isNotNull(main, "Could not find 'main'"); | 23 Expect.isNotNull(main, "Could not find 'main'"); |
47 compiler.deferredLoadTask.onResolutionComplete(main); | 24 compiler.deferredLoadTask.onResolutionComplete(main); |
48 | 25 |
49 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 26 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
50 | 27 |
51 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; | 28 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; |
52 var backend = compiler.backend; | 29 var backend = compiler.backend; |
53 var classes = backend.emitter.neededClasses; | 30 var classes = backend.emitter.neededClasses; |
54 var inputElement = classes.where((e) => e.name == 'InputElement').single; | 31 var inputElement = classes.where((e) => e.name == 'InputElement').single; |
55 var lib1 = lookupLibrary("memory:lib1.dart"); | 32 var lib1 = lookupLibrary("memory:lib1.dart"); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 139 |
163 bar1() { | 140 bar1() { |
164 return "hello"; | 141 return "hello"; |
165 } | 142 } |
166 | 143 |
167 bar2() { | 144 bar2() { |
168 return 2; | 145 return 2; |
169 } | 146 } |
170 """, | 147 """, |
171 }; | 148 }; |
OLD | NEW |