|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 'use strict'; |
|
6 |
|
7 module.metadata = { |
|
8 "stability": "unstable" |
|
9 }; |
|
10 |
|
11 const { Cc, Ci } = require('chrome'); |
|
12 const system = require('../sdk/system'); |
|
13 const runtime = require('../sdk/system/runtime'); |
|
14 const oscpu = Cc["@mozilla.org/network/protocol;1?name=http"] |
|
15 .getService(Ci.nsIHttpProtocolHandler).oscpu; |
|
16 const hostname = Cc["@mozilla.org/network/dns-service;1"] |
|
17 .getService(Ci.nsIDNSService).myHostName; |
|
18 const isWindows = system.platform === 'win32'; |
|
19 const endianness = ((new Uint32Array((new Uint8Array([1,2,3,4])).buffer))[0] === 0x04030201) ? 'LE' : 'BE'; |
|
20 |
|
21 /** |
|
22 * Returns a path to a temp directory |
|
23 */ |
|
24 exports.tmpdir = () => system.pathFor('TmpD'); |
|
25 |
|
26 /** |
|
27 * Returns the endianness of the architecture: either 'LE' or 'BE' |
|
28 */ |
|
29 exports.endianness = () => endianness; |
|
30 |
|
31 /** |
|
32 * Returns hostname of the machine |
|
33 */ |
|
34 exports.hostname = () => hostname; |
|
35 |
|
36 /** |
|
37 * Name of the OS type |
|
38 * Possible values: |
|
39 * https://developer.mozilla.org/en/OS_TARGET |
|
40 */ |
|
41 exports.type = () => runtime.OS; |
|
42 |
|
43 /** |
|
44 * Name of the OS Platform in lower case string. |
|
45 * Possible values: |
|
46 * https://developer.mozilla.org/en/OS_TARGET |
|
47 */ |
|
48 exports.platform = () => system.platform; |
|
49 |
|
50 /** |
|
51 * Type of processor architecture running: |
|
52 * 'arm', 'ia32', 'x86', 'x64' |
|
53 */ |
|
54 exports.arch = () => system.architecture; |
|
55 |
|
56 /** |
|
57 * Returns the operating system release. |
|
58 */ |
|
59 exports.release = () => { |
|
60 let match = oscpu.match(/(\d[\.\d]*)/); |
|
61 return match && match.length > 1 ? match[1] : oscpu; |
|
62 }; |
|
63 |
|
64 /** |
|
65 * Returns EOL character for the OS |
|
66 */ |
|
67 exports.EOL = isWindows ? '\r\n' : '\n'; |
|
68 |
|
69 /** |
|
70 * Returns [0, 0, 0], as this is not implemented. |
|
71 */ |
|
72 exports.loadavg = () => [0, 0, 0]; |
|
73 |
|
74 ['uptime', 'totalmem', 'freemem', 'cpus'].forEach(method => { |
|
75 exports[method] = () => { throw new Error('os.' + method + ' is not supported.'); }; |
|
76 }); |