| 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 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 // import 'root_library'; happens here from C Code | 8 // import 'root_library'; happens here from C Code |
| 9 | 9 |
| 10 // The root library (aka the script) is imported into this library. The | 10 // The root library (aka the script) is imported into this library. The |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 String _resolveUri(String base, String userString) { | 209 String _resolveUri(String base, String userString) { |
| 210 var baseUri = Uri.parse(base); | 210 var baseUri = Uri.parse(base); |
| 211 _logResolution('# Resolving: $userString from $base'); | 211 _logResolution('# Resolving: $userString from $base'); |
| 212 | 212 |
| 213 var uri = Uri.parse(userString); | 213 var uri = Uri.parse(userString); |
| 214 var resolved; | 214 var resolved; |
| 215 if ('dart-ext' == uri.scheme) { | 215 if ('dart-ext' == uri.scheme) { |
| 216 // Relative URIs with scheme dart-ext should be resolved as if with no | 216 // Relative URIs with scheme dart-ext should be resolved as if with no |
| 217 // scheme. | 217 // scheme. |
| 218 resolved = baseUri.resolve(uri.path); | 218 resolved = baseUri.resolve(uri.path); |
| 219 var path = resolved.path; | |
| 220 if (resolved.scheme == 'package') { | 219 if (resolved.scheme == 'package') { |
| 221 // If we are resolving relative to a package URI we go directly to the | 220 // If we are resolving relative to a package URI we go directly to the |
| 222 // file path and keep the dart-ext scheme. Otherwise, we will lose the | 221 // file path and keep the dart-ext scheme. Otherwise, we will lose the |
| 223 // package URI path part. | 222 // package URI path part. |
| 224 path = _filePathFromPackageUri(resolved); | 223 var path = _filePathFromPackageUri(resolved); |
| 224 if (path.startsWith('http:')) { |
| 225 throw "Native extensions not supported in " |
| 226 "packages loaded over http: %path"; |
| 227 } |
| 228 resolved = new Uri.file(path); |
| 225 } | 229 } |
| 226 resolved = new Uri(scheme: 'dart-ext', path: path); | 230 resolved = new Uri(scheme: 'dart-ext', path: resolved.path); |
| 227 } else { | 231 } else { |
| 228 resolved = baseUri.resolve(userString); | 232 resolved = baseUri.resolve(userString); |
| 229 } | 233 } |
| 230 _logResolution('# Resolved to: $resolved'); | 234 _logResolution('# Resolved to: $resolved'); |
| 231 return resolved.toString(); | 235 return resolved.toString(); |
| 232 } | 236 } |
| 233 | 237 |
| 234 | 238 |
| 235 // Returns either a file path or a URI starting with http:, as a String. | 239 // Returns either a file path or a URI starting with http:, as a String. |
| 236 String _filePathFromUri(String userUri) { | 240 String _filePathFromUri(String userUri) { |
| 237 var uri = Uri.parse(userUri); | 241 var uri = Uri.parse(userUri); |
| 238 _logResolution('# Getting file path from: $uri'); | 242 _logResolution('# Getting file path from: $uri'); |
| 239 | 243 |
| 240 var path; | 244 var path; |
| 241 switch (uri.scheme) { | 245 switch (uri.scheme) { |
| 242 case '': | 246 case '': |
| 243 case 'file': | 247 case 'file': |
| 244 return uri.toFilePath(); | 248 return uri.toFilePath(); |
| 245 break; | 249 break; |
| 246 case 'dart-ext': | 250 case 'dart-ext': |
| 247 return new Uri(scheme: 'file', | 251 // Relative file URIs don't start with file:///. |
| 252 var scheme = (uri.path.startsWith('/') ? 'file' : ''); |
| 253 return new Uri(scheme: scheme, |
| 248 host: uri.host, | 254 host: uri.host, |
| 249 path: uri.path).toFilePath(); | 255 path: uri.path).toFilePath(); |
| 250 break; | 256 break; |
| 251 case 'package': | 257 case 'package': |
| 252 return _filePathFromPackageUri(uri); | 258 return _filePathFromPackageUri(uri); |
| 253 break; | 259 break; |
| 254 case 'http': | 260 case 'http': |
| 255 return uri.toString(); | 261 return uri.toString(); |
| 256 default: | 262 default: |
| 257 // Only handling file, dart-ext, http, and package URIs | 263 // Only handling file, dart-ext, http, and package URIs |
| (...skipping 12 matching lines...) Expand all Loading... |
| 270 | 276 |
| 271 throw "URIs using the 'package:' scheme should look like " | 277 throw "URIs using the 'package:' scheme should look like " |
| 272 "'$right', not '$wrong'."; | 278 "'$right', not '$wrong'."; |
| 273 } | 279 } |
| 274 | 280 |
| 275 var packageRoot = _packageRoot == null ? | 281 var packageRoot = _packageRoot == null ? |
| 276 _entryPointScript.resolve('packages/') : | 282 _entryPointScript.resolve('packages/') : |
| 277 _packageRoot; | 283 _packageRoot; |
| 278 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); | 284 return _filePathFromUri(packageRoot.resolve(uri.path).toString()); |
| 279 } | 285 } |
| OLD | NEW |