Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: tests/compiler/dart2js/memory_source_file_helper.dart

Issue 2897903003: Support loading binary data in dart2js (Closed)
Patch Set: Updated cf. comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 export 'dart:io' show Platform; 8 export 'dart:io' show Platform;
9 9
10 import 'package:compiler/compiler_new.dart';
11
10 export 'package:compiler/src/apiimpl.dart' show CompilerImpl; 12 export 'package:compiler/src/apiimpl.dart' show CompilerImpl;
11 13
12 export 'package:compiler/src/filenames.dart' show currentDirectory; 14 export 'package:compiler/src/filenames.dart' show currentDirectory;
13 15
14 import 'package:compiler/src/io/source_file.dart' 16 import 'package:compiler/src/io/source_file.dart'
15 show StringSourceFile, SourceFile, Utf8BytesSourceFile; 17 show Binary, StringSourceFile, SourceFile, Utf8BytesSourceFile;
16 18
17 import 'package:compiler/src/source_file_provider.dart' show SourceFileProvider; 19 import 'package:compiler/src/source_file_provider.dart' show SourceFileProvider;
18 20
19 export 'package:compiler/src/source_file_provider.dart' 21 export 'package:compiler/src/source_file_provider.dart'
20 show SourceFileProvider, FormattingDiagnosticHandler; 22 show SourceFileProvider, FormattingDiagnosticHandler;
21 23
22 class MemorySourceFileProvider extends SourceFileProvider { 24 class MemorySourceFileProvider extends SourceFileProvider {
23 Map<String, dynamic> memorySourceFiles; 25 Map<String, dynamic> memorySourceFiles;
24 26
25 /// MemorySourceFiles can contain maps of file names to string contents or 27 /// MemorySourceFiles can contain maps of file names to string contents or
26 /// file names to binary contents. 28 /// file names to binary contents.
27 MemorySourceFileProvider(Map<String, dynamic> this.memorySourceFiles); 29 MemorySourceFileProvider(Map<String, dynamic> this.memorySourceFiles);
28 30
29 Future<List<int>> readUtf8BytesFromUri(Uri resourceUri) { 31 Future<Input> readBytesFromUri(Uri resourceUri, InputKind inputKind) {
30 if (resourceUri.scheme != 'memory') { 32 if (resourceUri.scheme != 'memory') {
31 return super.readUtf8BytesFromUri(resourceUri); 33 return super.readBytesFromUri(resourceUri, inputKind);
32 } 34 }
33 var source = memorySourceFiles[resourceUri.path]; 35 var source = memorySourceFiles[resourceUri.path];
34 if (source == null) { 36 if (source == null) {
35 return new Future.error(new Exception( 37 return new Future.error(new Exception(
36 'No such memory file $resourceUri in ${memorySourceFiles.keys}')); 38 'No such memory file $resourceUri in ${memorySourceFiles.keys}'));
37 } 39 }
38 var sourceFile; 40 Input input;
39 if (source is String) { 41 switch (inputKind) {
40 sourceFile = new StringSourceFile.fromUri(resourceUri, source); 42 case InputKind.utf8:
41 } else { 43 if (source is String) {
42 sourceFile = new Utf8BytesSourceFile(resourceUri, source); 44 input = new StringSourceFile.fromUri(resourceUri, source);
45 } else {
46 input = new Utf8BytesSourceFile(resourceUri, source);
47 }
48 break;
49 case InputKind.binary:
50 if (source is String) {
51 source = source.codeUnits;
52 }
53 input = new Binary(resourceUri, source);
54 break;
43 } 55 }
44 this.sourceFiles[resourceUri] = sourceFile; 56 this.sourceFiles[resourceUri] = input;
45 return new Future.value(source); 57 return new Future.value(input);
46 } 58 }
47 59
48 Future<List<int>> call(Uri resourceUri) => readUtf8BytesFromUri(resourceUri); 60 //Future<List<int>> call(Uri resourceUri) => readBytesFromUri(resourceUri, Inp utKind.utf8);
49 61
50 SourceFile getSourceFile(Uri resourceUri) { 62 SourceFile getSourceFile(Uri resourceUri) {
51 if (resourceUri.scheme != 'memory') { 63 if (resourceUri.scheme != 'memory') {
52 return super.getSourceFile(resourceUri); 64 return super.getSourceFile(resourceUri);
53 } 65 }
54 var source = memorySourceFiles[resourceUri.path]; 66 var source = memorySourceFiles[resourceUri.path];
55 if (source == null) { 67 if (source == null) {
56 throw new Exception( 68 throw new Exception(
57 'No such memory file $resourceUri in ${memorySourceFiles.keys}'); 69 'No such memory file $resourceUri in ${memorySourceFiles.keys}');
58 } 70 }
59 if (source is String) { 71 if (source is String) {
60 return new StringSourceFile.fromUri(resourceUri, source); 72 return new StringSourceFile.fromUri(resourceUri, source);
61 } 73 }
62 return new Utf8BytesSourceFile(resourceUri, source); 74 return new Utf8BytesSourceFile(resourceUri, source);
63 } 75 }
64 76
65 @override 77 @override
66 Future readFromUri(Uri resourceUri) => readUtf8BytesFromUri(resourceUri); 78 Future<Input> readFromUri(Uri resourceUri,
79 {InputKind inputKind: InputKind.utf8}) =>
80 readBytesFromUri(resourceUri, inputKind);
67 } 81 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/library_resolution_test.dart ('k') | tests/compiler/dart2js/missing_file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698