| 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 'dart:async' show Future; | 9 import 'dart:async' show Future; |
| 10 import 'dart:uri' show Uri; | 10 import 'dart:uri' show Uri; |
| 11 import 'dart:io'; | 11 import 'dart:io'; |
| 12 | 12 |
| 13 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' | 13 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' |
| 14 show Compiler; | 14 show Compiler; |
| 15 | 15 |
| 16 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 16 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| 17 as dart2js; | 17 as dart2js; |
| 18 | 18 |
| 19 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart' | 19 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart' |
| 20 show getCurrentDirectory, nativeToUriPath; | 20 show currentDirectory, nativeToUriPath; |
| 21 | 21 |
| 22 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart' | 22 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart' |
| 23 show SourceFile; | 23 show SourceFile; |
| 24 | 24 |
| 25 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart' | 25 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart' |
| 26 show FormattingDiagnosticHandler, | 26 show FormattingDiagnosticHandler, |
| 27 SourceFileProvider; | 27 SourceFileProvider; |
| 28 | 28 |
| 29 class MemorySourceFileProvider extends SourceFileProvider { | 29 class MemorySourceFileProvider extends SourceFileProvider { |
| 30 Future<String> readStringFromUri(Uri resourceUri) { | 30 Future<String> readStringFromUri(Uri resourceUri) { |
| 31 if (resourceUri.scheme != 'memory') { | 31 if (resourceUri.scheme != 'memory') { |
| 32 return super.readStringFromUri(resourceUri); | 32 return super.readStringFromUri(resourceUri); |
| 33 } | 33 } |
| 34 String source = MEMORY_SOURCE_FILES[resourceUri.path]; | 34 String source = MEMORY_SOURCE_FILES[resourceUri.path]; |
| 35 // TODO(ahe): Return new Future.immediateError(...) ? | 35 // TODO(ahe): Return new Future.immediateError(...) ? |
| 36 if (source == null) throw 'No such file $resourceUri'; | 36 if (source == null) throw 'No such file $resourceUri'; |
| 37 String resourceName = '$resourceUri'; | 37 String resourceName = '$resourceUri'; |
| 38 this.sourceFiles[resourceName] = new SourceFile(resourceName, source); | 38 this.sourceFiles[resourceName] = new SourceFile(resourceName, source); |
| 39 return new Future.immediate(source); | 39 return new Future.immediate(source); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void main() { | 43 void main() { |
| 44 Uri cwd = getCurrentDirectory(); | 44 Uri script = currentDirectory.resolve(nativeToUriPath(new Options().script)); |
| 45 Uri script = cwd.resolve(nativeToUriPath(new Options().script)); | |
| 46 Uri libraryRoot = script.resolve('../../../sdk/'); | 45 Uri libraryRoot = script.resolve('../../../sdk/'); |
| 47 Uri packageRoot = script.resolve('./packages/'); | 46 Uri packageRoot = script.resolve('./packages/'); |
| 48 | 47 |
| 49 var provider = new MemorySourceFileProvider(); | 48 var provider = new MemorySourceFileProvider(); |
| 50 var handler = new FormattingDiagnosticHandler(provider); | 49 var handler = new FormattingDiagnosticHandler(provider); |
| 51 | 50 |
| 52 Compiler compiler = new Compiler(provider.readStringFromUri, | 51 Compiler compiler = new Compiler(provider.readStringFromUri, |
| 53 (name, extension) => null, | 52 (name, extension) => null, |
| 54 handler.diagnosticHandler, | 53 handler.diagnosticHandler, |
| 55 libraryRoot, | 54 libraryRoot, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 class MyClass { | 96 class MyClass { |
| 98 const MyClass(); | 97 const MyClass(); |
| 99 | 98 |
| 100 foo(x) { | 99 foo(x) { |
| 101 new Expando(); | 100 new Expando(); |
| 102 return (x - 3) ~/ 2; | 101 return (x - 3) ~/ 2; |
| 103 } | 102 } |
| 104 } | 103 } |
| 105 """, | 104 """, |
| 106 }; | 105 }; |
| OLD | NEW |