| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 import 'editor.dart' show | 24 import 'editor.dart' show |
| 25 addDiagnostic, | 25 addDiagnostic, |
| 26 isMalformedInput; | 26 isMalformedInput; |
| 27 | 27 |
| 28 import 'run.dart' show | 28 import 'run.dart' show |
| 29 makeOutputFrame; | 29 makeOutputFrame; |
| 30 | 30 |
| 31 import 'ui.dart' show | 31 import 'ui.dart' show |
| 32 buildButton, | 32 buildButton, |
| 33 interaction, |
| 33 outputDiv, | 34 outputDiv, |
| 34 outputFrame; | 35 outputFrame; |
| 35 | 36 |
| 36 import 'settings.dart' show | 37 import 'settings.dart' show |
| 37 alwaysRunInWorker, | 38 alwaysRunInWorker, |
| 38 minified, | 39 minified, |
| 39 onlyAnalyze, | 40 onlyAnalyze, |
| 40 verboseCompiler; | 41 verboseCompiler; |
| 41 | 42 |
| 42 | 43 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 65 bool startCompilation() { | 66 bool startCompilation() { |
| 66 if (!CompilationProcess.shouldStartCompilation()) return false; | 67 if (!CompilationProcess.shouldStartCompilation()) return false; |
| 67 new CompilationProcess(currentSource, outputDiv).start(); | 68 new CompilationProcess(currentSource, outputDiv).start(); |
| 68 return true; | 69 return true; |
| 69 } | 70 } |
| 70 | 71 |
| 71 class CompilationProcess { | 72 class CompilationProcess { |
| 72 final String source; | 73 final String source; |
| 73 final Element console; | 74 final Element console; |
| 74 final ReceivePort receivePort = new ReceivePort(); | 75 final ReceivePort receivePort = new ReceivePort(); |
| 76 final Set<String> seenMessages = new Set<String>(); |
| 75 bool isCleared = false; | 77 bool isCleared = false; |
| 76 bool isDone = false; | 78 bool isDone = false; |
| 77 bool usesDartHtml = false; | 79 bool usesDartHtml = false; |
| 78 Worker worker; | 80 Worker worker; |
| 79 List<String> objectUrls = <String>[]; | 81 List<String> objectUrls = <String>[]; |
| 80 | 82 |
| 81 static CompilationProcess current; | 83 static CompilationProcess current; |
| 82 | 84 |
| 83 CompilationProcess(this.source, this.console); | 85 CompilationProcess(this.source, this.console); |
| 84 | 86 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 105 console.nodes.clear(); | 107 console.nodes.clear(); |
| 106 var options = [ | 108 var options = [ |
| 107 '--analyze-main', | 109 '--analyze-main', |
| 108 '--disable-type-inference', | 110 '--disable-type-inference', |
| 109 '--incremental-support', | 111 '--incremental-support', |
| 110 '--no-source-maps', | 112 '--no-source-maps', |
| 111 ]; | 113 ]; |
| 112 if (verboseCompiler) options.add('--verbose'); | 114 if (verboseCompiler) options.add('--verbose'); |
| 113 if (minified) options.add('--minify'); | 115 if (minified) options.add('--minify'); |
| 114 if (onlyAnalyze) options.add('--analyze-only'); | 116 if (onlyAnalyze) options.add('--analyze-only'); |
| 117 interaction.compilationStarting(); |
| 115 compilerPort.send([['options', options], receivePort.sendPort]); | 118 compilerPort.send([['options', options], receivePort.sendPort]); |
| 116 console.appendHtml('<i class="icon-spinner icon-spin"></i>'); | 119 console.appendHtml('<i class="icon-spinner icon-spin"></i>'); |
| 117 console.appendText(' Compiling Dart program...\n'); | 120 console.appendText(' Compiling Dart program...\n'); |
| 118 outputFrame.style.display = 'none'; | 121 outputFrame.style.display = 'none'; |
| 119 receivePort.listen(onMessage); | 122 receivePort.listen(onMessage); |
| 120 compilerPort.send([source, receivePort.sendPort]); | 123 compilerPort.send([source, receivePort.sendPort]); |
| 121 } | 124 } |
| 122 | 125 |
| 123 void dispose() { | 126 void dispose() { |
| 124 if (worker != null) worker.terminate(); | 127 if (worker != null) worker.terminate(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 144 onDartHtml(_) { | 147 onDartHtml(_) { |
| 145 usesDartHtml = true; | 148 usesDartHtml = true; |
| 146 } | 149 } |
| 147 | 150 |
| 148 onFail(_) { | 151 onFail(_) { |
| 149 clear(); | 152 clear(); |
| 150 consolePrint('Compilation failed'); | 153 consolePrint('Compilation failed'); |
| 151 } | 154 } |
| 152 | 155 |
| 153 onDone(_) { | 156 onDone(_) { |
| 157 interaction.onCompilationDone(); |
| 154 isDone = true; | 158 isDone = true; |
| 155 receivePort.close(); | 159 receivePort.close(); |
| 156 } | 160 } |
| 157 | 161 |
| 158 // This is called in browsers that support creating Object URLs in a | 162 // This is called in browsers that support creating Object URLs in a |
| 159 // web worker. For example, Chrome and Firefox 21. | 163 // web worker. For example, Chrome and Firefox 21. |
| 160 onUrl(String url) { | 164 onUrl(String url) { |
| 161 objectUrls.add(url); | 165 objectUrls.add(url); |
| 162 clear(); | 166 clear(); |
| 163 String wrapper = ''' | 167 String wrapper = ''' |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 consolePrint(event.data); | 242 consolePrint(event.data); |
| 239 }) | 243 }) |
| 240 ..onError.listen((ErrorEvent event) { | 244 ..onError.listen((ErrorEvent event) { |
| 241 worker.terminate(); | 245 worker.terminate(); |
| 242 worker = null; | 246 worker = null; |
| 243 onError(event.message); | 247 onError(event.message); |
| 244 }); | 248 }); |
| 245 } | 249 } |
| 246 | 250 |
| 247 onDiagnostic(Map<String, dynamic> diagnostic) { | 251 onDiagnostic(Map<String, dynamic> diagnostic) { |
| 252 if (currentSource != source) return; |
| 248 String kind = diagnostic['kind']; | 253 String kind = diagnostic['kind']; |
| 249 String message = diagnostic['message']; | 254 String message = diagnostic['message']; |
| 250 if (kind == 'verbose info') { | 255 if (kind == 'verbose info') { |
| 251 if (verboseCompiler) { | 256 if (verboseCompiler) { |
| 252 consolePrint(message); | 257 consolePrint(message); |
| 253 } else { | 258 } else { |
| 254 console.appendText('.'); | 259 console.appendText('.'); |
| 255 } | 260 } |
| 256 return; | 261 return; |
| 257 } | 262 } |
| 258 String uri = diagnostic['uri']; | 263 String uri = diagnostic['uri']; |
| 259 if (uri == null) { | 264 if (uri != '${PRIVATE_SCHEME}:/main.dart') { |
| 260 clear(); | 265 consolePrint('$uri: [$kind] $message'); |
| 261 consolePrint(message); | |
| 262 return; | 266 return; |
| 263 } | 267 } |
| 264 if (uri != '${PRIVATE_SCHEME}:/main.dart') return; | |
| 265 if (currentSource != source) return; | |
| 266 int begin = diagnostic['begin']; | 268 int begin = diagnostic['begin']; |
| 267 int end = diagnostic['end']; | 269 int end = diagnostic['end']; |
| 268 if (begin == null) return; | 270 if (begin == null) return; |
| 269 addDiagnostic(kind, message, begin, end); | 271 if (seenMessages.add('$begin:$end: [$kind] $message')) { |
| 272 // Guard against duplicated messages. |
| 273 addDiagnostic(kind, message, begin, end); |
| 274 } |
| 270 } | 275 } |
| 271 | 276 |
| 272 onCrash(data) { | 277 onCrash(data) { |
| 273 consolePrint(data); | 278 consolePrint(data); |
| 274 } | 279 } |
| 275 | 280 |
| 276 void consolePrint(message) { | 281 void consolePrint(message) { |
| 277 if (window.parent != window) { | 282 if (window.parent != window) { |
| 278 // Test support. | 283 // Test support. |
| 279 // TODO(ahe): Use '/' instead of '*' when Firefox is upgraded to version | 284 // TODO(ahe): Use '/' instead of '*' when Firefox is upgraded to version |
| (...skipping 12 matching lines...) Expand all Loading... |
| 292 port.send(replyTo.sendPort); | 297 port.send(replyTo.sendPort); |
| 293 replyTo.listen((message) { | 298 replyTo.listen((message) { |
| 294 List list = message as List; | 299 List list = message as List; |
| 295 try { | 300 try { |
| 296 compile(list[0], list[1]); | 301 compile(list[0], list[1]); |
| 297 } catch (exception, stack) { | 302 } catch (exception, stack) { |
| 298 port.send('$exception\n$stack'); | 303 port.send('$exception\n$stack'); |
| 299 } | 304 } |
| 300 }); | 305 }); |
| 301 } | 306 } |
| OLD | NEW |