Chromium Code Reviews| 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..f97770d04234ee172e37bd44b7aa9eab2c947050 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; |
|
vsm
2017/04/12 21:40:47
Type var to avoid dcall below.
Jacob
2017/04/15 02:26:49
fixed
|
| + 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"); |
|
vsm
2017/04/12 21:40:47
Where do prints go for the web compiler?
Jacob
2017/04/15 02:26:49
removed
|
| + 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,7 +130,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); |
| } |