net: check objectMode first and then readble || writable

Co-authored-by: Luigi Pinca <luigipinca@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/40344
Fixes: https://github.com/nodejs/node/issues/40336
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
Daijiro Wachi
2021-10-07 16:42:49 +09:00
committed by Node.js GitHub Bot
parent 46446623f5
commit c7cd8ef6c6

View File

@@ -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