| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 web_ui.src.utils; | 5 library web_ui.src.utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:pathos/path.dart' show Builder; | 9 import 'package:path/path.dart' show Builder; |
| 10 | 10 |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * An instance of the pathos library builder. We could just use the default | 13 * An instance of the path library builder. We could just use the default |
| 14 * builder in pathos, but we add this indirection to make it possible to run | 14 * builder in path, but we add this indirection to make it possible to run |
| 15 * unittest for windows paths. | 15 * unittest for windows paths. |
| 16 */ | 16 */ |
| 17 Builder path = new Builder(); | 17 Builder path = new Builder(); |
| 18 | 18 |
| 19 /** Convert a OS specific path into a url. */ | 19 /** Convert a OS specific path into a url. */ |
| 20 String pathToUrl(String relPath) => | 20 String pathToUrl(String relPath) => |
| 21 (path.separator == '/') ? relPath : path.split(relPath).join('/'); | 21 (path.separator == '/') ? relPath : path.split(relPath).join('/'); |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Converts a string name with hyphens into an identifier, by removing hyphens | 24 * Converts a string name with hyphens into an identifier, by removing hyphens |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 var i = results.length; | 137 var i = results.length; |
| 138 results.add(null); | 138 results.add(null); |
| 139 task.then((res) { | 139 task.then((res) { |
| 140 results[i] = res; | 140 results[i] = res; |
| 141 if (_failedTask != null) return; | 141 if (_failedTask != null) return; |
| 142 _pending--; | 142 _pending--; |
| 143 if (_pending == 0) { | 143 if (_pending == 0) { |
| 144 _pending = _FINISHED; | 144 _pending = _FINISHED; |
| 145 _completer.complete(results); | 145 _completer.complete(results); |
| 146 } | 146 } |
| 147 }, onError: (e) { | 147 }, onError: (e, trace) { |
| 148 if (_failedTask != null) return; | 148 if (_failedTask != null) return; |
| 149 _failedTask = task; | 149 _failedTask = task; |
| 150 _completer.completeError(e, getAttachedStackTrace(e)); | 150 _completer.completeError(e, trace); |
| 151 }); | 151 }); |
| 152 } | 152 } |
| 153 | 153 |
| 154 Future<List> get future => _completer.future; | 154 Future<List> get future => _completer.future; |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * Escapes [text] for use in a Dart string. | 159 * Escapes [text] for use in a Dart string. |
| 160 * [single] specifies single quote `'` vs double quote `"`. | 160 * [single] specifies single quote `'` vs double quote `"`. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 */ | 280 */ |
| 281 void compilerAssert(bool condition, [String message]) { | 281 void compilerAssert(bool condition, [String message]) { |
| 282 if (!condition) throw new InternalError(message); | 282 if (!condition) throw new InternalError(message); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // TODO(jmesserly): this is a start, but what we might want to instead: catch | 285 // TODO(jmesserly): this is a start, but what we might want to instead: catch |
| 286 // all errors at the top level and log to message (including stack). That way if | 286 // all errors at the top level and log to message (including stack). That way if |
| 287 // we have a noSuchMethod error or something it will show up the same way as | 287 // we have a noSuchMethod error or something it will show up the same way as |
| 288 // this does, including the bug report link. | 288 // this does, including the bug report link. |
| 289 /** Error thrown if there is a bug in the compiler itself. */ | 289 /** Error thrown if there is a bug in the compiler itself. */ |
| 290 class InternalError implements Error { | 290 class InternalError extends Error { |
| 291 final message; | 291 final message; |
| 292 | 292 |
| 293 InternalError([this.message]); | 293 InternalError([this.message]); |
| 294 | 294 |
| 295 String toString() { | 295 String toString() { |
| 296 var additionalMessage = ''; | 296 var additionalMessage = ''; |
| 297 if (message != null) { | 297 if (message != null) { |
| 298 additionalMessage = '\nInternal message: $message'; | 298 additionalMessage = '\nInternal message: $message'; |
| 299 } | 299 } |
| 300 return "We're sorry, you've just found a compiler bug. " | 300 return "We're sorry, you've just found a compiler bug. " |
| 301 'You can report it at:\n' | 301 'You can report it at:\n' |
| 302 'https://github.com/dart-lang/web-ui/issues/new\n' | 302 'https://github.com/dart-lang/web-ui/issues/new\n' |
| 303 'Thanks in advance for the bug report! It will help us improve Web UI.' | 303 'Thanks in advance for the bug report! It will help us improve Web UI.' |
| 304 '$additionalMessage'; | 304 '$additionalMessage'; |
| 305 } | 305 } |
| 306 } | 306 } |
| OLD | NEW |