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

Unified Diff: pkg/compiler/lib/src/old_to_new_api.dart

Issue 2897903003: Support loading binary data in dart2js (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/old_to_new_api.dart
diff --git a/pkg/compiler/lib/src/old_to_new_api.dart b/pkg/compiler/lib/src/old_to_new_api.dart
index 939683d34fc6470df63d7ad2407b84f1255551ab..160739dafcc5bdef3bd5bc7a59fef9d5a56b1251 100644
--- a/pkg/compiler/lib/src/old_to_new_api.dart
+++ b/pkg/compiler/lib/src/old_to_new_api.dart
@@ -11,6 +11,7 @@ import 'dart:async' show EventSink, Future;
import '../compiler.dart';
import '../compiler_new.dart';
+import 'io/source_file.dart';
import 'null_compiler_output.dart' show NullSink;
/// Implementation of [CompilerInput] using a [CompilerInputProvider].
@@ -20,8 +21,27 @@ class LegacyCompilerInput implements CompilerInput {
LegacyCompilerInput(this._inputProvider);
@override
- Future readFromUri(Uri uri) {
- return _inputProvider(uri);
+ Future<Input> readFromUri(Uri uri, {InputKind inputKind: InputKind.utf8}) {
+ return _inputProvider(uri).then((/*String|List<int>*/ data) {
+ switch (inputKind) {
+ case InputKind.utf8:
+ SourceFile sourceFile;
+ if (data is List<int>) {
+ sourceFile = new Utf8BytesSourceFile(uri, data);
+ } else if (data is String) {
+ sourceFile = new StringSourceFile.fromUri(uri, data);
+ } else {
+ throw "Expected a 'String' or a 'List<int>' from the input "
+ "provider, but got: ${Error.safeToString(data)}.";
+ }
+ return sourceFile;
+ case InputKind.binary:
+ if (data is String) {
+ data = data.codeUnits;
+ }
+ return new Binary(uri, data);
+ }
+ });
}
}

Powered by Google App Engine
This is Rietveld 408576698