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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 // sets up the package root. Automatically discovered package root will | 261 // sets up the package root. Automatically discovered package root will |
262 // not update the VMLibraryHooks value. | 262 // not update the VMLibraryHooks value. |
263 VMLibraryHooks.packageRootString = _packageRoot.toString(); | 263 VMLibraryHooks.packageRootString = _packageRoot.toString(); |
264 if (_traceLoading) { | 264 if (_traceLoading) { |
265 _log('Package root URI: $_packageRoot'); | 265 _log('Package root URI: $_packageRoot'); |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 | 269 |
270 // Given a uri with a 'package' scheme, return a Uri that is prefixed with | 270 // Given a uri with a 'package' scheme, return a Uri that is prefixed with |
271 // the package root. | 271 // the package root or resolved relative to the package configuration. |
272 Uri _resolvePackageUri(Uri uri) { | 272 Uri _resolvePackageUri(Uri uri) { |
273 assert(uri.scheme == "package"); | 273 assert(uri.scheme == "package"); |
274 assert(_packagesReady); | 274 assert(_packagesReady); |
275 | 275 |
276 if (!uri.host.isEmpty) { | 276 if (uri.host.isNotEmpty) { |
277 var path = '${uri.host}${uri.path}'; | 277 var path = '${uri.host}${uri.path}'; |
278 var right = 'package:$path'; | 278 var right = 'package:$path'; |
279 var wrong = 'package://$path'; | 279 var wrong = 'package://$path'; |
280 | 280 |
281 throw "URIs using the 'package:' scheme should look like " | 281 throw "URIs using the 'package:' scheme should look like " |
282 "'$right', not '$wrong'."; | 282 "'$right', not '$wrong'."; |
283 } | 283 } |
284 | 284 var packageNameEnd = uri.path.indexOf('/'); |
285 if (packageNameEnd == 0) { | |
286 // Package URIs must have a non-empty package name (not start with "/"). | |
287 throw "URIS using the 'package:' scheme should look like " | |
288 "'package:packageName${uri.path}', not 'package:${uri.path}'"; | |
Lasse Reichstein Nielsen
2016/05/19 10:55:25
This case wasn't handled before, but with a packag
| |
289 } | |
290 if (packageNameEnd < 0) { | |
291 // Package URIs must have a path after the package name, even if it's | |
292 // just "/". | |
293 throw "URIS using the 'package:' scheme should look like " | |
294 "'package:${uri.path}/', not 'package:${uri.path}'"; | |
295 } | |
285 if (_traceLoading) { | 296 if (_traceLoading) { |
286 _log('Resolving package with uri path: ${uri.path}'); | 297 _log('Resolving package with uri path: ${uri.path}'); |
287 } | 298 } |
288 var resolvedUri; | 299 var resolvedUri; |
289 if (_packageError != null) { | 300 if (_packageError != null) { |
290 if (_traceLoading) { | 301 if (_traceLoading) { |
291 _log("Resolving package with pending resolution error: $_packageError"); | 302 _log("Resolving package with pending resolution error: $_packageError"); |
292 } | 303 } |
293 throw _packageError; | 304 throw _packageError; |
294 } else if (_packageRoot != null) { | 305 } else if (_packageRoot != null) { |
295 resolvedUri = _packageRoot.resolve(uri.path); | 306 resolvedUri = _packageRoot.resolve(uri.path); |
296 } else { | 307 } else { |
297 var packageName = uri.pathSegments[0]; | 308 var packageName = uri.path.substring(0, packageNameEnd); |
298 var mapping = _packageMap[packageName]; | 309 var mapping = _packageMap[packageName]; |
299 if (_traceLoading) { | 310 if (_traceLoading) { |
300 _log("Mapped '$packageName' package to '$mapping'"); | 311 _log("Mapped '$packageName' package to '$mapping'"); |
301 } | 312 } |
302 if (mapping == null) { | 313 if (mapping == null) { |
303 throw "No mapping for '$packageName' package when resolving '$uri'."; | 314 throw "No mapping for '$packageName' package when resolving '$uri'."; |
304 } | 315 } |
305 var path; | 316 var path; |
306 if (uri.path.length > packageName.length) { | 317 assert(uri.path.length > packageName.length); |
307 path = uri.path.substring(packageName.length + 1); | 318 path = uri.path.substring(packageName.length + 1); |
308 } else { | |
309 // Handle naked package resolution to the default package name: | |
310 // package:foo is equivalent to package:foo/foo.dart | |
311 assert(uri.path.length == packageName.length); | |
312 path = "$packageName.dart"; | |
313 } | |
314 if (_traceLoading) { | 319 if (_traceLoading) { |
315 _log("Path to be resolved in package: $path"); | 320 _log("Path to be resolved in package: $path"); |
316 } | 321 } |
317 resolvedUri = mapping.resolve(path); | 322 resolvedUri = mapping.resolve(path); |
318 } | 323 } |
319 if (_traceLoading) { | 324 if (_traceLoading) { |
320 _log("Resolved '$uri' to '$resolvedUri'."); | 325 _log("Resolved '$uri' to '$resolvedUri'."); |
321 } | 326 } |
322 return resolvedUri; | 327 return resolvedUri; |
323 } | 328 } |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 | 910 |
906 // Register callbacks and hooks with the rest of the core libraries. | 911 // Register callbacks and hooks with the rest of the core libraries. |
907 _setupHooks() { | 912 _setupHooks() { |
908 _setupCompleted = true; | 913 _setupCompleted = true; |
909 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; | 914 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; |
910 | 915 |
911 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; | 916 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; |
912 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; | 917 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; |
913 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; | 918 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; |
914 } | 919 } |
OLD | NEW |