diff --git a/src/js/node/net.ts b/src/js/node/net.ts index 7ef4384b16..5900e24867 100644 --- a/src/js/node/net.ts +++ b/src/js/node/net.ts @@ -517,6 +517,13 @@ const Socket = (function (InternalSocket) { ...opts } = options || {}; + if (options?.objectMode) + throw $ERR_INVALID_ARG_VALUE("options.objectMode", options.objectMode, "is not supported"); + if (options?.readableObjectMode) + throw $ERR_INVALID_ARG_VALUE("options.readableObjectMode", options.readableObjectMode, "is not supported"); + if (options?.writableObjectMode) + throw $ERR_INVALID_ARG_VALUE("options.writableObjectMode", options.writableObjectMode, "is not supported"); + super({ ...opts, allowHalfOpen, diff --git a/test/js/node/test/parallel/test-net-connect-options-invalid.js b/test/js/node/test/parallel/test-net-connect-options-invalid.js new file mode 100644 index 0000000000..05a5654630 --- /dev/null +++ b/test/js/node/test/parallel/test-net-connect-options-invalid.js @@ -0,0 +1,27 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const net = require('net'); + +{ + const invalidKeys = [ + 'objectMode', + 'readableObjectMode', + 'writableObjectMode', + ]; + invalidKeys.forEach((invalidKey) => { + const option = { + port: 8080, + [invalidKey]: true + }; + const message = `The property 'options.${invalidKey}' is not supported. Received true`; + + assert.throws(() => { + net.createConnection(option); + }, { + code: 'ERR_INVALID_ARG_VALUE', + name: 'TypeError', + message: new RegExp(message) + }); + }); +}