diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 4893cdc96b0b9b..117db86598ad0d 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -789,7 +789,11 @@ function pingCallback(cb) { // 6. enablePush must be a boolean // All settings are optional and may be left undefined function validateSettings(settings) { - settings = { ...settings }; + if (settings === undefined) { + const err = new ERR_INVALID_ARG_TYPE('settings', 'object', settings); + Error.captureStackTrace(err, 'validateSettings'); + throw err; + } assertWithinRange('headerTableSize', settings.headerTableSize, 0, kMaxInt); @@ -813,7 +817,6 @@ function validateSettings(settings) { Error.captureStackTrace(err, 'validateSettings'); throw err; } - return settings; } // Creates the internal binding.Http2Session handle for an Http2Session @@ -1152,7 +1155,7 @@ class Http2Session extends EventEmitter { if (this.destroyed) throw new ERR_HTTP2_INVALID_SESSION(); assertIsObject(settings, 'settings'); - settings = validateSettings(settings); + validateSettings(settings); if (callback && typeof callback !== 'function') throw new ERR_INVALID_CALLBACK(); @@ -1160,7 +1163,7 @@ class Http2Session extends EventEmitter { this[kState].pendingAck++; - const settingsFn = submitSettings.bind(this, settings, callback); + const settingsFn = submitSettings.bind(this, { ...settings }, callback); if (this.connecting) { this.once('connect', settingsFn); return; @@ -2830,7 +2833,8 @@ function createServer(options, handler) { // HTTP2-Settings header frame. function getPackedSettings(settings) { assertIsObject(settings, 'settings'); - updateSettingsBuffer(validateSettings(settings)); + validateSettings(settings); + updateSettingsBuffer({ ...settings }); return binding.packSettings(); } diff --git a/test/parallel/test-http2-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js index 77c8cf442f5f27..0df2457f76c67c 100644 --- a/test/parallel/test-http2-getpackedsettings.js +++ b/test/parallel/test-http2-getpackedsettings.js @@ -88,8 +88,10 @@ http2.getPackedSettings({ enablePush: false }); // Check for not passing settings. { - const packed = http2.getPackedSettings(); - assert.strictEqual(packed.length, 0); + assert.throws( + () => http2.getPackedSettings(), + { code: 'ERR_INVALID_ARG_TYPE' } + ); } {