diff --git a/lib/net.js b/lib/net.js index 666854a3ccff60..0250f7a585ffe6 100644 --- a/lib/net.js +++ b/lib/net.js @@ -283,20 +283,21 @@ const kSetNoDelay = Symbol('kSetNoDelay'); function Socket(options) { if (!(this instanceof Socket)) return new Socket(options); - const invalidKeys = [ - 'objectMode', - 'readableObjectMode', - 'writableObjectMode', - ]; - invalidKeys.forEach((invalidKey) => { - if (ObjectKeys(options).includes(invalidKey)) { - throw new ERR_INVALID_ARG_VALUE( - `options.${invalidKey}`, - options[invalidKey], - 'is not supported' - ); - } - }); + if (options.objectMode) { + throw new ERR_INVALID_ARG_VALUE( + 'options.objectMode', + options.objectMode, + 'is not supported' + ); + } else if (options.readableObjectMode || options.writableObjectMode) { + throw new ERR_INVALID_ARG_VALUE( + `options.${ + options.readableObjectMode ? 'readableObjectMode' : 'writableObjectMode' + }`, + options.readableObjectMode || options.writableObjectMode, + 'is not supported' + ); + } this.connecting = false; // Problem with this is that users can supply their own handle, that may not