diff --git a/lib/dgram.js b/lib/dgram.js index 4630be4dff8c5c..c515c551427d98 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -369,7 +369,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { }; Socket.prototype.connect = function(port, address, callback) { - port = validatePort(port, 'Port', { allowZero: false }); + port = validatePort(port, 'Port', false); if (typeof address === 'function') { callback = address; address = ''; @@ -626,7 +626,7 @@ Socket.prototype.send = function(buffer, } if (!connected) - port = validatePort(port, 'Port', { allowZero: false }); + port = validatePort(port, 'Port', false); // Normalize callback so it's either a function or undefined but not anything // else. diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 9bca0aa747725e..b3a7ee26554e1a 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -155,7 +155,7 @@ const validateObject = hideStackFrames( } }); -const validateArray = hideStackFrames((value, name, { minLength = 0 } = {}) => { +const validateArray = hideStackFrames((value, name, minLength = 0) => { if (!ArrayIsArray(value)) { throw new ERR_INVALID_ARG_TYPE(name, 'Array', value); } @@ -166,8 +166,7 @@ const validateArray = hideStackFrames((value, name, { minLength = 0 } = {}) => { }); function validateSignalName(signal, name = 'signal') { - if (typeof signal !== 'string') - throw new ERR_INVALID_ARG_TYPE(name, 'string', signal); + validateString(signal, name); if (signals[signal] === undefined) { if (signals[StringPrototypeToUpperCase(signal)] !== undefined) { @@ -199,7 +198,7 @@ function validateEncoding(data, encoding) { // Check that the port number is not NaN when coerced to a number, // is an integer and that it falls within the legal range of port numbers. -function validatePort(port, name = 'Port', { allowZero = true } = {}) { +function validatePort(port, name = 'Port', allowZero = true) { if ((typeof port !== 'number' && typeof port !== 'string') || (typeof port === 'string' && StringPrototypeTrim(port).length === 0) || +port !== (+port >>> 0) || diff --git a/test/parallel/test-validators.js b/test/parallel/test-validators.js index 9dbf5f9c4599f2..6b0d49c6997a65 100644 --- a/test/parallel/test-validators.js +++ b/test/parallel/test-validators.js @@ -55,9 +55,9 @@ const invalidArgValueError = { }, invalidArgTypeError); }); - validateArray([1], 'foo', { minLength: 1 }); + validateArray([1], 'foo', 1); assert.throws(() => { - validateArray([], 'foo', { minLength: 1 }); + validateArray([], 'foo', 1); }, invalidArgValueError); }