summaryrefslogtreecommitdiffstats
path: root/toolkit/jetpack/node/os.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-09 06:46:43 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-09 06:46:43 -0500
commitac46df8daea09899ce30dc8fd70986e258c746bf (patch)
tree2750d3125fc253fd5b0671e4bd268eff1fd97296 /toolkit/jetpack/node/os.js
parent8cecf8d5208f3945b35f879bba3015bb1a11bec6 (diff)
downloadUXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar
UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.gz
UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.lz
UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.xz
UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.zip
Move Add-on SDK source to toolkit/jetpack
Diffstat (limited to 'toolkit/jetpack/node/os.js')
-rw-r--r--toolkit/jetpack/node/os.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/toolkit/jetpack/node/os.js b/toolkit/jetpack/node/os.js
new file mode 100644
index 000000000..1c41a9246
--- /dev/null
+++ b/toolkit/jetpack/node/os.js
@@ -0,0 +1,90 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+module.metadata = {
+ "stability": "unstable"
+};
+
+const { Cc, Ci } = require('chrome');
+const system = require('../sdk/system');
+const runtime = require('../sdk/system/runtime');
+const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
+const isWindows = system.platform === 'win32';
+const endianness = ((new Uint32Array((new Uint8Array([1,2,3,4])).buffer))[0] === 0x04030201) ? 'LE' : 'BE';
+
+XPCOMUtils.defineLazyGetter(this, "oscpu", () => {
+ try {
+ return Cc["@mozilla.org/network/protocol;1?name=http"].getService(Ci.nsIHttpProtocolHandler).oscpu;
+ } catch (e) {
+ return "";
+ }
+});
+
+XPCOMUtils.defineLazyGetter(this, "hostname", () => {
+ try {
+ // On some platforms (Linux according to try), this service does not exist and fails.
+ return Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService).myHostName;
+ } catch (e) {
+ return "";
+ }
+});
+
+/**
+ * Returns a path to a temp directory
+ */
+exports.tmpdir = () => system.pathFor('TmpD');
+
+/**
+ * Returns the endianness of the architecture: either 'LE' or 'BE'
+ */
+exports.endianness = () => endianness;
+
+/**
+ * Returns hostname of the machine
+ */
+exports.hostname = () => hostname;
+
+/**
+ * Name of the OS type
+ * Possible values:
+ * https://developer.mozilla.org/en/OS_TARGET
+ */
+exports.type = () => runtime.OS;
+
+/**
+ * Name of the OS Platform in lower case string.
+ * Possible values:
+ * https://developer.mozilla.org/en/OS_TARGET
+ */
+exports.platform = () => system.platform;
+
+/**
+ * Type of processor architecture running:
+ * 'arm', 'ia32', 'x86', 'x64'
+ */
+exports.arch = () => system.architecture;
+
+/**
+ * Returns the operating system release.
+ */
+exports.release = () => {
+ let match = oscpu.match(/(\d[\.\d]*)/);
+ return match && match.length > 1 ? match[1] : oscpu;
+};
+
+/**
+ * Returns EOL character for the OS
+ */
+exports.EOL = isWindows ? '\r\n' : '\n';
+
+/**
+ * Returns [0, 0, 0], as this is not implemented.
+ */
+exports.loadavg = () => [0, 0, 0];
+
+['uptime', 'totalmem', 'freemem', 'cpus'].forEach(method => {
+ exports[method] = () => { throw new Error('os.' + method + ' is not supported.'); };
+});