diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 2439342ae8a78b..192c21b52c83e8 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -2,11 +2,17 @@ const { ArrayIsArray, + ArrayPrototypeIncludes, + ArrayPrototypeJoin, + ArrayPrototypeMap, NumberIsInteger, NumberMAX_SAFE_INTEGER, NumberMIN_SAFE_INTEGER, NumberParseInt, + RegExpPrototypeTest, String, + StringPrototypeToUpperCase, + StringPrototypeTrim, } = primordials; const { @@ -63,7 +69,7 @@ function parseFileMode(value, name, def) { } if (typeof value === 'string') { - if (!octalReg.test(value)) { + if (!RegExpPrototypeTest(octalReg, value)) { throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc); } return NumberParseInt(value, 8); @@ -129,10 +135,11 @@ function validateNumber(value, name) { } const validateOneOf = hideStackFrames((value, name, oneOf) => { - if (!oneOf.includes(value)) { - const allowed = oneOf - .map((v) => (typeof v === 'string' ? `'${v}'` : String(v))) - .join(', '); + if (!ArrayPrototypeIncludes(oneOf, value)) { + const allowed = ArrayPrototypeJoin( + ArrayPrototypeMap(oneOf, (v) => + (typeof v === 'string' ? `'${v}'` : String(v))), + ', '); const reason = 'must be one of: ' + allowed; throw new ERR_INVALID_ARG_VALUE(name, value, reason); } @@ -167,7 +174,7 @@ function validateSignalName(signal, name = 'signal') { throw new ERR_INVALID_ARG_TYPE(name, 'string', signal); if (signals[signal] === undefined) { - if (signals[signal.toUpperCase()] !== undefined) { + if (signals[StringPrototypeToUpperCase(signal)] !== undefined) { throw new ERR_UNKNOWN_SIGNAL(signal + ' (signals must use all capital letters)'); } @@ -198,7 +205,7 @@ function validateEncoding(data, encoding) { // is an integer and that it falls within the legal range of port numbers. function validatePort(port, name = 'Port', { allowZero = true } = {}) { if ((typeof port !== 'number' && typeof port !== 'string') || - (typeof port === 'string' && port.trim().length === 0) || + (typeof port === 'string' && StringPrototypeTrim(port).length === 0) || +port !== (+port >>> 0) || port > 0xFFFF || (port === 0 && !allowZero)) {