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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 // The current working directory when the embedder was launched. | 83 // The current working directory when the embedder was launched. |
84 Uri _workingDirectory; | 84 Uri _workingDirectory; |
85 // The URI that the root script was loaded from. Remembered so that | 85 // The URI that the root script was loaded from. Remembered so that |
86 // package imports can be resolved relative to it. The root script is the basis | 86 // package imports can be resolved relative to it. The root script is the basis |
87 // for the root library in the VM. | 87 // for the root library in the VM. |
88 Uri _rootScript; | 88 Uri _rootScript; |
89 | 89 |
90 // Packages are either resolved looking up in a map or resolved from within a | 90 // Packages are either resolved looking up in a map or resolved from within a |
91 // package root. | 91 // package root. |
92 bool _packagesReady() => (_packageRoot != null) || (_packageMap != null); | 92 bool get _packagesReady => |
| 93 (_packageRoot != null) || (_packageMap != null) || (_packageError != null); |
| 94 // Error string set if there was an error resolving package configuration. |
| 95 // For example not finding a .packages file or packages/ directory, malformed |
| 96 // .packages file or any other related error. |
| 97 String _packageError = null; |
93 // The directory to look in to resolve "package:" scheme URIs. By detault it is | 98 // The directory to look in to resolve "package:" scheme URIs. By detault it is |
94 // the 'packages' directory right next to the script. | 99 // the 'packages' directory right next to the script. |
95 Uri _packageRoot = null; // Used to be _rootScript.resolve('packages/'); | 100 Uri _packageRoot = null; // Used to be _rootScript.resolve('packages/'); |
96 // The map describing how certain package names are mapped to Uris. | 101 // The map describing how certain package names are mapped to Uris. |
| 102 Uri _packageConfig = null; |
97 Map<String, Uri> _packageMap = null; | 103 Map<String, Uri> _packageMap = null; |
| 104 |
98 // A list of pending packags which have been requested while resolving the | 105 // A list of pending packags which have been requested while resolving the |
99 // location of the package root or the contents of the package map. | 106 // location of the package root or the contents of the package map. |
100 List<_LoadRequest> _pendingPackageLoads = []; | 107 List<_LoadRequest> _pendingPackageLoads = []; |
101 | 108 |
102 // If we have outstanding loads or pending package loads waiting for resolution, | 109 // If we have outstanding loads or pending package loads waiting for resolution, |
103 // then we do have pending loads. | 110 // then we do have pending loads. |
104 bool _pendingLoads() => !_reqMap.isEmpty || !_pendingPackageLoads.isEmpty; | 111 bool _pendingLoads() => !_reqMap.isEmpty || !_pendingPackageLoads.isEmpty; |
105 | 112 |
106 // Special handling for Windows paths so that they are compatible with URI | 113 // Special handling for Windows paths so that they are compatible with URI |
107 // handling. | 114 // handling. |
108 // Embedder sets this to true if we are running on Windows. | 115 // Embedder sets this to true if we are running on Windows. |
109 bool _isWindows = false; | 116 bool _isWindows = false; |
110 | 117 |
111 // Logging from builtin.dart is prefixed with a '*'. | 118 // Logging from builtin.dart is prefixed with a '*'. |
| 119 String _logId = (Isolate.current.hashCode % 0x100000).toRadixString(16); |
112 _log(msg) { | 120 _log(msg) { |
113 _print("* $msg"); | 121 _print("* $_logId $msg"); |
114 } | 122 } |
115 | 123 |
116 // A class wrapping the load error message in an Error object. | 124 // A class wrapping the load error message in an Error object. |
117 class _LoadError extends Error { | 125 class _LoadError extends Error { |
118 final String message; | 126 final String message; |
119 final String uri; | 127 final String uri; |
120 _LoadError(this.uri, this.message); | 128 _LoadError(this.uri, this.message); |
121 | 129 |
122 String toString() => 'Load Error for "$uri": $message'; | 130 String toString() => 'Load Error for "$uri": $message'; |
123 } | 131 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (packageRoot.startsWith('file:') || | 236 if (packageRoot.startsWith('file:') || |
229 packageRoot.startsWith('http:') || | 237 packageRoot.startsWith('http:') || |
230 packageRoot.startsWith('https:')) { | 238 packageRoot.startsWith('https:')) { |
231 _packageRoot = _workingDirectory.resolve(packageRoot); | 239 _packageRoot = _workingDirectory.resolve(packageRoot); |
232 } else { | 240 } else { |
233 packageRoot = _sanitizeWindowsPath(packageRoot); | 241 packageRoot = _sanitizeWindowsPath(packageRoot); |
234 packageRoot = _trimWindowsPath(packageRoot); | 242 packageRoot = _trimWindowsPath(packageRoot); |
235 _packageRoot = _workingDirectory.resolveUri(new Uri.file(packageRoot)); | 243 _packageRoot = _workingDirectory.resolveUri(new Uri.file(packageRoot)); |
236 } | 244 } |
237 // Now that we have determined the packageRoot value being used, set it | 245 // Now that we have determined the packageRoot value being used, set it |
238 // up for use in Platform.packageRoot. | 246 // up for use in Platform.packageRoot. This is only set when the embedder |
239 VMLibraryHooks.packageRoot = _packageRoot.toString(); | 247 // sets up the package root. Automatically discovered package root will |
| 248 // not update the VMLibraryHooks value. |
| 249 VMLibraryHooks.packageRootString = _packageRoot.toString(); |
240 if (_traceLoading) { | 250 if (_traceLoading) { |
241 _log('Package root URI: $_packageRoot'); | 251 _log('Package root URI: $_packageRoot'); |
242 } | 252 } |
243 } | 253 } |
244 | 254 |
245 | 255 |
246 // Given a uri with a 'package' scheme, return a Uri that is prefixed with | 256 // Given a uri with a 'package' scheme, return a Uri that is prefixed with |
247 // the package root. | 257 // the package root. |
248 Uri _resolvePackageUri(Uri uri) { | 258 Uri _resolvePackageUri(Uri uri) { |
| 259 assert(uri.scheme == "package"); |
| 260 assert(_packagesReady); |
| 261 |
249 if (!uri.host.isEmpty) { | 262 if (!uri.host.isEmpty) { |
250 var path = '${uri.host}${uri.path}'; | 263 var path = '${uri.host}${uri.path}'; |
251 var right = 'package:$path'; | 264 var right = 'package:$path'; |
252 var wrong = 'package://$path'; | 265 var wrong = 'package://$path'; |
253 | 266 |
254 throw "URIs using the 'package:' scheme should look like " | 267 throw "URIs using the 'package:' scheme should look like " |
255 "'$right', not '$wrong'."; | 268 "'$right', not '$wrong'."; |
256 } | 269 } |
257 | 270 |
258 if (_traceLoading) { | 271 if (_traceLoading) { |
259 _log('Resolving package with uri path: ${uri.path}'); | 272 _log('Resolving package with uri path: ${uri.path}'); |
260 } | 273 } |
261 var resolvedUri; | 274 var resolvedUri; |
262 if (_packageRoot != null) { | 275 if (_packageError != null) { |
| 276 if (_traceLoading) { |
| 277 _log("Resolving package with pending resolution error: $_packageError"); |
| 278 } |
| 279 throw _packageError; |
| 280 } else if (_packageRoot != null) { |
263 resolvedUri = _packageRoot.resolve(uri.path); | 281 resolvedUri = _packageRoot.resolve(uri.path); |
264 } else { | 282 } else { |
265 var packageName = uri.pathSegments[0]; | 283 var packageName = uri.pathSegments[0]; |
266 var mapping = _packageMap[packageName]; | 284 var mapping = _packageMap[packageName]; |
267 if (_traceLoading) { | 285 if (_traceLoading) { |
268 _log("Mapped '$packageName' package to '$mapping'"); | 286 _log("Mapped '$packageName' package to '$mapping'"); |
269 } | 287 } |
270 if (mapping == null) { | 288 if (mapping == null) { |
271 throw "No mapping for '$packageName' package when resolving '$uri'."; | 289 throw "No mapping for '$packageName' package when resolving '$uri'."; |
272 } | 290 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 _packagesPort.close(); | 419 _packagesPort.close(); |
402 _packagesPort = null; | 420 _packagesPort = null; |
403 | 421 |
404 if (_traceLoading) { | 422 if (_traceLoading) { |
405 _log("Got packages reply: $msg"); | 423 _log("Got packages reply: $msg"); |
406 } | 424 } |
407 if (msg is String) { | 425 if (msg is String) { |
408 if (_traceLoading) { | 426 if (_traceLoading) { |
409 _log("Got failure response on package port: '$msg'"); | 427 _log("Got failure response on package port: '$msg'"); |
410 } | 428 } |
411 throw msg; | 429 // Remember the error message. |
412 } | 430 _packageError = msg; |
413 if (msg.length == 1) { | 431 } else if (msg is List) { |
| 432 if (msg.length == 1) { |
| 433 if (_traceLoading) { |
| 434 _log("Received package root: '${msg[0]}'"); |
| 435 } |
| 436 _packageRoot = Uri.parse(msg[0]); |
| 437 } else { |
| 438 // First entry contains the location of the loaded .packages file. |
| 439 assert((msg.length % 2) == 0); |
| 440 assert(msg.length >= 2); |
| 441 assert(msg[1] == null); |
| 442 _packageConfig = Uri.parse(msg[0]); |
| 443 _packageMap = new Map<String, Uri>(); |
| 444 for (var i = 2; i < msg.length; i+=2) { |
| 445 // TODO(iposva): Complain about duplicate entries. |
| 446 _packageMap[msg[i]] = Uri.parse(msg[i+1]); |
| 447 } |
| 448 if (_traceLoading) { |
| 449 _log("Setup package map: $_packageMap"); |
| 450 } |
| 451 } |
| 452 } else { |
| 453 _packageError = "Bad type of packages reply: ${msg.runtimeType}"; |
414 if (_traceLoading) { | 454 if (_traceLoading) { |
415 _log("Received package root: '${msg[0]}'"); | 455 _log(_packageError); |
416 } | |
417 _packageRoot = Uri.parse(msg[0]); | |
418 } else { | |
419 assert((msg.length % 2) == 0); | |
420 _packageMap = new Map<String, Uri>(); | |
421 for (var i = 0; i < msg.length; i+=2) { | |
422 // TODO(iposva): Complain about duplicate entries. | |
423 _packageMap[msg[i]] = Uri.parse(msg[i+1]); | |
424 } | |
425 if (_traceLoading) { | |
426 _log("Setup package map: $_packageMap"); | |
427 } | 456 } |
428 } | 457 } |
429 | 458 |
430 // Resolve all pending package loads now that we know how to resolve them. | 459 // Resolve all pending package loads now that we know how to resolve them. |
431 while (_pendingPackageLoads.length > 0) { | 460 while (_pendingPackageLoads.length > 0) { |
432 // Order does not matter as we queue all of the requests up right now. | 461 // Order does not matter as we queue all of the requests up right now. |
433 var req = _pendingPackageLoads.removeLast(); | 462 var req = _pendingPackageLoads.removeLast(); |
434 // Call the registered closure, to handle the delayed action. | 463 // Call the registered closure, to handle the delayed action. |
435 req(); | 464 req(); |
436 } | 465 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 if (_workingDirectory == null) { | 507 if (_workingDirectory == null) { |
479 throw 'No current working directory set.'; | 508 throw 'No current working directory set.'; |
480 } | 509 } |
481 var packagesName = _sanitizeWindowsPath(packagesParam); | 510 var packagesName = _sanitizeWindowsPath(packagesParam); |
482 var packagesUri = Uri.parse(packagesName); | 511 var packagesUri = Uri.parse(packagesName); |
483 if (packagesUri.scheme == '') { | 512 if (packagesUri.scheme == '') { |
484 // Script does not have a scheme, assume that it is a path, | 513 // Script does not have a scheme, assume that it is a path, |
485 // resolve it against the working directory. | 514 // resolve it against the working directory. |
486 packagesUri = _workingDirectory.resolveUri(packagesUri); | 515 packagesUri = _workingDirectory.resolveUri(packagesUri); |
487 } | 516 } |
488 VMLibraryHooks.packageConfig = packagesUri.toString(); | 517 var packagesUriStr = packagesUri.toString(); |
| 518 VMLibraryHooks.packageConfigString = packagesUriStr; |
489 if (_traceLoading) { | 519 if (_traceLoading) { |
490 _log('Resolved packages map to: $packagesUri'); | 520 _log('Resolved packages map to: $packagesUri'); |
491 } | 521 } |
492 | 522 |
493 // Request the loading and parsing of the packages map at the specified URI. | 523 // Request the loading and parsing of the packages map at the specified URI. |
494 // Create a port to receive the packages map on. | 524 // Create a port to receive the packages map on. |
495 assert(_packagesPort == null); | 525 assert(_packagesPort == null); |
496 _packagesPort = new RawReceivePort(_handlePackagesReply); | 526 _packagesPort = new RawReceivePort(_handlePackagesReply); |
497 var sp = _packagesPort.sendPort; | 527 var sp = _packagesPort.sendPort; |
498 | 528 |
499 var msg = new List(4); | 529 var msg = new List(4); |
500 msg[0] = sp; | 530 msg[0] = sp; |
501 msg[1] = _traceLoading; | 531 msg[1] = _traceLoading; |
502 msg[2] = -2; | 532 msg[2] = -2; |
503 msg[3] = packagesUri.toString(); | 533 msg[3] = packagesUriStr; |
504 _loadPort.send(msg); | 534 _loadPort.send(msg); |
505 | 535 |
506 // Signal that the resolution of the packages map has started. But in this | 536 // Signal that the resolution of the packages map has started. But in this |
507 // case it is not tied to a particular request. | 537 // case it is not tied to a particular request. |
508 _pendingPackageLoads.add(() { | 538 _pendingPackageLoads.add(() { |
509 // Nothing to be done beyond registering that there is pending package | 539 // Nothing to be done beyond registering that there is pending package |
510 // resolution requested by having an empty entry. | 540 // resolution requested by having an empty entry. |
511 if (_traceLoading) { | 541 if (_traceLoading) { |
512 _log("Skipping dummy deferred request."); | 542 _log("Skipping dummy deferred request."); |
513 } | 543 } |
514 }); | 544 }); |
515 | 545 |
516 if (_traceLoading) { | 546 if (_traceLoading) { |
517 _log("Requested packages map at '$packagesUri'."); | 547 _log("Requested packages map at '$packagesUri'."); |
518 } | 548 } |
519 } | 549 } |
520 | 550 |
521 | 551 |
522 // Embedder Entrypoint: | |
523 // Add mapping from package name to URI. | |
524 void _addPackageMapEntry(String key, String value) { | |
525 if (!_setupCompleted) { | |
526 _setupHooks(); | |
527 } | |
528 if (_traceLoading) { | |
529 _log("Adding packages map entry: $key -> $value"); | |
530 } | |
531 if (_packageRoot != null) { | |
532 if (_traceLoading) { | |
533 _log("_packageRoot already set: $_packageRoot"); | |
534 } | |
535 throw "Cannot add package map entry to an exisiting package root."; | |
536 } | |
537 if (_packagesPort != null) { | |
538 if (_traceLoading) { | |
539 _log("Package map load request already pending."); | |
540 } | |
541 throw "Cannot add package map entry during package map resolution."; | |
542 } | |
543 if (_packageMap == null) { | |
544 _packageMap = new Map<String, Uri>(); | |
545 } | |
546 _packageMap[key] = _workingDirectory.resolve(value); | |
547 } | |
548 | |
549 | |
550 void _asyncLoadError(_LoadRequest req, _LoadError error, StackTrace stack) { | 552 void _asyncLoadError(_LoadRequest req, _LoadError error, StackTrace stack) { |
551 if (_traceLoading) { | 553 if (_traceLoading) { |
552 _log("_asyncLoadError(${req._uri}), error: $error\nstack: $stack"); | 554 _log("_asyncLoadError(${req._uri}), error: $error\nstack: $stack"); |
553 } | 555 } |
554 if (req._tag == _Dart_kResourceLoad) { | 556 if (req._tag == _Dart_kResourceLoad) { |
555 Completer c = req._context; | 557 Completer c = req._context; |
556 c.completeError(error, stack); | 558 c.completeError(error, stack); |
557 } else { | 559 } else { |
558 String libraryUri = req._context; | 560 String libraryUri = req._context; |
559 if (req._tag == _Dart_kImportTag) { | 561 if (req._tag == _Dart_kImportTag) { |
(...skipping 20 matching lines...) Expand all Loading... |
580 // Register a dummy load request and fail to load it. | 582 // Register a dummy load request and fail to load it. |
581 var req = new _LoadRequest(tag, uri, resourceUri, context); | 583 var req = new _LoadRequest(tag, uri, resourceUri, context); |
582 _asyncLoadError(req, error, s); | 584 _asyncLoadError(req, error, s); |
583 } | 585 } |
584 } | 586 } |
585 | 587 |
586 | 588 |
587 // Loading a package URI needs to first map the package name to a loadable | 589 // Loading a package URI needs to first map the package name to a loadable |
588 // URI. | 590 // URI. |
589 _loadPackage(int tag, String uri, Uri resourceUri, context) { | 591 _loadPackage(int tag, String uri, Uri resourceUri, context) { |
590 if (_packagesReady()) { | 592 if (_packagesReady) { |
591 _loadData(tag, uri, _resolvePackageUri(resourceUri), context); | 593 var resolvedUri; |
| 594 try { |
| 595 resolvedUri = _resolvePackageUri(resourceUri); |
| 596 } catch (e, s) { |
| 597 if (_traceLoading) { |
| 598 _log("Exception ($e) when resolving package URI: $resourceUri"); |
| 599 } |
| 600 // Wrap inside a _LoadError unless we are already propagating a previously |
| 601 // seen _LoadError. |
| 602 var error = (e is _LoadError) ? e : new _LoadError(uri, e.toString()); |
| 603 // Register a dummy load request and fail to load it. |
| 604 var req = new _LoadRequest(tag, uri, resourceUri, context); |
| 605 _asyncLoadError(req, error, s); |
| 606 } |
| 607 _loadData(tag, uri, resolvedUri, context); |
592 } else { | 608 } else { |
593 if (_pendingPackageLoads.isEmpty) { | 609 if (_pendingPackageLoads.isEmpty) { |
594 // Package resolution has not been setup yet, and this is the first | 610 // Package resolution has not been setup yet, and this is the first |
595 // request for package resolution & loading. | 611 // request for package resolution & loading. |
596 _requestPackagesMap(); | 612 _requestPackagesMap(); |
597 } | 613 } |
598 // Register the action of loading this package once the package resolution | 614 // Register the action of loading this package once the package resolution |
599 // is ready. | 615 // is ready. |
600 _pendingPackageLoads.add(() { | 616 _pendingPackageLoads.add(() { |
601 if (_traceLoading) { | 617 if (_traceLoading) { |
602 _log("Handling deferred package request: " | 618 _log("Handling deferred package request: " |
603 "$tag, $uri, $resourceUri, $context"); | 619 "$tag, $uri, $resourceUri, $context"); |
604 } | 620 } |
605 _loadPackage(tag, uri, resourceUri, context); | 621 _loadPackage(tag, uri, resourceUri, context); |
606 }); | 622 }); |
607 if (_traceLoading) { | 623 if (_traceLoading) { |
608 _log("Pending package load of '$uri': " | 624 _log("Pending package load of '$uri': " |
609 "${_pendingPackageLoads.length} pending"); | 625 "${_pendingPackageLoads.length} pending"); |
610 } | 626 } |
611 } | 627 } |
612 } | 628 } |
613 | 629 |
614 | 630 |
615 // Load the data associated with the resourceUri. | 631 // Load the data associated with the resourceUri. |
616 _loadData(int tag, String uri, Uri resourceUri, context) { | 632 _loadData(int tag, String uri, Uri resourceUri, context) { |
617 if (resourceUri.scheme == 'package') { | 633 if (resourceUri.scheme == 'package') { |
618 // package based uris need to be resolved to the correct loadable location. | 634 // package based uris need to be resolved to the correct loadable location. |
619 // The logic of which is handled seperately, and then _loadData is called | 635 // The logic of which is handled seperately, and then _loadData is called |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 } | 678 } |
663 if (_traceLoading) { | 679 if (_traceLoading) { |
664 _log('Resolved $userString in $base to $result'); | 680 _log('Resolved $userString in $base to $result'); |
665 } | 681 } |
666 return result; | 682 return result; |
667 } | 683 } |
668 | 684 |
669 | 685 |
670 // Handling of access to the package root or package map from user code. | 686 // Handling of access to the package root or package map from user code. |
671 _triggerPackageResolution(action) { | 687 _triggerPackageResolution(action) { |
672 if (_packagesReady()) { | 688 if (_packagesReady) { |
673 // Packages are ready. Execute the action now. | 689 // Packages are ready. Execute the action now. |
674 action(); | 690 action(); |
675 } else { | 691 } else { |
676 if (_pendingPackageLoads.isEmpty) { | 692 if (_pendingPackageLoads.isEmpty) { |
677 // Package resolution has not been setup yet, and this is the first | 693 // Package resolution has not been setup yet, and this is the first |
678 // request for package resolution & loading. | 694 // request for package resolution & loading. |
679 _requestPackagesMap(); | 695 _requestPackagesMap(); |
680 } | 696 } |
681 // Register the action for when the package resolution is ready. | 697 // Register the action for when the package resolution is ready. |
682 _pendingPackageLoads.add(action); | 698 _pendingPackageLoads.add(action); |
683 } | 699 } |
684 } | 700 } |
685 | 701 |
686 | 702 |
687 Future<Uri> _getPackageRoot() { | 703 Future<Uri> _getPackageRootFuture() { |
688 if (_traceLoading) { | 704 if (_traceLoading) { |
689 _log("Request for package root from user code."); | 705 _log("Request for package root from user code."); |
690 } | 706 } |
691 var completer = new Completer<Uri>(); | 707 var completer = new Completer<Uri>(); |
692 _triggerPackageResolution(() { | 708 _triggerPackageResolution(() { |
693 completer.complete(_packageRoot); | 709 completer.complete(_packageRoot); |
694 }); | 710 }); |
695 return completer.future; | 711 return completer.future; |
696 } | 712 } |
697 | 713 |
698 | 714 |
699 Future<Map<String, Uri>> _getPackageMap() { | 715 Future<Uri> _getPackageConfigFuture() { |
700 if (_traceLoading) { | 716 if (_traceLoading) { |
701 _log("Request for package map from user code."); | 717 _log("Request for package config from user code."); |
702 } | 718 } |
703 var completer = new Completer<Map<String, Uri>>(); | 719 var completer = new Completer<Uri>(); |
704 _triggerPackageResolution(() { | 720 _triggerPackageResolution(() { |
705 var result = (_packageMap != null) ? new Map.from(_packageMap) : {}; | 721 completer.complete(_packageConfig); |
706 completer.complete(result); | |
707 }); | 722 }); |
708 return completer.future; | 723 return completer.future; |
709 } | 724 } |
710 | 725 |
711 | 726 |
| 727 Future<Uri> _resolvePackageUriFuture(Uri packageUri) async { |
| 728 if (_traceLoading) { |
| 729 _log("Request for package Uri resolution from user code: $packageUri"); |
| 730 } |
| 731 if (packageUri.scheme != "package") { |
| 732 if (_traceLoading) { |
| 733 _log("Non-package Uri, returning unmodified: $packageUri"); |
| 734 } |
| 735 // Return the incoming parameter if not passed a package: URI. |
| 736 return packageUri; |
| 737 } |
| 738 |
| 739 if (!_packagesReady) { |
| 740 if (_traceLoading) { |
| 741 _log("Trigger loading by requesting the package config."); |
| 742 } |
| 743 // Make sure to trigger package resolution. |
| 744 var dummy = await _getPackageConfigFuture(); |
| 745 } |
| 746 assert(_packagesReady); |
| 747 |
| 748 var result = _resolvePackageUri(packageUri); |
| 749 if (_traceLoading) { |
| 750 _log("Resolved '$packageUri' to '$result'"); |
| 751 } |
| 752 return result; |
| 753 } |
| 754 |
| 755 |
712 // Handling of Resource class by dispatching to the load port. | 756 // Handling of Resource class by dispatching to the load port. |
713 Future<List<int>> _resourceReadAsBytes(Uri uri) { | 757 Future<List<int>> _resourceReadAsBytes(Uri uri) { |
714 var completer = new Completer<List<int>>(); | 758 var completer = new Completer<List<int>>(); |
715 // Request the load of the resource associating the completer as the context | 759 // Request the load of the resource associating the completer as the context |
716 // for the load. | 760 // for the load. |
717 _loadData(_Dart_kResourceLoad, uri.toString(), uri, completer); | 761 _loadData(_Dart_kResourceLoad, uri.toString(), uri, completer); |
718 // Return the future that will be triggered once the resource has been loaded. | 762 // Return the future that will be triggered once the resource has been loaded. |
719 return completer.future; | 763 return completer.future; |
720 } | 764 } |
721 | 765 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 var filename = _platformExtensionFileName(name); | 873 var filename = _platformExtensionFileName(name); |
830 | 874 |
831 return [path, filename, name]; | 875 return [path, filename, name]; |
832 } | 876 } |
833 | 877 |
834 | 878 |
835 // Register callbacks and hooks with the rest of the core libraries. | 879 // Register callbacks and hooks with the rest of the core libraries. |
836 _setupHooks() { | 880 _setupHooks() { |
837 _setupCompleted = true; | 881 _setupCompleted = true; |
838 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; | 882 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; |
839 VMLibraryHooks.getPackageRoot = _getPackageRoot; | 883 |
840 VMLibraryHooks.getPackageMap = _getPackageMap; | 884 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; |
| 885 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; |
| 886 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; |
841 } | 887 } |
OLD | NEW |