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

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

Issue 10386107: Implement spawnUri from dart:isolate. This function allows us to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/builtin.cc ('k') | 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 #import("dart:uri"); 6 #import("dart:uri");
7 7
8 void print(arg) { 8 void print(arg) {
9 _Logger._printString(arg.toString()); 9 _Logger._printString(arg.toString());
10 } 10 }
11 11
12 void exit(int status) { 12 void exit(int status) {
13 if (status is !int) { 13 if (status is !int) {
14 throw new IllegalArgumentException("int status expected"); 14 throw new IllegalArgumentException("int status expected");
15 } 15 }
16 _exit(status); 16 _exit(status);
17 } 17 }
18 18
19 _exit(int status) native "Exit"; 19 _exit(int status) native "Exit";
20 20
21 class _Logger { 21 class _Logger {
22 static void _printString(String s) native "Logger_PrintString"; 22 static void _printString(String s) native "Logger_PrintString";
23 } 23 }
24 24
25 25
26 // Code to deal with URI resolution for the standalone binary.
27 // For Windows we need to massage the paths a bit according to
28 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx
29 var _is_windows;
30
31 // The URI that the entrypoint script was loaded from. Remembered so that 26 // The URI that the entrypoint script was loaded from. Remembered so that
32 // package imports can be resolved relative to it. 27 // package imports can be resolved relative to it.
33 var _entrypoint; 28 var _entrypoint;
34 29
35 // The directory to look in to resolve "package:" scheme URIs. 30 // The directory to look in to resolve "package:" scheme URIs.
36 var _packageRoot; 31 var _packageRoot;
37 32
38 void _logResolution(String msg) { 33 void _logResolution(String msg) {
39 final enabled = false; 34 final enabled = false;
40 if (enabled) { 35 if (enabled) {
41 _Logger._printString(msg); 36 _Logger._printString(msg);
42 } 37 }
43 } 38 }
44 39
45 String _setPackageRoot(String packageRoot) { 40 String _setPackageRoot(String packageRoot) {
46 // TODO(mattsh) - refactor windows drive and path handling code 41 // TODO(mattsh) - refactor windows drive and path handling code
47 // so it can be used here if needed. 42 // so it can be used here if needed.
48 _packageRoot = packageRoot; 43 _packageRoot = packageRoot;
49 } 44 }
50 45
51 String _resolveScriptUri(String cwd, String scriptName, bool windows) { 46 String _resolveScriptUri(String cwd, String scriptName, bool isWindows) {
52 _is_windows = windows;
53 _logResolution("# Current working directory: $cwd"); 47 _logResolution("# Current working directory: $cwd");
54 _logResolution("# ScriptName: $scriptName"); 48 _logResolution("# ScriptName: $scriptName");
55 if (windows) { 49 if (isWindows) {
50 // For Windows we need to massage the paths a bit according to
51 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx
52 //
56 // Convert 53 // Convert
57 // C:\one\two\three 54 // C:\one\two\three
58 // to 55 // to
59 // /C:/one/two/three 56 // /C:/one/two/three
60 cwd = "/${cwd.replaceAll('\\', '/')}"; 57 cwd = "/${cwd.replaceAll('\\', '/')}";
61 _logResolution("## cwd: $cwd"); 58 _logResolution("## cwd: $cwd");
62 if ((scriptName.length > 2) && (scriptName[1] == ":")) { 59 if ((scriptName.length > 2) && (scriptName[1] == ":")) {
63 // This is an absolute path. 60 // This is an absolute path.
64 scriptName = "/${scriptName.replaceAll('\\', '/')}"; 61 scriptName = "/${scriptName.replaceAll('\\', '/')}";
65 } else { 62 } else {
(...skipping 19 matching lines...) Expand all
85 resolved = baseUri.resolve(uri.path); 82 resolved = baseUri.resolve(uri.path);
86 resolved = new Uri(scheme: "dart-ext", path: resolved.path); 83 resolved = new Uri(scheme: "dart-ext", path: resolved.path);
87 } else { 84 } else {
88 resolved = baseUri.resolve(userString); 85 resolved = baseUri.resolve(userString);
89 } 86 }
90 _logResolution("# Resolved to: $resolved"); 87 _logResolution("# Resolved to: $resolved");
91 return resolved.toString(); 88 return resolved.toString();
92 } 89 }
93 90
94 91
95 String _filePathFromUri(String userUri) { 92 String _filePathFromUri(String userUri, bool isWindows) {
96 var uri = new Uri.fromString(userUri); 93 var uri = new Uri.fromString(userUri);
97 _logResolution("# Getting file path from: $uri"); 94 _logResolution("# Getting file path from: $uri");
98 95
99 var path; 96 var path;
100 switch (uri.scheme) { 97 switch (uri.scheme) {
101 case 'file': 98 case 'file':
102 path = _filePathFromFileUri(uri); 99 path = _filePathFromFileUri(uri);
103 break; 100 break;
104 case 'dart-ext': 101 case 'dart-ext':
105 path = _filePathFromOtherUri(uri); 102 path = _filePathFromOtherUri(uri);
106 break; 103 break;
107 case 'package': 104 case 'package':
108 path = _filePathFromPackageUri(uri); 105 path = _filePathFromPackageUri(uri);
109 break; 106 break;
110 default: 107 default:
111 // Only handling file and package URIs in standalone binary. 108 // Only handling file and package URIs in standalone binary.
112 _logResolution("# Unknown scheme (${uri.scheme}) in $uri."); 109 _logResolution("# Unknown scheme (${uri.scheme}) in $uri.");
113 throw "Not a known scheme: $uri"; 110 throw "Not a known scheme: $uri";
114 } 111 }
115 112
116 if (_is_windows) { 113 if (isWindows) {
114 // For Windows we need to massage the paths a bit according to
115 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx
116 //
117 // Drop the leading / before the drive letter. 117 // Drop the leading / before the drive letter.
118 path = path.substring(1); 118 path = path.substring(1);
119 _logResolution("# path: $path"); 119 _logResolution("# path: $path");
120 } 120 }
121 121
122 return path; 122 return path;
123 } 123 }
124 124
125 String _filePathFromFileUri(Uri uri) { 125 String _filePathFromFileUri(Uri uri) {
126 if (uri.domain != '') { 126 if (uri.domain != '') {
(...skipping 26 matching lines...) Expand all
153 var path; 153 var path;
154 if (_packageRoot !== null) { 154 if (_packageRoot !== null) {
155 path = "${_packageRoot}${uri.path}"; 155 path = "${_packageRoot}${uri.path}";
156 } else { 156 } else {
157 path = _entrypoint.resolve('packages/${uri.path}').path; 157 path = _entrypoint.resolve('packages/${uri.path}').path;
158 } 158 }
159 159
160 _logResolution("# Package: $path"); 160 _logResolution("# Package: $path");
161 return path; 161 return path;
162 } 162 }
OLDNEW
« no previous file with comments | « runtime/bin/builtin.cc ('k') | runtime/bin/dartutils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698