From dbb2e6f429ac77d749ab8c398fabb74d18d5b126 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Thu, 7 Oct 2021 16:42:49 +0900 Subject: [PATCH] net: check objectMode first and then readble || writable Co-authored-by: Luigi Pinca PR-URL: https://github.com/nodejs/node/pull/40344 Fixes: https://github.com/nodejs/node/issues/40336 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Minwoo Jung Reviewed-By: Zijian Liu Reviewed-By: Robert Nagy --- lib/net.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) 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