diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index b3fbba0596d736..7df4b6612229aa 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -591,10 +591,6 @@ TLSSocket.prototype.setMaxSendFragment = function setMaxSendFragment(size) { return this._handle.setMaxSendFragment(size) === 1; }; -TLSSocket.prototype.getTLSTicket = function getTLSTicket() { - return this._handle.getTLSTicket(); -}; - TLSSocket.prototype._handleTimeout = function() { this._emitTLSError(new ERR_TLS_HANDSHAKE_TIMEOUT()); }; @@ -671,51 +667,25 @@ TLSSocket.prototype.getPeerCertificate = function(detailed) { return null; }; -TLSSocket.prototype.getFinished = function() { - if (this._handle) - return this._handle.getFinished(); -}; - -TLSSocket.prototype.getPeerFinished = function() { - if (this._handle) - return this._handle.getPeerFinished(); -}; - -TLSSocket.prototype.getSession = function() { - if (this._handle) { - return this._handle.getSession(); - } - - return null; -}; - -TLSSocket.prototype.isSessionReused = function() { - if (this._handle) { - return this._handle.isSessionReused(); - } - - return null; -}; - -TLSSocket.prototype.getCipher = function(err) { - if (this._handle) { - return this._handle.getCurrentCipher(); - } else { +// Proxy TLSSocket handle methods +function makeSocketMethodProxy(name) { + return function socketMethodProxy(...args) { + if (this._handle) + return this._handle[name].apply(this._handle, args); return null; - } -}; - -TLSSocket.prototype.getEphemeralKeyInfo = function() { - if (this._handle) - return this._handle.getEphemeralKeyInfo(); + }; +} - return null; -}; +[ + 'getFinished', 'getPeerFinished', 'getSession', 'isSessionReused', + 'getEphemeralKeyInfo', 'getProtocol', 'getTLSTicket' +].forEach((method) => { + TLSSocket.prototype[method] = makeSocketMethodProxy(method); +}); -TLSSocket.prototype.getProtocol = function() { +TLSSocket.prototype.getCipher = function(err) { if (this._handle) - return this._handle.getProtocol(); - + return this._handle.getCurrentCipher(); return null; };