Chromium Code Reviews| 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 if (e is! _LoadError) { |
| 389 print("Wrapped error is $e"); | |
|
Ivan Posva
2016/01/29 23:33:29
Don't think this is needed.
turnidge
2016/01/30 00:29:00
Done.
| |
| 390 } | |
| 391 var error = | |
| 392 (e is _LoadError) ? e : new _LoadError(req, e.toString()); | |
|
Ivan Posva
2016/01/29 23:33:29
Put back on one line.
turnidge
2016/01/30 00:29:00
Done.
| |
| 382 assert(req != null); | 393 assert(req != null); |
| 383 _asyncLoadError(req, error, s); | 394 _asyncLoadError(req, error, s); |
| 384 } | 395 } |
| 385 } | 396 } |
| 386 | 397 |
| 387 | 398 |
| 388 void _startLoadRequest(int tag, String uri, Uri resourceUri, context) { | 399 void _startLoadRequest(int tag, String uri, Uri resourceUri, context) { |
| 389 if (_dataPort == null) { | 400 if (_dataPort == null) { |
| 390 if (_traceLoading) { | 401 if (_traceLoading) { |
| 391 _log("Initializing load port."); | 402 _log("Initializing load port."); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 } | 580 } |
| 570 | 581 |
| 571 | 582 |
| 572 _loadDataFromLoadPort(int tag, String uri, Uri resourceUri, context) { | 583 _loadDataFromLoadPort(int tag, String uri, Uri resourceUri, context) { |
| 573 try { | 584 try { |
| 574 _startLoadRequest(tag, uri, resourceUri, context); | 585 _startLoadRequest(tag, uri, resourceUri, context); |
| 575 } catch (e, s) { | 586 } catch (e, s) { |
| 576 if (_traceLoading) { | 587 if (_traceLoading) { |
| 577 _log("Exception when communicating with service isolate: $e"); | 588 _log("Exception when communicating with service isolate: $e"); |
| 578 } | 589 } |
| 590 // Register a dummy load request and fail to load it. | |
|
Ivan Posva
2016/01/29 23:33:29
// Register a dummy load request so we can fail to
turnidge
2016/01/30 00:29:00
Done.
| |
| 591 var req = new _LoadRequest(tag, uri, resourceUri, context); | |
| 592 | |
| 579 // Wrap inside a _LoadError unless we are already propagating a previously | 593 // Wrap inside a _LoadError unless we are already propagating a previously |
| 580 // seen _LoadError. | 594 // seen _LoadError. |
| 581 var error = (e is _LoadError) ? e : new _LoadError(uri, e.toString()); | 595 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); | 596 _asyncLoadError(req, error, s); |
| 585 } | 597 } |
| 586 } | 598 } |
| 587 | 599 |
| 588 | 600 |
| 589 // Loading a package URI needs to first map the package name to a loadable | 601 // Loading a package URI needs to first map the package name to a loadable |
| 590 // URI. | 602 // URI. |
| 591 _loadPackage(int tag, String uri, Uri resourceUri, context) { | 603 _loadPackage(int tag, String uri, Uri resourceUri, context) { |
| 592 if (_packagesReady) { | 604 if (_packagesReady) { |
| 593 var resolvedUri; | 605 var resolvedUri; |
| 594 try { | 606 try { |
| 595 resolvedUri = _resolvePackageUri(resourceUri); | 607 resolvedUri = _resolvePackageUri(resourceUri); |
| 596 } catch (e, s) { | 608 } catch (e, s) { |
| 597 if (_traceLoading) { | 609 if (_traceLoading) { |
| 598 _log("Exception ($e) when resolving package URI: $resourceUri"); | 610 _log("Exception ($e) when resolving package URI: $resourceUri"); |
| 599 } | 611 } |
| 612 // Register a dummy load request and fail to load it. | |
|
Ivan Posva
2016/01/29 23:33:29
ditto
turnidge
2016/01/30 00:29:00
Done.
| |
| 613 var req = new _LoadRequest(tag, uri, resourceUri, context); | |
| 614 | |
| 600 // Wrap inside a _LoadError unless we are already propagating a previously | 615 // Wrap inside a _LoadError unless we are already propagating a previously |
| 601 // seen _LoadError. | 616 // seen _LoadError. |
| 602 var error = (e is _LoadError) ? e : new _LoadError(uri, e.toString()); | 617 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); | 618 _asyncLoadError(req, error, s); |
| 606 } | 619 } |
| 607 _loadData(tag, uri, resolvedUri, context); | 620 _loadData(tag, uri, resolvedUri, context); |
| 608 } else { | 621 } else { |
| 609 if (_pendingPackageLoads.isEmpty) { | 622 if (_pendingPackageLoads.isEmpty) { |
| 610 // Package resolution has not been setup yet, and this is the first | 623 // Package resolution has not been setup yet, and this is the first |
| 611 // request for package resolution & loading. | 624 // request for package resolution & loading. |
| 612 _requestPackagesMap(); | 625 _requestPackagesMap(); |
| 613 } | 626 } |
| 614 // Register the action of loading this package once the package resolution | 627 // 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 | 891 |
| 879 // Register callbacks and hooks with the rest of the core libraries. | 892 // Register callbacks and hooks with the rest of the core libraries. |
| 880 _setupHooks() { | 893 _setupHooks() { |
| 881 _setupCompleted = true; | 894 _setupCompleted = true; |
| 882 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; | 895 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; |
| 883 | 896 |
| 884 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; | 897 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; |
| 885 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; | 898 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; |
| 886 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; | 899 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; |
| 887 } | 900 } |
| OLD | NEW |