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 builtin; | 5 library builtin; |
6 // NOTE: Do not import 'dart:io' in builtin. | 6 // NOTE: Do not import 'dart:io' in builtin. |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:_internal'; | 9 import 'dart:_internal'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 resolvedUri = _packageRoot.resolve(uri.path); | 288 resolvedUri = _packageRoot.resolve(uri.path); |
289 } else { | 289 } else { |
290 var packageName = uri.pathSegments[0]; | 290 var packageName = uri.pathSegments[0]; |
291 var mapping = _packageMap[packageName]; | 291 var mapping = _packageMap[packageName]; |
292 if (_traceLoading) { | 292 if (_traceLoading) { |
293 _log("Mapped '$packageName' package to '$mapping'"); | 293 _log("Mapped '$packageName' package to '$mapping'"); |
294 } | 294 } |
295 if (mapping == null) { | 295 if (mapping == null) { |
296 throw "No mapping for '$packageName' package when resolving '$uri'."; | 296 throw "No mapping for '$packageName' package when resolving '$uri'."; |
297 } | 297 } |
298 var path = uri.path.substring(packageName.length + 1); | 298 var path; |
299 if (uri.path.length > packageName.length) { | |
300 path = uri.path.substring(packageName.length + 1); | |
301 } else { | |
302 // Handle naked package resolution to the default package name: | |
303 // package:foo is equivalent to package:foo/foo.dart | |
304 assert(uri.path.length == packageName.length); | |
305 path = "$packageName.dart"; | |
Lasse Reichstein Nielsen
2016/03/23 11:18:18
While I like this change in general, it should be
| |
306 } | |
307 if (_traceLoading) { | |
308 _log("Path to be resolved in package: $path"); | |
309 } | |
299 resolvedUri = mapping.resolve(path); | 310 resolvedUri = mapping.resolve(path); |
300 } | 311 } |
301 if (_traceLoading) { | 312 if (_traceLoading) { |
302 _log("Resolved '$uri' to '$resolvedUri'."); | 313 _log("Resolved '$uri' to '$resolvedUri'."); |
303 } | 314 } |
304 return resolvedUri; | 315 return resolvedUri; |
305 } | 316 } |
306 | 317 |
307 | 318 |
308 // Resolves the script uri in the current working directory iff the given uri | 319 // Resolves the script uri in the current working directory iff the given uri |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 | 758 |
748 if (!_packagesReady) { | 759 if (!_packagesReady) { |
749 if (_traceLoading) { | 760 if (_traceLoading) { |
750 _log("Trigger loading by requesting the package config."); | 761 _log("Trigger loading by requesting the package config."); |
751 } | 762 } |
752 // Make sure to trigger package resolution. | 763 // Make sure to trigger package resolution. |
753 var dummy = await _getPackageConfigFuture(); | 764 var dummy = await _getPackageConfigFuture(); |
754 } | 765 } |
755 assert(_packagesReady); | 766 assert(_packagesReady); |
756 | 767 |
757 var result = _resolvePackageUri(packageUri); | 768 var result; |
769 try { | |
770 result = _resolvePackageUri(packageUri); | |
771 } catch (e, s) { | |
772 // Any error during resolution will resolve this package as not mapped, | |
773 // which is indicated by a null return. | |
774 if (_traceLoading) { | |
775 _log("Exception ($e) when resolving package URI: $packageUri"); | |
776 } | |
777 result = null; | |
778 } | |
758 if (_traceLoading) { | 779 if (_traceLoading) { |
759 _log("Resolved '$packageUri' to '$result'"); | 780 _log("Resolved '$packageUri' to '$result'"); |
760 } | 781 } |
761 return result; | 782 return result; |
762 } | 783 } |
763 | 784 |
764 | 785 |
765 // Handling of Resource class by dispatching to the load port. | 786 // Handling of Resource class by dispatching to the load port. |
766 Future<List<int>> _resourceReadAsBytes(Uri uri) { | 787 Future<List<int>> _resourceReadAsBytes(Uri uri) { |
767 var completer = new Completer<List<int>>(); | 788 var completer = new Completer<List<int>>(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
887 | 908 |
888 // Register callbacks and hooks with the rest of the core libraries. | 909 // Register callbacks and hooks with the rest of the core libraries. |
889 _setupHooks() { | 910 _setupHooks() { |
890 _setupCompleted = true; | 911 _setupCompleted = true; |
891 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; | 912 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; |
892 | 913 |
893 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; | 914 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; |
894 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; | 915 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; |
895 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; | 916 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; |
896 } | 917 } |
OLD | NEW |