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

Unified Diff: sdk/lib/platform/platform.dart

Issue 36883005: Add fields to platform library, implement them on runtime dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase on CL 32683002 Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/platform/platform.dart
diff --git a/sdk/lib/platform/platform.dart b/sdk/lib/platform/platform.dart
index 0ef0a572eed98bca60c9b1a1c3947e6a2b36cf6e..ed62119001ffa07a275d675cd62bb80398239dca 100644
--- a/sdk/lib/platform/platform.dart
+++ b/sdk/lib/platform/platform.dart
@@ -6,3 +6,131 @@
* Runtime information about the current platform.
*/
library dart.platform;
+
+const int _kNumberOfProcessors = 1;
+const int _kPathSeparator = 2;
+const int _kOperatingSystem = 3;
+const int _kLocalHostname = 4;
+const int _kVersion = 5;
+const int _kEnvironment = 6;
+const int _kScript = 7;
+const int _kExecutable = 8;
+const int _kExecutableArguments = 9;
+const int _kPackageRoot = 10;
+
+const List<String> _propertyNames = const <String>[
+ '',
+ 'numberOfProcessors',
+ 'pathSeparator',
+ 'operatingSystem',
+ 'localHostname',
+ 'version',
+ 'environment',
+ 'script',
+ 'executable',
+ 'executableArguments',
+ 'packageRoot'];
+
+
+// The platform-specific function, set by the embedder, that fetches
+// the platform information.
+Function _platform = _defaultImplementation;
+
+/**
+ * Get the number of processors of the machine.
+ */
+final int numberOfProcessors = _platform(_kNumberOfProcessors);
Anders Johnsen 2013/10/24 08:30:08 These should be marked as 'external', with this im
+
+/**
+ * Get the path separator used by the operating system to separate
+ * components in file paths.
+ */
+final String pathSeparator = _platform(_kPathSeparator);
+
+
+/**
+ * Get a string (`linux`, `macos`, `windows` or `android`)
+ * representing the operating system.
+ */
+final String operatingSystem = _platform(_kOperatingSystem);
+
+/**
+ * Get the local hostname for the system.
+ */
+final String localHostname = _platform(_kLocalHostname);
+
+/**
+ * Returns the version of the current Dart runtime.
+ */
+final String version = _platform(_kVersion);
+
+/**
+ * Returns true if the operating system is Linux.
+ */
+bool get isLinux => operatingSystem == "linux";
+
+/**
+ * Returns true if the operating system is Mac OS.
+ */
+bool get isMacOS => operatingSystem == "macos";
+
+/**
+ * Returns true if the operating system is Windows.
+ */
+bool get isWindows => operatingSystem == "windows";
+
+/**
+ * Returns true if the operating system is Android.
+ */
+bool get isAndroid => operatingSystem == "android";
+
+/**
+ * Get the environment for this process.
+ *
+ * Environment variables on Windows are case-insensitive. The map
+ * returned on Windows is therefore case-insensitive and will convert
+ * all keys to upper case. On other platforms the returned map is
+ * a standard case-sensitive map.
+ */
+final Map<String, String> environment = _platform(_kEnvironment);
+
+/**
+ * Returns the path of the executable used to run the script in this
+ * isolate.
+ *
+ * If the execution environment does not support [executable] an empty
+ * string is returned.
+ */
+final String executable = _platform(_kExecutable);
+
+/**
+ * Returns the URI (in String form) of the script being run in this
+ * isolate. If the URI is relative it is relative to the file URI of
+ * the working directory of the VM when it was started.
+ *
+ * If the executable environment does not support [script] an empty
+ * string is returned.
+ */
+final String script = _platform(_kScript);
+
+/**
+ * Returns the flags passed to the executable used to run the script in this
+ * isolate. These are the command-line flags between the executable name
+ * and the script name. Each fetch of executableArguments returns a new
+ * List, containing the flags passed to the executable.
+ */
+final List<String> executableArguments = _platform(_kExecutableArguments);
+
+/**
+ * Returns the value of the --package-root flag passed to the executable
+ * used to run the script in this isolate. This is the directory in which
+ * Dart packages are looked up.
+ *
+ * If there is no --package-root flag, then the empty string is returned.
+ */
+final String packageRoot = _platform(_kPackageRoot);
+
+_defaultImplementation(int propertyIndex) {
+ throw new UnsupportedError(
+ 'dart:platform.${_propertyNames[propertyIndex]} not supported.');
+}

Powered by Google App Engine
This is Rietveld 408576698