| 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 'dart:convert'; | 8 import 'dart:convert'; |
| 9 // import 'root_library'; happens here from C Code | 9 // import 'root_library'; happens here from C Code |
| 10 | 10 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd); | 190 _workingWindowsDrivePrefix = _extractDriveLetterPrefix(cwd); |
| 191 _workingDirectoryUri = new Uri.file(cwd); | 191 _workingDirectoryUri = new Uri.file(cwd); |
| 192 if (!_workingDirectoryUri.path.endsWith("/")) { | 192 if (!_workingDirectoryUri.path.endsWith("/")) { |
| 193 var directoryPath = _workingDirectoryUri.path + "/"; | 193 var directoryPath = _workingDirectoryUri.path + "/"; |
| 194 _workingDirectoryUri = _workingDirectoryUri.resolve(directoryPath); | 194 _workingDirectoryUri = _workingDirectoryUri.resolve(directoryPath); |
| 195 } | 195 } |
| 196 | 196 |
| 197 _logResolution('# Working Directory: $cwd'); | 197 _logResolution('# Working Directory: $cwd'); |
| 198 } | 198 } |
| 199 | 199 |
| 200 Uri _uriFromPathOrUri(String location) { |
| 201 if (location.startsWith('file:') || |
| 202 location.startsWith('http:') || |
| 203 location.startsWith('https:')) { |
| 204 return Uri.parse(location); |
| 205 } |
| 206 return new Uri.file(location); |
| 207 } |
| 200 | 208 |
| 201 _setPackageRoot(String packageRoot) { | 209 _setPackageRoot(String packageRoot) { |
| 202 packageRoot = _enforceTrailingSlash(packageRoot); | 210 packageRoot = _enforceTrailingSlash(packageRoot); |
| 203 if (packageRoot.startsWith('file:') || | 211 _packageRoot = |
| 204 packageRoot.startsWith('http:') || | 212 _workingDirectoryUri.resolveUri(_uriFromPathOrUri(packageRoot)); |
| 205 packageRoot.startsWith('https:')) { | |
| 206 _packageRoot = _workingDirectoryUri.resolve(packageRoot); | |
| 207 } else { | |
| 208 _packageRoot = _workingDirectoryUri.resolveUri(new Uri.file(packageRoot)); | |
| 209 } | |
| 210 _logResolution('# Package root: $packageRoot -> $_packageRoot'); | 213 _logResolution('# Package root: $packageRoot -> $_packageRoot'); |
| 211 } | 214 } |
| 212 | 215 |
| 213 | 216 |
| 214 String _resolveScriptUri(String scriptName) { | 217 String _resolveScriptUri(String scriptName) { |
| 215 if (_workingDirectoryUri == null) { | 218 if (_workingDirectoryUri == null) { |
| 216 throw 'No current working directory set.'; | 219 throw 'No current working directory set.'; |
| 217 } | 220 } |
| 218 var scriptUri; | 221 var scriptUri = _uriFromPathOrUri(scriptName); |
| 219 if (scriptName.startsWith("file:") || | |
| 220 scriptName.startsWith("http:") || | |
| 221 scriptName.startsWith("https:")) { | |
| 222 scriptUri = Uri.parse(scriptName); | |
| 223 } else { | |
| 224 // Assume it's a file name. | |
| 225 scriptUri = new Uri.file(scriptName); | |
| 226 } | |
| 227 if (scriptUri.scheme != '') { | 222 if (scriptUri.scheme != '') { |
| 228 // Script has a scheme, assume that it is fully formed. | 223 // Script has a scheme, assume that it is fully formed. |
| 229 _entryPointScript = scriptUri; | 224 _entryPointScript = scriptUri; |
| 230 } else { | 225 } else { |
| 231 // Script does not have a scheme, assume that it is a path, | 226 // Script does not have a scheme, assume that it is a path, |
| 232 // resolve it against the working directory. | 227 // resolve it against the working directory. |
| 233 _entryPointScript = _workingDirectoryUri.resolve(scriptName); | 228 _entryPointScript = _workingDirectoryUri.resolve(scriptName); |
| 234 } | 229 } |
| 235 _logResolution('# Resolved entry point to: $_entryPointScript'); | 230 _logResolution('# Resolved entry point to: $_entryPointScript'); |
| 236 return _entryPointScript.toString(); | 231 return _entryPointScript.toString(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 assert(_numOutstandingLoadRequests > 0); | 314 assert(_numOutstandingLoadRequests > 0); |
| 320 _numOutstandingLoadRequests--; | 315 _numOutstandingLoadRequests--; |
| 321 _asyncLoadErrorCallback(uri, error); | 316 _asyncLoadErrorCallback(uri, error); |
| 322 } | 317 } |
| 323 | 318 |
| 324 | 319 |
| 325 // Asynchronously loads script data (source or snapshot) through | 320 // Asynchronously loads script data (source or snapshot) through |
| 326 // an http or file uri. | 321 // an http or file uri. |
| 327 _loadDataAsync(String uri) { | 322 _loadDataAsync(String uri) { |
| 328 uri = _resolveScriptUri(uri); | 323 uri = _resolveScriptUri(uri); |
| 329 Uri sourceUri = Uri.parse(uri); | 324 Uri sourceUri = _uriFromPathOrUri(uri); |
| 330 _numOutstandingLoadRequests++; | 325 _numOutstandingLoadRequests++; |
| 331 _logResolution("_loadDataAsync($uri), " | 326 _logResolution("_loadDataAsync($uri), " |
| 332 "${_numOutstandingLoadRequests} requests outstanding"); | 327 "${_numOutstandingLoadRequests} requests outstanding"); |
| 333 if (sourceUri.scheme == 'http') { | 328 if (sourceUri.scheme == 'http') { |
| 334 _httpGet(sourceUri, (data) { | 329 _httpGet(sourceUri, (data) { |
| 335 _loadScript(uri, data); | 330 _loadScript(uri, data); |
| 336 }); | 331 }); |
| 337 } else { | 332 } else { |
| 338 var sourceFile = new File(_filePathFromUri(uri)); | 333 var sourceFile = new File(_filePathFromUri(uri)); |
| 339 sourceFile.readAsBytes().then((data) { | 334 sourceFile.readAsBytes().then((data) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } else if (Platform.isWindows) { | 421 } else if (Platform.isWindows) { |
| 427 filename = '$name.dll'; | 422 filename = '$name.dll'; |
| 428 } else { | 423 } else { |
| 429 _logResolution( | 424 _logResolution( |
| 430 'Native extensions not supported on ${Platform.operatingSystem}'); | 425 'Native extensions not supported on ${Platform.operatingSystem}'); |
| 431 throw 'Native extensions not supported on ${Platform.operatingSystem}'; | 426 throw 'Native extensions not supported on ${Platform.operatingSystem}'; |
| 432 } | 427 } |
| 433 | 428 |
| 434 return [path, filename, name]; | 429 return [path, filename, name]; |
| 435 } | 430 } |
| OLD | NEW |