1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/lib/node/os.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +'use strict'; 1.9 + 1.10 +module.metadata = { 1.11 + "stability": "unstable" 1.12 +}; 1.13 + 1.14 +const { Cc, Ci } = require('chrome'); 1.15 +const system = require('../sdk/system'); 1.16 +const runtime = require('../sdk/system/runtime'); 1.17 +const oscpu = Cc["@mozilla.org/network/protocol;1?name=http"] 1.18 + .getService(Ci.nsIHttpProtocolHandler).oscpu; 1.19 +const hostname = Cc["@mozilla.org/network/dns-service;1"] 1.20 + .getService(Ci.nsIDNSService).myHostName; 1.21 +const isWindows = system.platform === 'win32'; 1.22 +const endianness = ((new Uint32Array((new Uint8Array([1,2,3,4])).buffer))[0] === 0x04030201) ? 'LE' : 'BE'; 1.23 + 1.24 +/** 1.25 + * Returns a path to a temp directory 1.26 + */ 1.27 +exports.tmpdir = () => system.pathFor('TmpD'); 1.28 + 1.29 +/** 1.30 + * Returns the endianness of the architecture: either 'LE' or 'BE' 1.31 + */ 1.32 +exports.endianness = () => endianness; 1.33 + 1.34 +/** 1.35 + * Returns hostname of the machine 1.36 + */ 1.37 +exports.hostname = () => hostname; 1.38 + 1.39 +/** 1.40 + * Name of the OS type 1.41 + * Possible values: 1.42 + * https://developer.mozilla.org/en/OS_TARGET 1.43 + */ 1.44 +exports.type = () => runtime.OS; 1.45 + 1.46 +/** 1.47 + * Name of the OS Platform in lower case string. 1.48 + * Possible values: 1.49 + * https://developer.mozilla.org/en/OS_TARGET 1.50 + */ 1.51 +exports.platform = () => system.platform; 1.52 + 1.53 +/** 1.54 + * Type of processor architecture running: 1.55 + * 'arm', 'ia32', 'x86', 'x64' 1.56 + */ 1.57 +exports.arch = () => system.architecture; 1.58 + 1.59 +/** 1.60 + * Returns the operating system release. 1.61 + */ 1.62 +exports.release = () => { 1.63 + let match = oscpu.match(/(\d[\.\d]*)/); 1.64 + return match && match.length > 1 ? match[1] : oscpu; 1.65 +}; 1.66 + 1.67 +/** 1.68 + * Returns EOL character for the OS 1.69 + */ 1.70 +exports.EOL = isWindows ? '\r\n' : '\n'; 1.71 + 1.72 +/** 1.73 + * Returns [0, 0, 0], as this is not implemented. 1.74 + */ 1.75 +exports.loadavg = () => [0, 0, 0]; 1.76 + 1.77 +['uptime', 'totalmem', 'freemem', 'cpus'].forEach(method => { 1.78 + exports[method] = () => { throw new Error('os.' + method + ' is not supported.'); }; 1.79 +});