From 444d77391ccfb4c76e01aead2cb8a7a08c686d71 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 21 May 2022 17:57:01 +0800 Subject: [PATCH] tls: use `kEmptyObject` PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel --- lib/_tls_common.js | 6 +++++- lib/_tls_wrap.js | 7 ++++--- lib/internal/tls/secure-context.js | 6 +++++- lib/internal/tls/secure-pair.js | 3 ++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 533fbe7fd25..2b5b17436bf 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -47,6 +47,10 @@ const { }, } = internalBinding('constants'); +const { + kEmptyObject, +} = require('internal/util'); + const { validateInteger, } = require('internal/validators'); @@ -97,7 +101,7 @@ function SecureContext(secureProtocol, secureOptions, minVersion, maxVersion) { } function createSecureContext(options) { - if (!options) options = {}; + if (!options) options = kEmptyObject; const { honorCipherOrder, diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 6db61991f50..5f1f326c487 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -40,7 +40,8 @@ const { const { assertCrypto, - deprecate + deprecate, + kEmptyObject, } = require('internal/util'); assertCrypto(); @@ -1182,9 +1183,9 @@ function Server(options, listener) { if (typeof options === 'function') { listener = options; - options = {}; + options = kEmptyObject; } else if (options == null || typeof options === 'object') { - options = options || {}; + options = options ?? kEmptyObject; } else { throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); } diff --git a/lib/internal/tls/secure-context.js b/lib/internal/tls/secure-context.js index 8cb3ae06d2e..152627b420a 100644 --- a/lib/internal/tls/secure-context.js +++ b/lib/internal/tls/secure-context.js @@ -17,6 +17,10 @@ const { }, } = require('internal/errors'); +const { + kEmptyObject, +} = require('internal/util'); + const { isArrayBufferView, } = require('internal/util/types'); @@ -117,7 +121,7 @@ function processCiphers(ciphers, name) { return { cipherList, cipherSuites }; } -function configSecureContext(context, options = {}, name = 'options') { +function configSecureContext(context, options = kEmptyObject, name = 'options') { validateObject(options, name); const { diff --git a/lib/internal/tls/secure-pair.js b/lib/internal/tls/secure-pair.js index b3f0930a3c7..db999d90ccf 100644 --- a/lib/internal/tls/secure-pair.js +++ b/lib/internal/tls/secure-pair.js @@ -1,6 +1,7 @@ 'use strict'; const EventEmitter = require('events'); +const { kEmptyObject } = require('internal/util'); const { Duplex } = require('stream'); const _tls_wrap = require('_tls_wrap'); const _tls_common = require('_tls_common'); @@ -57,7 +58,7 @@ class SecurePair extends EventEmitter { isServer = false, requestCert = !isServer, rejectUnauthorized = false, - options = {}) { + options = kEmptyObject) { super(); const { socket1, socket2 } = new DuplexPair();