summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-08-23 15:47:40 -0400
committerRich Trott <rtrott@gmail.com>2019-08-25 16:10:07 -0700
commit627bf59e8ddd9826720c45f430c2a2e489df6e66 (patch)
treecef948ca425404ce85f9c125affa3e3c566cfa55 /lib
parent66043e18128dc80457f4e184b7ed7faedcd93ca7 (diff)
downloadandroid-node-v8-627bf59e8ddd9826720c45f430c2a2e489df6e66.tar.gz
android-node-v8-627bf59e8ddd9826720c45f430c2a2e489df6e66.tar.bz2
android-node-v8-627bf59e8ddd9826720c45f430c2a2e489df6e66.zip
lib: consolidate lazyErrmapGet()
There are currently two implementations of this function. This commit removes the redundancy, and removes "lazy" from the name. PR-URL: https://github.com/nodejs/node/pull/29285 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/errors.js7
-rw-r--r--lib/internal/util.js25
2 files changed, 12 insertions, 20 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 5c0d328a1b..cf97a76b36 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -327,7 +327,7 @@ function lazyUv() {
return uvBinding;
}
-function lazyErrmapGet(name) {
+function uvErrmapGet(name) {
uvBinding = lazyUv();
if (!uvBinding.errmap) {
uvBinding.errmap = uvBinding.getErrorMap();
@@ -346,7 +346,7 @@ function lazyErrmapGet(name) {
* @returns {Error}
*/
function uvException(ctx) {
- const [ code, uvmsg ] = lazyErrmapGet(ctx.errno);
+ const [ code, uvmsg ] = uvErrmapGet(ctx.errno);
let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`;
let path;
@@ -404,7 +404,7 @@ function uvException(ctx) {
* @returns {Error}
*/
function uvExceptionWithHostPort(err, syscall, address, port) {
- const [ code, uvmsg ] = lazyErrmapGet(err);
+ const [ code, uvmsg ] = uvErrmapGet(err);
const message = `${syscall} ${code}: ${uvmsg}`;
let details = '';
@@ -671,6 +671,7 @@ module.exports = {
hideStackFrames,
isStackOverflowError,
connResetException,
+ uvErrmapGet,
uvException,
uvExceptionWithHostPort,
SystemError,
diff --git a/lib/internal/util.js b/lib/internal/util.js
index 67d4130ddd..e13cce92ff 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -1,12 +1,14 @@
'use strict';
const { Object, Reflect } = primordials;
-
const {
- ERR_INVALID_ARG_TYPE,
- ERR_NO_CRYPTO,
- ERR_UNKNOWN_SIGNAL
-} = require('internal/errors').codes;
+ codes: {
+ ERR_INVALID_ARG_TYPE,
+ ERR_NO_CRYPTO,
+ ERR_UNKNOWN_SIGNAL
+ },
+ uvErrmapGet
+} = require('internal/errors');
const { signals } = internalBinding('constants').os;
const {
getHiddenValue,
@@ -244,19 +246,8 @@ function getConstructorOf(obj) {
return null;
}
-let uvBinding;
-function lazyErrmapGet(name) {
- if (!uvBinding) {
- uvBinding = internalBinding('uv');
- }
- if (!uvBinding.errmap) {
- uvBinding.errmap = uvBinding.getErrorMap();
- }
- return uvBinding.errmap.get(name);
-}
-
function getSystemErrorName(err) {
- const entry = lazyErrmapGet(err);
+ const entry = uvErrmapGet(err);
return entry ? entry[0] : `Unknown system error ${err}`;
}