Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 @JS() | 4 @JS() |
| 5 library dev_compiler.web.web_command; | 5 library dev_compiler.web.web_command; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:math' as math; | |
| 9 import 'dart:html' show HttpRequest; | 10 import 'dart:html' show HttpRequest; |
| 10 import 'dart:typed_data'; | 11 import 'dart:typed_data'; |
| 11 | 12 |
| 12 import 'package:analyzer/dart/element/element.dart' | 13 import 'package:analyzer/dart/element/element.dart' |
| 13 show | 14 show |
| 14 LibraryElement, | 15 LibraryElement, |
| 15 ImportElement, | 16 ImportElement, |
| 16 ShowElementCombinator, | 17 ShowElementCombinator, |
| 17 HideElementCombinator; | 18 HideElementCombinator; |
| 18 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; | 19 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 39 @JS() | 40 @JS() |
| 40 @anonymous | 41 @anonymous |
| 41 class JSIterator<V> {} | 42 class JSIterator<V> {} |
| 42 | 43 |
| 43 @JS('Map') | 44 @JS('Map') |
| 44 class JSMap<K, V> { | 45 class JSMap<K, V> { |
| 45 external V get(K v); | 46 external V get(K v); |
| 46 external set(K k, V v); | 47 external set(K k, V v); |
| 47 external JSIterator<K> keys(); | 48 external JSIterator<K> keys(); |
| 48 external JSIterator<V> values(); | 49 external JSIterator<V> values(); |
| 50 external int get size; | |
| 49 } | 51 } |
| 50 | 52 |
| 51 @JS('Array.from') | 53 @JS('Array.from') |
| 52 external List<V> iteratorToList<V>(JSIterator<V> iterator); | 54 external List<V> iteratorToList<V>(JSIterator<V> iterator); |
| 53 | 55 |
| 54 @JS() | 56 @JS() |
| 55 @anonymous | 57 @anonymous |
| 56 class CompileResult { | 58 class CompileResult { |
| 57 external factory CompileResult( | 59 external factory CompileResult( |
| 58 {String code, List<String> errors, bool isValid}); | 60 {String code, List<String> errors, bool isValid}); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 73 CompilerOptions.addArguments(argParser); | 75 CompilerOptions.addArguments(argParser); |
| 74 AnalyzerOptions.addArguments(argParser); | 76 AnalyzerOptions.addArguments(argParser); |
| 75 } | 77 } |
| 76 | 78 |
| 77 @override | 79 @override |
| 78 Function run() { | 80 Function run() { |
| 79 return requestSummaries; | 81 return requestSummaries; |
| 80 } | 82 } |
| 81 | 83 |
| 82 Future<Null> requestSummaries(String sdkUrl, JSMap<String, String> summaryMap, | 84 Future<Null> requestSummaries(String sdkUrl, JSMap<String, String> summaryMap, |
| 83 Function onCompileReady, Function onError) async { | 85 Function onCompileReady, Function onError, Function onProgress) async { |
| 84 var sdkRequest; | 86 var sdkRequest; |
| 87 var progress = 0; | |
| 88 int lastReported = 0; | |
| 89 // Add 1 to the count for the SDK summary. | |
| 90 var total = summaryMap.size + 1; | |
| 91 // No need to report after every summary is loaded. Posting about 100 | |
| 92 // progress updates should be more than sufficient for users to understand | |
| 93 // how long loading will take. | |
| 94 num progressDelta = math.max(total / 100, 1); | |
| 95 num nextProgressToReport = 0; | |
| 96 maybeReportProgress() { | |
| 97 if (nextProgressToReport > progress && progress != total) return; | |
| 98 nextProgressToReport += progressDelta; | |
| 99 if (onProgress != null) onProgress(progress, total); | |
| 100 } | |
| 101 | |
| 85 try { | 102 try { |
| 86 sdkRequest = await HttpRequest.request(sdkUrl, | 103 sdkRequest = await HttpRequest.request(sdkUrl, |
| 87 responseType: "arraybuffer", mimeType: "application/octet-stream"); | 104 responseType: "arraybuffer", mimeType: "application/octet-stream"); |
| 88 } catch (error) { | 105 } catch (error) { |
| 89 onError('Dart sdk summaries failed to load: $error. url: $sdkUrl'); | 106 onError('Dart sdk summaries failed to load: $error. url: $sdkUrl'); |
| 90 return null; | 107 return null; |
| 91 } | 108 } |
| 109 progress++; | |
| 110 maybeReportProgress(); | |
| 92 | 111 |
| 93 var sdkBytes = (sdkRequest.response as ByteBuffer).asUint8List(); | 112 var sdkBytes = (sdkRequest.response as ByteBuffer).asUint8List(); |
| 94 | 113 |
| 95 // Map summary URLs to HttpRequests. | 114 // Map summary URLs to HttpRequests. |
| 96 var summaryRequests = iteratorToList(summaryMap.values()) | 115 |
| 97 .map((String summaryUrl) => HttpRequest.request(summaryUrl, | 116 var summaryRequests = |
| 98 responseType: "arraybuffer", mimeType: "application/octet-stream")) | 117 iteratorToList(summaryMap.values()).map((String summaryUrl) async { |
| 99 .toList(); | 118 var ret = await HttpRequest.request(summaryUrl, |
|
Alan Knight
2017/05/13 00:22:41
Style guide frowns on abbreviations and non-meanin
| |
| 119 responseType: "arraybuffer", mimeType: "application/octet-stream"); | |
| 120 progress++; | |
| 121 maybeReportProgress(); | |
| 122 return ret; | |
| 123 }).toList(); | |
| 100 try { | 124 try { |
| 101 var summaryResponses = await Future.wait(summaryRequests); | 125 var summaryResponses = await Future.wait(summaryRequests); |
| 102 // Map summary responses to summary bytes. | 126 // Map summary responses to summary bytes. |
| 103 List<List<int>> summaryBytes = summaryResponses | 127 List<List<int>> summaryBytes = summaryResponses |
| 104 .map((response) => (response.response as ByteBuffer).asUint8List()) | 128 .map((response) => (response.response as ByteBuffer).asUint8List()) |
| 105 .toList(); | 129 .toList(); |
| 106 onCompileReady(setUpCompile( | 130 onCompileReady(setUpCompile( |
| 107 sdkBytes, summaryBytes, iteratorToList(summaryMap.keys()))); | 131 sdkBytes, summaryBytes, iteratorToList(summaryMap.keys()))); |
| 108 } catch (error) { | 132 } catch (error) { |
| 109 onError('Summaries failed to load: $error'); | 133 onError('Summaries failed to load: $error'); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 if (source is InSummarySource) { | 324 if (source is InSummarySource) { |
| 301 return source.summaryPath.substring(1).replaceAll('.api.ds', ''); | 325 return source.summaryPath.substring(1).replaceAll('.api.ds', ''); |
| 302 } | 326 } |
| 303 return source.toString().substring(1).replaceAll('.dart', ''); | 327 return source.toString().substring(1).replaceAll('.dart', ''); |
| 304 } | 328 } |
| 305 | 329 |
| 306 /// Thrown when the input source code has errors. | 330 /// Thrown when the input source code has errors. |
| 307 class CompileErrorException implements Exception { | 331 class CompileErrorException implements Exception { |
| 308 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; | 332 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; |
| 309 } | 333 } |
| OLD | NEW |