| 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..6ddda879637de5d7cc2df3fc4d0039a4bf0536f0 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,39 @@ 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();
|
| + try {
|
| + var summaryResponses = await Future.wait(summaryRequests);
|
| + // Map summary responses to summary bytes.
|
| + List<List<int>> summaryBytes = summaryResponses
|
| + .map((response) => (response.response as ByteBuffer).asUint8List())
|
| + .toList();
|
| + onCompileReady(setUpCompile(
|
| + sdkBytes, summaryBytes, iteratorToList(summaryMap.keys())));
|
| + } catch (error) {
|
| + onError('Summaries failed to load: $error');
|
| + }
|
| }
|
|
|
| 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,7 +126,11 @@ class WebCompileCommand extends Command {
|
| resourceProvider: resourceProvider, recordDependencyInfo: true);
|
| for (var i = 0; i < summaryBytes.length; i++) {
|
| var bytes = summaryBytes[i];
|
| - var url = '/' + summaryUrls[i];
|
| +
|
| + // Packages with no dart source files will have empty invalid summaries.
|
| + if (bytes.length == 0) continue;
|
| +
|
| + var url = '/${moduleIds[i]}.api.ds';
|
| var summaryBundle = new PackageBundle.fromBuffer(bytes);
|
| summaryDataStore.addBundle(url, summaryBundle);
|
| }
|
|
|