Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * Runtime information about the current platform. | 6 * Runtime information about the current platform. |
| 7 */ | 7 */ |
| 8 library dart.platform; | 8 library dart.platform; |
| 9 | |
| 10 const int _kNumberOfProcessors = 1; | |
| 11 const int _kPathSeparator = 2; | |
| 12 const int _kOperatingSystem = 3; | |
| 13 const int _kLocalHostname = 4; | |
| 14 const int _kVersion = 5; | |
| 15 const int _kEnvironment = 6; | |
| 16 const int _kScript = 7; | |
| 17 const int _kExecutable = 8; | |
| 18 const int _kExecutableArguments = 9; | |
| 19 const int _kPackageRoot = 10; | |
| 20 | |
| 21 const List<String> _propertyNames = const <String>[ | |
| 22 '', | |
| 23 'numberOfProcessors', | |
| 24 'pathSeparator', | |
| 25 'operatingSystem', | |
| 26 'localHostname', | |
| 27 'version', | |
| 28 'environment', | |
| 29 'script', | |
| 30 'executable', | |
| 31 'executableArguments', | |
| 32 'packageRoot']; | |
| 33 | |
| 34 | |
| 35 // The platform-specific function, set by the embedder, that fetches | |
| 36 // the platform information. | |
| 37 Function _platform = _defaultImplementation; | |
| 38 | |
| 39 /** | |
| 40 * Get the number of processors of the machine. | |
| 41 */ | |
| 42 final int numberOfProcessors = _platform(_kNumberOfProcessors); | |
|
Anders Johnsen
2013/10/24 08:30:08
These should be marked as 'external', with this im
| |
| 43 | |
| 44 /** | |
| 45 * Get the path separator used by the operating system to separate | |
| 46 * components in file paths. | |
| 47 */ | |
| 48 final String pathSeparator = _platform(_kPathSeparator); | |
| 49 | |
| 50 | |
| 51 /** | |
| 52 * Get a string (`linux`, `macos`, `windows` or `android`) | |
| 53 * representing the operating system. | |
| 54 */ | |
| 55 final String operatingSystem = _platform(_kOperatingSystem); | |
| 56 | |
| 57 /** | |
| 58 * Get the local hostname for the system. | |
| 59 */ | |
| 60 final String localHostname = _platform(_kLocalHostname); | |
| 61 | |
| 62 /** | |
| 63 * Returns the version of the current Dart runtime. | |
| 64 */ | |
| 65 final String version = _platform(_kVersion); | |
| 66 | |
| 67 /** | |
| 68 * Returns true if the operating system is Linux. | |
| 69 */ | |
| 70 bool get isLinux => operatingSystem == "linux"; | |
| 71 | |
| 72 /** | |
| 73 * Returns true if the operating system is Mac OS. | |
| 74 */ | |
| 75 bool get isMacOS => operatingSystem == "macos"; | |
| 76 | |
| 77 /** | |
| 78 * Returns true if the operating system is Windows. | |
| 79 */ | |
| 80 bool get isWindows => operatingSystem == "windows"; | |
| 81 | |
| 82 /** | |
| 83 * Returns true if the operating system is Android. | |
| 84 */ | |
| 85 bool get isAndroid => operatingSystem == "android"; | |
| 86 | |
| 87 /** | |
| 88 * Get the environment for this process. | |
| 89 * | |
| 90 * Environment variables on Windows are case-insensitive. The map | |
| 91 * returned on Windows is therefore case-insensitive and will convert | |
| 92 * all keys to upper case. On other platforms the returned map is | |
| 93 * a standard case-sensitive map. | |
| 94 */ | |
| 95 final Map<String, String> environment = _platform(_kEnvironment); | |
| 96 | |
| 97 /** | |
| 98 * Returns the path of the executable used to run the script in this | |
| 99 * isolate. | |
| 100 * | |
| 101 * If the execution environment does not support [executable] an empty | |
| 102 * string is returned. | |
| 103 */ | |
| 104 final String executable = _platform(_kExecutable); | |
| 105 | |
| 106 /** | |
| 107 * Returns the URI (in String form) of the script being run in this | |
| 108 * isolate. If the URI is relative it is relative to the file URI of | |
| 109 * the working directory of the VM when it was started. | |
| 110 * | |
| 111 * If the executable environment does not support [script] an empty | |
| 112 * string is returned. | |
| 113 */ | |
| 114 final String script = _platform(_kScript); | |
| 115 | |
| 116 /** | |
| 117 * Returns the flags passed to the executable used to run the script in this | |
| 118 * isolate. These are the command-line flags between the executable name | |
| 119 * and the script name. Each fetch of executableArguments returns a new | |
| 120 * List, containing the flags passed to the executable. | |
| 121 */ | |
| 122 final List<String> executableArguments = _platform(_kExecutableArguments); | |
| 123 | |
| 124 /** | |
| 125 * Returns the value of the --package-root flag passed to the executable | |
| 126 * used to run the script in this isolate. This is the directory in which | |
| 127 * Dart packages are looked up. | |
| 128 * | |
| 129 * If there is no --package-root flag, then the empty string is returned. | |
| 130 */ | |
| 131 final String packageRoot = _platform(_kPackageRoot); | |
| 132 | |
| 133 _defaultImplementation(int propertyIndex) { | |
| 134 throw new UnsupportedError( | |
| 135 'dart:platform.${_propertyNames[propertyIndex]} not supported.'); | |
| 136 } | |
| OLD | NEW |