| 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 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:compiler/src/compiler.dart'; | 10 import 'package:compiler/src/compiler.dart'; |
| 11 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
| 12 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
| 13 | 13 |
| 14 void main() { | 14 void main() { |
| 15 deferredTest1(); | 15 deferredTest1(); |
| 16 deferredTest2(); | 16 deferredTest2(); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void deferredTest1() { | 19 void deferredTest1() { |
| 20 asyncTest(() async { | 20 asyncTest(() async { |
| 21 CompilationResult result = await runCompiler(memorySourceFiles: TEST1); | 21 CompilationResult result = await runCompiler(memorySourceFiles: TEST1); |
| 22 Compiler compiler = result.compiler; | 22 Compiler compiler = result.compiler; |
| 23 | 23 |
| 24 lookupLibrary(name) { | 24 lookupLibrary(name) { |
| 25 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 25 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 var main = compiler.mainFunction; | 28 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; |
| 29 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 29 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
| 30 | 30 |
| 31 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; | 31 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; |
| 32 var backend = compiler.backend; | 32 var backend = compiler.backend; |
| 33 var lib1 = lookupLibrary("memory:lib1.dart"); | 33 var lib1 = lookupLibrary("memory:lib1.dart"); |
| 34 var lib2 = lookupLibrary("memory:lib2.dart"); | 34 var lib2 = lookupLibrary("memory:lib2.dart"); |
| 35 var foo1 = lib1.find("foo1"); | 35 var foo1 = lib1.find("foo1"); |
| 36 var foo2 = lib2.find("foo2"); | 36 var foo2 = lib2.find("foo2"); |
| 37 | 37 |
| 38 Expect.notEquals(mainOutputUnit, outputUnitForElement(foo2)); | 38 Expect.notEquals(mainOutputUnit, outputUnitForElement(foo2)); |
| 39 }); | 39 }); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void deferredTest2() { | 42 void deferredTest2() { |
| 43 asyncTest(() async { | 43 asyncTest(() async { |
| 44 CompilationResult result = await runCompiler(memorySourceFiles: TEST2); | 44 CompilationResult result = await runCompiler(memorySourceFiles: TEST2); |
| 45 Compiler compiler = result.compiler; | 45 Compiler compiler = result.compiler; |
| 46 | 46 |
| 47 lookupLibrary(name) { | 47 lookupLibrary(name) { |
| 48 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 48 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 var main = compiler.mainFunction; | 51 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; |
| 52 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 52 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
| 53 | 53 |
| 54 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; | 54 var mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; |
| 55 var shared = lookupLibrary("memory:shared.dart"); | 55 var shared = lookupLibrary("memory:shared.dart"); |
| 56 var a = shared.find("A"); | 56 var a = shared.find("A"); |
| 57 | 57 |
| 58 Expect.equals(mainOutputUnit, outputUnitForElement(a)); | 58 Expect.equals(mainOutputUnit, outputUnitForElement(a)); |
| 59 }); | 59 }); |
| 60 } | 60 } |
| 61 | 61 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 import 'shared.dart'; | 109 import 'shared.dart'; |
| 110 | 110 |
| 111 toto() { print(new A()); } | 111 toto() { print(new A()); } |
| 112 """, | 112 """, |
| 113 "shared.dart": """ | 113 "shared.dart": """ |
| 114 class A {} | 114 class A {} |
| 115 class B extends A {} | 115 class B extends A {} |
| 116 foo(B b) => null; | 116 foo(B b) => null; |
| 117 """, | 117 """, |
| 118 }; | 118 }; |
| OLD | NEW |