From 99d85be529cd22df33236f575c2c8a87ee955719 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 3 Mar 2025 21:57:13 -0800 Subject: [PATCH] node: fix test-net-connect-options-invalid.js (#17824) --- src/js/node/net.ts | 7 +++++ .../test-net-connect-options-invalid.js | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/js/node/test/parallel/test-net-connect-options-invalid.js 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) + }); + }); +}