| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 bool _isWindows = false; | 116 bool _isWindows = false; |
| 117 | 117 |
| 118 // 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); | 119 String _logId = (Isolate.current.hashCode % 0x100000).toRadixString(16); |
| 120 _log(msg) { | 120 _log(msg) { |
| 121 _print("* $_logId $msg"); | 121 _print("* $_logId $msg"); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // A class wrapping the load error message in an Error object. | 124 // A class wrapping the load error message in an Error object. |
| 125 class _LoadError extends Error { | 125 class _LoadError extends Error { |
| 126 final _LoadRequest request; |
| 126 final String message; | 127 final String message; |
| 127 final String uri; | 128 _LoadError(this.request, this.message); |
| 128 _LoadError(this.uri, this.message); | |
| 129 | 129 |
| 130 String toString() => 'Load Error for "$uri": $message'; | 130 String toString() { |
| 131 var context = request._context; |
| 132 if (context == null || context is! String) { |
| 133 return 'Could not load "${request._uri}": $message'; |
| 134 } else { |
| 135 return 'Could not import "${request._uri}" from "$context": $message'; |
| 136 } |
| 137 } |
| 131 } | 138 } |
| 132 | 139 |
| 133 // Class collecting all of the information about a particular load request. | 140 // Class collecting all of the information about a particular load request. |
| 134 class _LoadRequest { | 141 class _LoadRequest { |
| 135 final int _id = _reqId++; | 142 final int _id = _reqId++; |
| 136 final int _tag; | 143 final int _tag; |
| 137 final String _uri; | 144 final String _uri; |
| 138 final Uri _resourceUri; | 145 final Uri _resourceUri; |
| 139 final _context; | 146 final _context; |
| 140 | 147 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 c.complete(dataOrError); | 372 c.complete(dataOrError); |
| 366 } else { | 373 } else { |
| 367 // TODO: Currently a compilation error while loading the script is | 374 // TODO: Currently a compilation error while loading the script is |
| 368 // fatal for the isolate. _loadScriptCallback() does not return and | 375 // fatal for the isolate. _loadScriptCallback() does not return and |
| 369 // the number of requests remains out of sync. | 376 // the number of requests remains out of sync. |
| 370 _loadScriptCallback(req._tag, req._uri, req._context, dataOrError); | 377 _loadScriptCallback(req._tag, req._uri, req._context, dataOrError); |
| 371 } | 378 } |
| 372 _finishLoadRequest(req); | 379 _finishLoadRequest(req); |
| 373 } else { | 380 } else { |
| 374 assert(dataOrError is String); | 381 assert(dataOrError is String); |
| 375 var error = new _LoadError(req._uri, dataOrError.toString()); | 382 var error = new _LoadError(req, dataOrError.toString()); |
| 376 _asyncLoadError(req, error, null); | 383 _asyncLoadError(req, error, null); |
| 377 } | 384 } |
| 378 } catch(e, s) { | 385 } catch(e, s) { |
| 379 // Wrap inside a _LoadError unless we are already propagating a | 386 // Wrap inside a _LoadError unless we are already propagating a |
| 380 // previous _LoadError. | 387 // previous _LoadError. |
| 381 var error = (e is _LoadError) ? e : new _LoadError(req._uri, e.toString()); | 388 var error = (e is _LoadError) ? e : new _LoadError(req, e.toString()); |
| 382 assert(req != null); | 389 assert(req != null); |
| 383 _asyncLoadError(req, error, s); | 390 _asyncLoadError(req, error, s); |
| 384 } | 391 } |
| 385 } | 392 } |
| 386 | 393 |
| 387 | 394 |
| 388 void _startLoadRequest(int tag, String uri, Uri resourceUri, context) { | 395 void _startLoadRequest(int tag, String uri, Uri resourceUri, context) { |
| 389 if (_dataPort == null) { | 396 if (_dataPort == null) { |
| 390 if (_traceLoading) { | 397 if (_traceLoading) { |
| 391 _log("Initializing load port."); | 398 _log("Initializing load port."); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 } | 576 } |
| 570 | 577 |
| 571 | 578 |
| 572 _loadDataFromLoadPort(int tag, String uri, Uri resourceUri, context) { | 579 _loadDataFromLoadPort(int tag, String uri, Uri resourceUri, context) { |
| 573 try { | 580 try { |
| 574 _startLoadRequest(tag, uri, resourceUri, context); | 581 _startLoadRequest(tag, uri, resourceUri, context); |
| 575 } catch (e, s) { | 582 } catch (e, s) { |
| 576 if (_traceLoading) { | 583 if (_traceLoading) { |
| 577 _log("Exception when communicating with service isolate: $e"); | 584 _log("Exception when communicating with service isolate: $e"); |
| 578 } | 585 } |
| 586 // Register a dummy load request so we can fail to load it. |
| 587 var req = new _LoadRequest(tag, uri, resourceUri, context); |
| 588 |
| 579 // Wrap inside a _LoadError unless we are already propagating a previously | 589 // Wrap inside a _LoadError unless we are already propagating a previously |
| 580 // seen _LoadError. | 590 // seen _LoadError. |
| 581 var error = (e is _LoadError) ? e : new _LoadError(uri, e.toString()); | 591 var error = (e is _LoadError) ? e : new _LoadError(req, e.toString()); |
| 582 // Register a dummy load request and fail to load it. | |
| 583 var req = new _LoadRequest(tag, uri, resourceUri, context); | |
| 584 _asyncLoadError(req, error, s); | 592 _asyncLoadError(req, error, s); |
| 585 } | 593 } |
| 586 } | 594 } |
| 587 | 595 |
| 588 | 596 |
| 589 // Loading a package URI needs to first map the package name to a loadable | 597 // Loading a package URI needs to first map the package name to a loadable |
| 590 // URI. | 598 // URI. |
| 591 _loadPackage(int tag, String uri, Uri resourceUri, context) { | 599 _loadPackage(int tag, String uri, Uri resourceUri, context) { |
| 592 if (_packagesReady) { | 600 if (_packagesReady) { |
| 593 var resolvedUri; | 601 var resolvedUri; |
| 594 try { | 602 try { |
| 595 resolvedUri = _resolvePackageUri(resourceUri); | 603 resolvedUri = _resolvePackageUri(resourceUri); |
| 596 } catch (e, s) { | 604 } catch (e, s) { |
| 597 if (_traceLoading) { | 605 if (_traceLoading) { |
| 598 _log("Exception ($e) when resolving package URI: $resourceUri"); | 606 _log("Exception ($e) when resolving package URI: $resourceUri"); |
| 599 } | 607 } |
| 608 // Register a dummy load request so we can fail to load it. |
| 609 var req = new _LoadRequest(tag, uri, resourceUri, context); |
| 610 |
| 600 // Wrap inside a _LoadError unless we are already propagating a previously | 611 // Wrap inside a _LoadError unless we are already propagating a previously |
| 601 // seen _LoadError. | 612 // seen _LoadError. |
| 602 var error = (e is _LoadError) ? e : new _LoadError(uri, e.toString()); | 613 var error = (e is _LoadError) ? e : new _LoadError(req, 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); | 614 _asyncLoadError(req, error, s); |
| 606 } | 615 } |
| 607 _loadData(tag, uri, resolvedUri, context); | 616 _loadData(tag, uri, resolvedUri, context); |
| 608 } else { | 617 } else { |
| 609 if (_pendingPackageLoads.isEmpty) { | 618 if (_pendingPackageLoads.isEmpty) { |
| 610 // Package resolution has not been setup yet, and this is the first | 619 // Package resolution has not been setup yet, and this is the first |
| 611 // request for package resolution & loading. | 620 // request for package resolution & loading. |
| 612 _requestPackagesMap(); | 621 _requestPackagesMap(); |
| 613 } | 622 } |
| 614 // Register the action of loading this package once the package resolution | 623 // Register the action of loading this package once the package resolution |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 | 887 |
| 879 // Register callbacks and hooks with the rest of the core libraries. | 888 // Register callbacks and hooks with the rest of the core libraries. |
| 880 _setupHooks() { | 889 _setupHooks() { |
| 881 _setupCompleted = true; | 890 _setupCompleted = true; |
| 882 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; | 891 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; |
| 883 | 892 |
| 884 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; | 893 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; |
| 885 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; | 894 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; |
| 886 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; | 895 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; |
| 887 } | 896 } |
| OLD | NEW |