Skip to content

Commit

Permalink
net: check objectMode first and then readble || writable
Browse files Browse the repository at this point in the history
Co-authored-by: Luigi Pinca <[email protected]>

PR-URL: #40344
Fixes: #40336
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Zijian Liu <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
  • Loading branch information
watilde authored and targos committed Oct 13, 2021
1 parent a672be5 commit dbb2e6f
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dbb2e6f

Please sign in to comment.