| 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 |
| 6 // NOTE: Do not import 'dart:io' in builtin. | 7 // NOTE: Do not import 'dart:io' in builtin. |
| 7 import 'dart:async'; | 8 import 'dart:async'; |
| 8 import 'dart:collection'; | 9 import 'dart:collection'; |
| 9 import 'dart:_internal' hide Symbol; | 10 import 'dart:_internal' hide Symbol; |
| 10 import 'dart:isolate'; | 11 import 'dart:isolate'; |
| 11 import 'dart:typed_data'; | 12 import 'dart:typed_data'; |
| 12 | 13 |
| 13 // Embedder sets this to true if the --trace-loading flag was passed on the | 14 // Embedder sets this to true if the --trace-loading flag was passed on the |
| 14 // command line. | 15 // command line. |
| 15 bool _traceLoading = false; | 16 bool _traceLoading = false; |
| 16 | 17 |
| 17 | |
| 18 // Before handling an embedder entrypoint we finalize the setup of the | 18 // Before handling an embedder entrypoint we finalize the setup of the |
| 19 // dart:_builtin library. | 19 // dart:_builtin library. |
| 20 bool _setupCompleted = false; | 20 bool _setupCompleted = false; |
| 21 | 21 |
| 22 | |
| 23 // The root library (aka the script) is imported into this library. The | 22 // The root library (aka the script) is imported into this library. The |
| 24 // standalone embedder uses this to lookup the main entrypoint in the | 23 // standalone embedder uses this to lookup the main entrypoint in the |
| 25 // root library's namespace. | 24 // root library's namespace. |
| 26 Function _getMainClosure() => main; | 25 Function _getMainClosure() => main; |
| 27 | 26 |
| 28 | |
| 29 // 'print' implementation. | 27 // 'print' implementation. |
| 30 // The standalone embedder registers the closurized _print function with the | 28 // The standalone embedder registers the closurized _print function with the |
| 31 // dart:core library. | 29 // dart:core library. |
| 32 void _printString(String s) native "Builtin_PrintString"; | 30 void _printString(String s) native "Builtin_PrintString"; |
| 33 | 31 |
| 34 | |
| 35 void _print(arg) { | 32 void _print(arg) { |
| 36 _printString(arg.toString()); | 33 _printString(arg.toString()); |
| 37 } | 34 } |
| 38 | 35 |
| 39 | |
| 40 _getPrintClosure() => _print; | 36 _getPrintClosure() => _print; |
| 41 | 37 |
| 42 | |
| 43 // Corelib 'Uri.base' implementation. | 38 // Corelib 'Uri.base' implementation. |
| 44 // Uri.base is susceptible to changes in the current working directory. | 39 // Uri.base is susceptible to changes in the current working directory. |
| 45 _getCurrentDirectoryPath() native "Builtin_GetCurrentDirectory"; | 40 _getCurrentDirectoryPath() native "Builtin_GetCurrentDirectory"; |
| 46 | 41 |
| 47 | |
| 48 Uri _uriBase() { | 42 Uri _uriBase() { |
| 49 // We are not using Dircetory.current here to limit the dependency | 43 // We are not using Dircetory.current here to limit the dependency |
| 50 // on dart:io. This code is the same as: | 44 // on dart:io. This code is the same as: |
| 51 // return new Uri.directory(Directory.current.path); | 45 // return new Uri.directory(Directory.current.path); |
| 52 var path = _getCurrentDirectoryPath(); | 46 var path = _getCurrentDirectoryPath(); |
| 53 return new Uri.directory(path); | 47 return new Uri.directory(path); |
| 54 } | 48 } |
| 55 | 49 |
| 56 | |
| 57 _getUriBaseClosure() => _uriBase; | 50 _getUriBaseClosure() => _uriBase; |
| 58 | 51 |
| 59 // Asynchronous loading of resources. | 52 // Asynchronous loading of resources. |
| 60 // The embedder forwards loading requests to the service isolate. | 53 // The embedder forwards loading requests to the service isolate. |
| 61 | 54 |
| 62 // A port for communicating with the service isolate for I/O. | 55 // A port for communicating with the service isolate for I/O. |
| 63 SendPort _loadPort; | 56 SendPort _loadPort; |
| 64 | 57 |
| 65 // The isolateId used to communicate with the service isolate for I/O. | 58 // The isolateId used to communicate with the service isolate for I/O. |
| 66 int _isolateId; | 59 int _isolateId; |
| 67 | 60 |
| 68 // Requests made to the service isolate over the load port. | 61 // Requests made to the service isolate over the load port. |
| 69 | 62 |
| 70 // Extra requests. Keep these in sync between loader.dart and builtin.dart. | 63 // Extra requests. Keep these in sync between loader.dart and builtin.dart. |
| 71 const _Dart_kInitLoader = 4; // Initialize the loader. | 64 const _Dart_kInitLoader = 4; // Initialize the loader. |
| 72 const _Dart_kResourceLoad = 5; // Resource class support. | 65 const _Dart_kResourceLoad = 5; // Resource class support. |
| 73 const _Dart_kGetPackageRootUri = 6; // Uri of the packages/ directory. | 66 const _Dart_kGetPackageRootUri = 6; // Uri of the packages/ directory. |
| 74 const _Dart_kGetPackageConfigUri = 7; // Uri of the .packages file. | 67 const _Dart_kGetPackageConfigUri = 7; // Uri of the .packages file. |
| 75 const _Dart_kResolvePackageUri = 8; // Resolve a package: uri. | 68 const _Dart_kResolvePackageUri = 8; // Resolve a package: uri. |
| 76 | 69 |
| 77 // Make a request to the loader. Future will complete with result which is | 70 // Make a request to the loader. Future will complete with result which is |
| 78 // either a Uri or a List<int>. | 71 // either a Uri or a List<int>. |
| 79 Future _makeLoaderRequest(int tag, String uri) { | 72 Future _makeLoaderRequest(int tag, String uri) { |
| 80 assert(_isolateId != null); | 73 assert(_isolateId != null); |
| 81 assert(_loadPort != null); | 74 assert(_loadPort != null); |
| 82 Completer completer = new Completer(); | 75 Completer completer = new Completer(); |
| 83 RawReceivePort port = new RawReceivePort(); | 76 RawReceivePort port = new RawReceivePort(); |
| 84 port.handler = (msg) { | 77 port.handler = (msg) { |
| 85 // Close the port. | 78 // Close the port. |
| 86 port.close(); | 79 port.close(); |
| 87 completer.complete(msg); | 80 completer.complete(msg); |
| 88 }; | 81 }; |
| 89 _loadPort.send([_traceLoading, _isolateId, tag, port.sendPort, uri]); | 82 _loadPort.send([_traceLoading, _isolateId, tag, port.sendPort, uri]); |
| 90 return completer.future; | 83 return completer.future; |
| 91 } | 84 } |
| 92 | 85 |
| 93 | |
| 94 // The current working directory when the embedder was launched. | 86 // The current working directory when the embedder was launched. |
| 95 Uri _workingDirectory; | 87 Uri _workingDirectory; |
| 96 // The URI that the root script was loaded from. Remembered so that | 88 // The URI that the root script was loaded from. Remembered so that |
| 97 // package imports can be resolved relative to it. The root script is the basis | 89 // package imports can be resolved relative to it. The root script is the basis |
| 98 // for the root library in the VM. | 90 // for the root library in the VM. |
| 99 Uri _rootScript; | 91 Uri _rootScript; |
| 100 // The package root set on the command line. | 92 // The package root set on the command line. |
| 101 Uri _packageRoot; | 93 Uri _packageRoot; |
| 102 | 94 |
| 103 // Special handling for Windows paths so that they are compatible with URI | 95 // Special handling for Windows paths so that they are compatible with URI |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 String _filePathFromUri(String userUri) { | 286 String _filePathFromUri(String userUri) { |
| 295 var uri = Uri.parse(userUri); | 287 var uri = Uri.parse(userUri); |
| 296 if (_traceLoading) { | 288 if (_traceLoading) { |
| 297 _log('Getting file path from: $uri'); | 289 _log('Getting file path from: $uri'); |
| 298 } | 290 } |
| 299 | 291 |
| 300 var path; | 292 var path; |
| 301 switch (uri.scheme) { | 293 switch (uri.scheme) { |
| 302 case '': | 294 case '': |
| 303 case 'file': | 295 case 'file': |
| 304 return uri.toFilePath(); | 296 return uri.toFilePath(); |
| 305 case 'package': | 297 case 'package': |
| 306 return _filePathFromUri(_resolvePackageUri(uri).toString()); | 298 return _filePathFromUri(_resolvePackageUri(uri).toString()); |
| 307 case 'data': | 299 case 'data': |
| 308 case 'http': | 300 case 'http': |
| 309 case 'https': | 301 case 'https': |
| 310 return uri.toString(); | 302 return uri.toString(); |
| 311 default: | 303 default: |
| 312 // Only handling file, http, and package URIs | 304 // Only handling file, http, and package URIs |
| 313 // in standalone binary. | 305 // in standalone binary. |
| 314 if (_traceLoading) { | 306 if (_traceLoading) { |
| 315 _log('Unknown scheme (${uri.scheme}) in $uri.'); | 307 _log('Unknown scheme (${uri.scheme}) in $uri.'); |
| 316 } | 308 } |
| 317 throw 'Not a known scheme: $uri'; | 309 throw 'Not a known scheme: $uri'; |
| 318 } | 310 } |
| 319 } | 311 } |
| 320 | 312 |
| 321 // Embedder Entrypoint. | 313 // Embedder Entrypoint. |
| 322 _libraryFilePath(String libraryUri) { | 314 _libraryFilePath(String libraryUri) { |
| 323 if (!_setupCompleted) { | 315 if (!_setupCompleted) { |
| 324 _setupHooks(); | 316 _setupHooks(); |
| 325 } | 317 } |
| 326 int index = libraryUri.lastIndexOf('/'); | 318 int index = libraryUri.lastIndexOf('/'); |
| 327 var path; | 319 var path; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 if (_traceLoading) { | 365 if (_traceLoading) { |
| 374 _log("Request for package Uri resolution from user code: $packageUri"); | 366 _log("Request for package Uri resolution from user code: $packageUri"); |
| 375 } | 367 } |
| 376 if (packageUri.scheme != "package") { | 368 if (packageUri.scheme != "package") { |
| 377 if (_traceLoading) { | 369 if (_traceLoading) { |
| 378 _log("Non-package Uri, returning unmodified: $packageUri"); | 370 _log("Non-package Uri, returning unmodified: $packageUri"); |
| 379 } | 371 } |
| 380 // Return the incoming parameter if not passed a package: URI. | 372 // Return the incoming parameter if not passed a package: URI. |
| 381 return packageUri; | 373 return packageUri; |
| 382 } | 374 } |
| 383 var result = await _makeLoaderRequest(_Dart_kResolvePackageUri, | 375 var result = |
| 384 packageUri.toString()); | 376 await _makeLoaderRequest(_Dart_kResolvePackageUri, packageUri.toString()); |
| 385 if (result is! Uri) { | 377 if (result is! Uri) { |
| 386 if (_traceLoading) { | 378 if (_traceLoading) { |
| 387 _log("Exception when resolving package URI: $packageUri"); | 379 _log("Exception when resolving package URI: $packageUri"); |
| 388 } | 380 } |
| 389 result = null; | 381 result = null; |
| 390 } | 382 } |
| 391 if (_traceLoading) { | 383 if (_traceLoading) { |
| 392 _log("Resolved '$packageUri' to '$result'"); | 384 _log("Resolved '$packageUri' to '$result'"); |
| 393 } | 385 } |
| 394 return result; | 386 return result; |
| 395 } | 387 } |
| OLD | NEW |