summaryrefslogtreecommitdiff
path: root/lib/os.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-10-27 16:27:16 -0700
committerJames M Snell <jasnell@gmail.com>2017-11-02 11:58:38 -0700
commit056b858e57a72c5429d9278bc7b77d1922a2dbe4 (patch)
tree71a7ad2be887c50d4bf5c2d461fe7a16131e3181 /lib/os.js
parentc3dc0e0d75cc5a03de154f3586e1062df1e719e4 (diff)
downloadandroid-node-v8-056b858e57a72c5429d9278bc7b77d1922a2dbe4.tar.gz
android-node-v8-056b858e57a72c5429d9278bc7b77d1922a2dbe4.tar.bz2
android-node-v8-056b858e57a72c5429d9278bc7b77d1922a2dbe4.zip
os: migrate node_os.cc to internal/errors
PR-URL: https://github.com/nodejs/node/pull/16567 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'lib/os.js')
-rw-r--r--lib/os.js34
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/os.js b/lib/os.js
index 6af5d15cbc..7c07a5b0d3 100644
--- a/lib/os.js
+++ b/lib/os.js
@@ -27,21 +27,43 @@ const { deprecate } = require('internal/util');
const { getCIDRSuffix } = require('internal/os');
const isWindows = process.platform === 'win32';
+const errors = require('internal/errors');
+
const {
getCPUs,
getFreeMem,
- getHomeDirectory,
- getHostname,
- getInterfaceAddresses,
+ getHomeDirectory: _getHomeDirectory,
+ getHostname: _getHostname,
+ getInterfaceAddresses: _getInterfaceAddresses,
getLoadAvg,
- getOSRelease,
- getOSType,
+ getOSRelease: _getOSRelease,
+ getOSType: _getOSType,
getTotalMem,
- getUserInfo,
+ getUserInfo: _getUserInfo,
getUptime,
isBigEndian
} = process.binding('os');
+function getCheckedFunction(fn) {
+ return function checkError(...args) {
+ const ctx = {};
+ const ret = fn(...args, ctx);
+ if (ret === undefined) {
+ const err = new errors.SystemError(ctx);
+ Error.captureStackTrace(err, checkError);
+ throw err;
+ }
+ return ret;
+ };
+}
+
+const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
+const getHostname = getCheckedFunction(_getHostname);
+const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
+const getOSRelease = getCheckedFunction(_getOSRelease);
+const getOSType = getCheckedFunction(_getOSType);
+const getUserInfo = getCheckedFunction(_getUserInfo);
+
getFreeMem[Symbol.toPrimitive] = () => getFreeMem();
getHostname[Symbol.toPrimitive] = () => getHostname();
getHomeDirectory[Symbol.toPrimitive] = () => getHomeDirectory();