Index: pkg/dev_compiler/web/web_command.dart |
diff --git a/pkg/dev_compiler/web/web_command.dart b/pkg/dev_compiler/web/web_command.dart |
index 1df3255ec61bf74ce53e0bccdf0b22b16f40c8b0..7aad19a2aef2dc8249e551575518f1c264f65102 100644 |
--- a/pkg/dev_compiler/web/web_command.dart |
+++ b/pkg/dev_compiler/web/web_command.dart |
@@ -7,6 +7,7 @@ library dev_compiler.web.web_command; |
import 'dart:async'; |
import 'dart:convert'; |
import 'dart:html' show HttpRequest; |
+import 'dart:typed_data'; |
import 'package:analyzer/dart/element/element.dart' |
show |
@@ -37,6 +38,21 @@ typedef void MessageHandler(Object message); |
@JS() |
@anonymous |
+class JSIterator<V> {} |
+ |
+@JS('Map') |
+class JSMap<K, V> { |
+ external V get(K v); |
+ external set(K k, V v); |
+ external JSIterator<K> keys(); |
+ external JSIterator<V> values(); |
+} |
+ |
+@JS('Array.from') |
+external List<V> iteratorToList<V>(JSIterator<V> iterator); |
+ |
+@JS() |
+@anonymous |
class CompileResult { |
external factory CompileResult( |
{String code, List<String> errors, bool isValid}); |
@@ -63,35 +79,43 @@ class WebCompileCommand extends Command { |
return requestSummaries; |
} |
- void requestSummaries(String summaryRoot, String sdkUrl, |
- List<String> summaryUrls, Function onCompileReady, Function onError) { |
- HttpRequest |
- .request(sdkUrl, |
- responseType: "arraybuffer", mimeType: "application/octet-stream") |
- .then((sdkRequest) { |
- var sdkBytes = sdkRequest.response.asUint8List(); |
- |
- // Map summary URLs to HttpRequests. |
- var summaryRequests = summaryUrls.map((summary) => new Future(() => |
- HttpRequest.request(summaryRoot + summary, |
- responseType: "arraybuffer", |
- mimeType: "application/octet-stream"))); |
- |
- Future.wait(summaryRequests).then((summaryResponses) { |
- // Map summary responses to summary bytes. |
- var summaryBytes = <List<int>>[]; |
- for (var response in summaryResponses) { |
- summaryBytes.add(response.response.asUint8List()); |
- } |
+ Future<Null> requestSummaries(String sdkUrl, JSMap<String, String> summaryMap, |
+ Function onCompileReady, Function onError) async { |
+ var sdkRequest; |
+ try { |
+ sdkRequest = await HttpRequest.request(sdkUrl, |
+ responseType: "arraybuffer", mimeType: "application/octet-stream"); |
+ } catch (error) { |
+ onError('Dart sdk summaries failed to load: $error. url: $sdkUrl'); |
+ return null; |
+ } |
- onCompileReady(setUpCompile(sdkBytes, summaryBytes, summaryUrls)); |
- }).catchError((error) => onError('Summaries failed to load: $error')); |
- }).catchError((error) => |
- onError('Dart sdk summaries failed to load: $error. url: $sdkUrl')); |
+ var sdkBytes = (sdkRequest.response as ByteBuffer).asUint8List(); |
+ |
+ // Map summary URLs to HttpRequests. |
+ var summaryRequests = iteratorToList(summaryMap.values()) |
+ .map((String summaryUrl) => HttpRequest.request(summaryUrl, |
+ responseType: "arraybuffer", mimeType: "application/octet-stream")) |
+ .toList(); |
+ var summaryResponses; |
+ try { |
+ summaryResponses = await Future.wait(summaryRequests); |
+ } catch (error) { |
+ print('Summaries failed to load: $error'); |
+ onError('Summaries failed to load: $error'); |
+ return null; |
+ } |
+ // Map summary responses to summary bytes. |
+ List<List<int>> summaryBytes = summaryResponses |
+ .map((response) => (response.response as ByteBuffer).asUint8List()) |
+ .toList(); |
+ print("Summaries loaded"); |
+ onCompileReady(setUpCompile( |
+ sdkBytes, summaryBytes, iteratorToList(summaryMap.keys()))); |
} |
List<Function> setUpCompile(List<int> sdkBytes, List<List<int>> summaryBytes, |
- List<String> summaryUrls) { |
+ List<String> moduleIds) { |
var dartSdkSummaryPath = '/dart-sdk/lib/_internal/web_sdk.sum'; |
var resourceProvider = new MemoryResourceProvider() |
@@ -106,9 +130,17 @@ class WebCompileCommand extends Command { |
resourceProvider: resourceProvider, recordDependencyInfo: true); |
for (var i = 0; i < summaryBytes.length; i++) { |
var bytes = summaryBytes[i]; |
- var url = '/' + summaryUrls[i]; |
- var summaryBundle = new PackageBundle.fromBuffer(bytes); |
- summaryDataStore.addBundle(url, summaryBundle); |
+ // Packages with no dart source files will have empty summaries which is fine. |
+ if (bytes.length == 0) continue; |
+ var url = '/${moduleIds[i]}.api.ds'; |
+ try { |
+ var summaryBundle = new PackageBundle.fromBuffer(bytes); |
+ summaryDataStore.addBundle(url, summaryBundle); |
+ } catch (e) { |
+ print( |
+ "XXX failed to load summary for $i, ${moduleIds[i]}, len = ${summaryBytes[i].length}"); |
+ continue; |
+ } |
} |
var summaryResolver = |
new InSummaryUriResolver(resourceProvider, summaryDataStore); |