| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 | 4 |
| 5 library trydart.compilation; | 5 library trydart.compilation; |
| 6 | 6 |
| 7 import 'dart:html' show | 7 import 'dart:html' show |
| 8 Blob, | 8 Blob, |
| 9 Element, | 9 Element, |
| 10 ErrorEvent, | 10 ErrorEvent, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 class CompilationProcess { | 72 class CompilationProcess { |
| 73 final String source; | 73 final String source; |
| 74 final Element console; | 74 final Element console; |
| 75 final ReceivePort receivePort = new ReceivePort(); | 75 final ReceivePort receivePort = new ReceivePort(); |
| 76 final Set<String> seenMessages = new Set<String>(); | 76 final Set<String> seenMessages = new Set<String>(); |
| 77 bool isDone = false; | 77 bool isDone = false; |
| 78 bool usesDartHtml = false; | 78 bool usesDartHtml = false; |
| 79 Worker worker; | 79 Worker worker; |
| 80 List<String> objectUrls = <String>[]; | 80 List<String> objectUrls = <String>[]; |
| 81 String firstError; |
| 81 | 82 |
| 82 static CompilationProcess current; | 83 static CompilationProcess current; |
| 83 | 84 |
| 84 CompilationProcess(this.source, this.console); | 85 CompilationProcess(this.source, this.console); |
| 85 | 86 |
| 86 static bool shouldStartCompilation() { | 87 static bool shouldStartCompilation() { |
| 87 if (compilerPort == null) return false; | 88 if (compilerPort == null) return false; |
| 88 if (isMalformedInput) return false; | 89 if (isMalformedInput) return false; |
| 89 if (current != null) return current.isDone; | 90 if (current != null) return current.isDone; |
| 90 return true; | 91 return true; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 default: | 133 default: |
| 133 throw ['Unknown message kind', message]; | 134 throw ['Unknown message kind', message]; |
| 134 } | 135 } |
| 135 } | 136 } |
| 136 | 137 |
| 137 onDartHtml(_) { | 138 onDartHtml(_) { |
| 138 usesDartHtml = true; | 139 usesDartHtml = true; |
| 139 } | 140 } |
| 140 | 141 |
| 141 onFail(_) { | 142 onFail(_) { |
| 142 interaction.onCompilationFailed(); | 143 interaction.onCompilationFailed(firstError); |
| 143 } | 144 } |
| 144 | 145 |
| 145 onDone(_) { | 146 onDone(_) { |
| 146 interaction.onCompilationDone(); | 147 interaction.onCompilationDone(); |
| 147 isDone = true; | 148 isDone = true; |
| 148 receivePort.close(); | 149 receivePort.close(); |
| 149 } | 150 } |
| 150 | 151 |
| 151 // This is called in browsers that support creating Object URLs in a | 152 // This is called in browsers that support creating Object URLs in a |
| 152 // web worker. For example, Chrome and Firefox 21. | 153 // web worker. For example, Chrome and Firefox 21. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 234 } |
| 234 | 235 |
| 235 onDiagnostic(Map<String, dynamic> diagnostic) { | 236 onDiagnostic(Map<String, dynamic> diagnostic) { |
| 236 if (currentSource != source) return; | 237 if (currentSource != source) return; |
| 237 String kind = diagnostic['kind']; | 238 String kind = diagnostic['kind']; |
| 238 String message = diagnostic['message']; | 239 String message = diagnostic['message']; |
| 239 if (kind == 'verbose info') { | 240 if (kind == 'verbose info') { |
| 240 interaction.verboseCompilerMessage(message); | 241 interaction.verboseCompilerMessage(message); |
| 241 return; | 242 return; |
| 242 } | 243 } |
| 244 if (kind == 'error' && firstError == null) { |
| 245 firstError = message; |
| 246 } |
| 243 String uri = diagnostic['uri']; | 247 String uri = diagnostic['uri']; |
| 244 if (uri != '${PRIVATE_SCHEME}:/main.dart') { | 248 if (uri != '${PRIVATE_SCHEME}:/main.dart') { |
| 245 interaction.consolePrintLine('$uri: [$kind] $message'); | 249 interaction.consolePrintLine('$uri: [$kind] $message'); |
| 246 return; | 250 return; |
| 247 } | 251 } |
| 248 int begin = diagnostic['begin']; | 252 int begin = diagnostic['begin']; |
| 249 int end = diagnostic['end']; | 253 int end = diagnostic['end']; |
| 250 if (begin == null) return; | 254 if (begin == null) return; |
| 251 if (seenMessages.add('$begin:$end: [$kind] $message')) { | 255 if (seenMessages.add('$begin:$end: [$kind] $message')) { |
| 252 // Guard against duplicated messages. | 256 // Guard against duplicated messages. |
| 253 addDiagnostic(kind, message, begin, end); | 257 addDiagnostic(kind, message, begin, end); |
| 254 } | 258 } |
| 255 } | 259 } |
| 256 | 260 |
| 257 onCrash(data) { | 261 onCrash(data) { |
| 258 interaction.onCompilerCrash(data); | 262 interaction.onCompilerCrash(data); |
| 259 } | 263 } |
| 260 } | 264 } |
| OLD | NEW |