Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(709)

Side by Side Diff: runtime/bin/builtin.dart

Issue 2004933002: Simplify the canonicalization of dart-ext uris. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/bin/dartutils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 // Function called by standalone embedder to resolve uris when the VM requests 695 // Function called by standalone embedder to resolve uris when the VM requests
696 // Dart_kCanonicalizeUrl from the tag handler. 696 // Dart_kCanonicalizeUrl from the tag handler.
697 String _resolveUri(String base, String userString) { 697 String _resolveUri(String base, String userString) {
698 if (!_setupCompleted) { 698 if (!_setupCompleted) {
699 _setupHooks(); 699 _setupHooks();
700 } 700 }
701 if (_traceLoading) { 701 if (_traceLoading) {
702 _log('Resolving: $userString from $base'); 702 _log('Resolving: $userString from $base');
703 } 703 }
704 var baseUri = Uri.parse(base); 704 var baseUri = Uri.parse(base);
705 var result; 705 var result = baseUri.resolve(userString).toString();
706 if (userString.startsWith(_DART_EXT)) {
707 var uri = userString.substring(_DART_EXT.length);
708 result = '$_DART_EXT${baseUri.resolve(uri)}';
709 } else {
710 result = baseUri.resolve(userString).toString();
711 }
712 if (_traceLoading) { 706 if (_traceLoading) {
713 _log('Resolved $userString in $base to $result'); 707 _log('Resolved $userString in $base to $result');
714 } 708 }
715 return result; 709 return result;
716 } 710 }
717 711
718 712
719 // Handling of access to the package root or package map from user code. 713 // Handling of access to the package root or package map from user code.
720 _triggerPackageResolution(action) { 714 _triggerPackageResolution(action) {
721 if (_packagesReady) { 715 if (_packagesReady) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 } 818 }
825 uri = _workingDirectory.resolveUri(uri); 819 uri = _workingDirectory.resolveUri(uri);
826 820
827 if (_traceLoading) { 821 if (_traceLoading) {
828 _log('Resolved in working directory: $fileName -> $uri'); 822 _log('Resolved in working directory: $fileName -> $uri');
829 } 823 }
830 return uri.toString(); 824 return uri.toString();
831 } 825 }
832 826
833 827
834 // Handling of dart-ext loading.
835 // Dart native extension scheme.
836 const _DART_EXT = 'dart-ext:';
837
838 // Returns either a file path or a URI starting with http[s]:, as a String. 828 // Returns either a file path or a URI starting with http[s]:, as a String.
839 String _filePathFromUri(String userUri) { 829 String _filePathFromUri(String userUri) {
840 var uri = Uri.parse(userUri); 830 var uri = Uri.parse(userUri);
841 if (_traceLoading) { 831 if (_traceLoading) {
842 _log('Getting file path from: $uri'); 832 _log('Getting file path from: $uri');
843 } 833 }
844 834
845 var path; 835 var path;
846 switch (uri.scheme) { 836 switch (uri.scheme) {
847 case '': 837 case '':
848 case 'file': 838 case 'file':
849 return uri.toFilePath(); 839 return uri.toFilePath();
850 case 'package': 840 case 'package':
851 return _filePathFromUri(_resolvePackageUri(uri).toString()); 841 return _filePathFromUri(_resolvePackageUri(uri).toString());
852 case 'data': 842 case 'data':
853 case 'http': 843 case 'http':
854 case 'https': 844 case 'https':
855 return uri.toString(); 845 return uri.toString();
856 default: 846 default:
857 // Only handling file, http, and package URIs 847 // Only handling file, http, and package URIs
858 // in standalone binary. 848 // in standalone binary.
859 if (_traceLoading) { 849 if (_traceLoading) {
860 _log('Unknown scheme (${uri.scheme}) in $uri.'); 850 _log('Unknown scheme (${uri.scheme}) in $uri.');
861 } 851 }
862 throw 'Not a known scheme: $uri'; 852 throw 'Not a known scheme: $uri';
863 } 853 }
864 } 854 }
865 855
866 856
867 // Embedder Entrypoint: 857 // Embedder Entrypoint.
868 // When loading an extension the embedder calls this method to get the 858 _libraryFilePath(String libraryUri) {
869 // different components.
870 // Returns the directory part, the filename part, and the name
871 // of a native extension URL as a list [directory, filename, name].
872 // The directory part is either a file system path or an HTTP(S) URL.
873 // The filename part is the extension name, with the platform-dependent
874 // prefixes and extensions added.
875 _extensionPathFromUri(String userUri) {
876 if (!_setupCompleted) { 859 if (!_setupCompleted) {
877 _setupHooks(); 860 _setupHooks();
878 } 861 }
879 if (!userUri.startsWith(_DART_EXT)) { 862 int index = libraryUri.lastIndexOf('/');
880 throw 'Unexpected internal error: Extension URI $userUri missing dart-ext:'; 863 var path;
864 if (index == -1) {
865 path = './';
866 } else {
867 path = libraryUri.substring(0, index + 1);
881 } 868 }
882 userUri = userUri.substring(_DART_EXT.length); 869 return _filePathFromUri(path);
883
884 if (userUri.contains('\\')) {
885 throw 'Unexpected internal error: Extension URI $userUri contains \\';
886 }
887
888 String name;
889 String path; // Will end in '/'.
890 int index = userUri.lastIndexOf('/');
891 if (index == -1) {
892 name = userUri;
893 path = './';
894 } else if (index == userUri.length - 1) {
895 throw 'Extension name missing in $extensionUri';
896 } else {
897 name = userUri.substring(index + 1);
898 path = userUri.substring(0, index + 1);
899 }
900 path = _filePathFromUri(path);
901
902 return [path, name];
903 } 870 }
904 871
905 872
906 // Register callbacks and hooks with the rest of the core libraries. 873 // Register callbacks and hooks with the rest of the core libraries.
907 _setupHooks() { 874 _setupHooks() {
908 _setupCompleted = true; 875 _setupCompleted = true;
909 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes; 876 VMLibraryHooks.resourceReadAsBytes = _resourceReadAsBytes;
910 877
911 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture; 878 VMLibraryHooks.packageRootUriFuture = _getPackageRootFuture;
912 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture; 879 VMLibraryHooks.packageConfigUriFuture = _getPackageConfigFuture;
913 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture; 880 VMLibraryHooks.resolvePackageUriFuture = _resolvePackageUriFuture;
914 } 881 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/dartutils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698