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 library dart2js.test.memory_source_file_helper; | 5 library dart2js.test.memory_source_file_helper; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 export 'dart:io' show Platform; | 9 export 'dart:io' show Platform; |
10 | 10 |
11 export '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' | 11 export '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' |
12 show Compiler; | 12 show Compiler; |
13 | 13 |
14 export '../../../sdk/lib/_internal/compiler/implementation/filenames.dart' | 14 export '../../../sdk/lib/_internal/compiler/implementation/filenames.dart' |
15 show currentDirectory, nativeToUriPath; | 15 show currentDirectory, nativeToUriPath; |
16 | 16 |
17 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart' | 17 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart' |
18 show SourceFile; | 18 show SourceFile; |
19 | 19 |
20 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart' | 20 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart' |
21 show SourceFileProvider; | 21 show SourceFileProvider; |
22 | 22 |
23 export '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart' | 23 export '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart' |
24 show SourceFileProvider, FormattingDiagnosticHandler; | 24 show SourceFileProvider, FormattingDiagnosticHandler; |
25 | 25 |
26 class MemorySourceFileProvider extends SourceFileProvider { | 26 class MemorySourceFileProvider extends SourceFileProvider { |
27 static Map MEMORY_SOURCE_FILES; | 27 final Map<String, String> memorySourceFiles; |
| 28 |
| 29 MemorySourceFileProvider(Map<String, String> this.memorySourceFiles); |
| 30 |
28 Future<String> readStringFromUri(Uri resourceUri) { | 31 Future<String> readStringFromUri(Uri resourceUri) { |
29 if (resourceUri.scheme != 'memory') { | 32 if (resourceUri.scheme != 'memory') { |
30 return super.readStringFromUri(resourceUri); | 33 return super.readStringFromUri(resourceUri); |
31 } | 34 } |
32 String source = MEMORY_SOURCE_FILES[resourceUri.path]; | 35 String source = memorySourceFiles[resourceUri.path]; |
33 // TODO(ahe): Return new Future.error(...) ? | 36 // TODO(ahe): Return new Future.error(...) ? |
34 if (source == null) throw 'No such file $resourceUri'; | 37 if (source == null) return new Future.error('No such file $resourceUri'); |
35 String resourceName = '$resourceUri'; | 38 String resourceName = '$resourceUri'; |
36 this.sourceFiles[resourceName] = new SourceFile(resourceName, source); | 39 this.sourceFiles[resourceName] = new SourceFile(resourceName, source); |
37 return new Future.value(source); | 40 return new Future.value(source); |
38 } | 41 } |
39 } | 42 } |
OLD | NEW |