| 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 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
| 6 library utils; | 6 library utils; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:crypto'; | 9 import 'dart:crypto'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 var map = {}; | 356 var map = {}; |
| 357 for (var pair in resolvedPairs) { | 357 for (var pair in resolvedPairs) { |
| 358 map[pair.first] = pair.last; | 358 map[pair.first] = pair.last; |
| 359 } | 359 } |
| 360 return map; | 360 return map; |
| 361 }); | 361 }); |
| 362 } | 362 } |
| 363 | 363 |
| 364 /// Returns the path to the library named [libraryName]. The library name must | 364 /// Returns the path to the library named [libraryName]. The library name must |
| 365 /// be globally unique, or the wrong library path may be returned. | 365 /// be globally unique, or the wrong library path may be returned. |
| 366 String libraryPath(String libraryName) => | 366 String libraryPath(String libraryName) { |
| 367 fileUriToPath(currentMirrorSystem().libraries[new Symbol(libraryName)].uri); | 367 var libraries = currentMirrorSystem().findLibrary(new Symbol(libraryName)); |
| 368 return fileUriToPath(libraries.single.uri); |
| 369 } |
| 368 | 370 |
| 369 /// Converts a `file:` [Uri] to a local path string. | 371 /// Converts a `file:` [Uri] to a local path string. |
| 370 String fileUriToPath(Uri uri) { | 372 String fileUriToPath(Uri uri) { |
| 371 if (uri.scheme != 'file') { | 373 if (uri.scheme != 'file') { |
| 372 throw new ArgumentError("Uri $uri must have scheme 'file:'."); | 374 throw new ArgumentError("Uri $uri must have scheme 'file:'."); |
| 373 } | 375 } |
| 374 if (Platform.operatingSystem != 'windows') return uri.path; | 376 if (Platform.operatingSystem != 'windows') return uri.path; |
| 375 if (uri.path.startsWith("/")) { | 377 if (uri.path.startsWith("/")) { |
| 376 // Drive-letter paths look like "file:///C:/path/to/file". The replaceFirst | 378 // Drive-letter paths look like "file:///C:/path/to/file". The replaceFirst |
| 377 // removes the extra initial slash. | 379 // removes the extra initial slash. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 405 error is FileIOException || | 407 error is FileIOException || |
| 406 error is HttpException || | 408 error is HttpException || |
| 407 error is HttpParserException || | 409 error is HttpParserException || |
| 408 error is LinkIOException || | 410 error is LinkIOException || |
| 409 error is MimeParserException || | 411 error is MimeParserException || |
| 410 error is OSError || | 412 error is OSError || |
| 411 error is ProcessException || | 413 error is ProcessException || |
| 412 error is SocketIOException || | 414 error is SocketIOException || |
| 413 error is WebSocketException; | 415 error is WebSocketException; |
| 414 } | 416 } |
| OLD | NEW |