Skip to content

Commit dbb2e6f

Browse files
watildetargos
authored andcommitted
net: check objectMode first and then readble || writable
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]>
1 parent a672be5 commit dbb2e6f

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lib/net.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -283,20 +283,21 @@ const kSetNoDelay = Symbol('kSetNoDelay');
283283

284284
function Socket(options) {
285285
if (!(this instanceof Socket)) return new Socket(options);
286-
const invalidKeys = [
287-
'objectMode',
288-
'readableObjectMode',
289-
'writableObjectMode',
290-
];
291-
invalidKeys.forEach((invalidKey) => {
292-
if (ObjectKeys(options).includes(invalidKey)) {
293-
throw new ERR_INVALID_ARG_VALUE(
294-
`options.${invalidKey}`,
295-
options[invalidKey],
296-
'is not supported'
297-
);
298-
}
299-
});
286+
if (options.objectMode) {
287+
throw new ERR_INVALID_ARG_VALUE(
288+
'options.objectMode',
289+
options.objectMode,
290+
'is not supported'
291+
);
292+
} else if (options.readableObjectMode || options.writableObjectMode) {
293+
throw new ERR_INVALID_ARG_VALUE(
294+
`options.${
295+
options.readableObjectMode ? 'readableObjectMode' : 'writableObjectMode'
296+
}`,
297+
options.readableObjectMode || options.writableObjectMode,
298+
'is not supported'
299+
);
300+
}
300301

301302
this.connecting = false;
302303
// Problem with this is that users can supply their own handle, that may not

0 commit comments

Comments
 (0)