michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: 'use strict'; michael@0: michael@0: module.metadata = { michael@0: "stability": "unstable" michael@0: }; michael@0: michael@0: const { Cc, Ci } = require('chrome'); michael@0: const system = require('../sdk/system'); michael@0: const runtime = require('../sdk/system/runtime'); michael@0: const oscpu = Cc["@mozilla.org/network/protocol;1?name=http"] michael@0: .getService(Ci.nsIHttpProtocolHandler).oscpu; michael@0: const hostname = Cc["@mozilla.org/network/dns-service;1"] michael@0: .getService(Ci.nsIDNSService).myHostName; michael@0: const isWindows = system.platform === 'win32'; michael@0: const endianness = ((new Uint32Array((new Uint8Array([1,2,3,4])).buffer))[0] === 0x04030201) ? 'LE' : 'BE'; michael@0: michael@0: /** michael@0: * Returns a path to a temp directory michael@0: */ michael@0: exports.tmpdir = () => system.pathFor('TmpD'); michael@0: michael@0: /** michael@0: * Returns the endianness of the architecture: either 'LE' or 'BE' michael@0: */ michael@0: exports.endianness = () => endianness; michael@0: michael@0: /** michael@0: * Returns hostname of the machine michael@0: */ michael@0: exports.hostname = () => hostname; michael@0: michael@0: /** michael@0: * Name of the OS type michael@0: * Possible values: michael@0: * https://developer.mozilla.org/en/OS_TARGET michael@0: */ michael@0: exports.type = () => runtime.OS; michael@0: michael@0: /** michael@0: * Name of the OS Platform in lower case string. michael@0: * Possible values: michael@0: * https://developer.mozilla.org/en/OS_TARGET michael@0: */ michael@0: exports.platform = () => system.platform; michael@0: michael@0: /** michael@0: * Type of processor architecture running: michael@0: * 'arm', 'ia32', 'x86', 'x64' michael@0: */ michael@0: exports.arch = () => system.architecture; michael@0: michael@0: /** michael@0: * Returns the operating system release. michael@0: */ michael@0: exports.release = () => { michael@0: let match = oscpu.match(/(\d[\.\d]*)/); michael@0: return match && match.length > 1 ? match[1] : oscpu; michael@0: }; michael@0: michael@0: /** michael@0: * Returns EOL character for the OS michael@0: */ michael@0: exports.EOL = isWindows ? '\r\n' : '\n'; michael@0: michael@0: /** michael@0: * Returns [0, 0, 0], as this is not implemented. michael@0: */ michael@0: exports.loadavg = () => [0, 0, 0]; michael@0: michael@0: ['uptime', 'totalmem', 'freemem', 'cpus'].forEach(method => { michael@0: exports[method] = () => { throw new Error('os.' + method + ' is not supported.'); }; michael@0: });