From 607ee37a5da611c805bda3217c7f8c7ed49e9227 Mon Sep 17 00:00:00 2001 From: Marco Levrero Date: Tue, 19 Jun 2018 22:03:33 +0100 Subject: [PATCH 1/4] lib: name anonymous callbacks This commit is to help in the effort to name all anonymous functions to help when heap debugging. Specifically, this commit fixes some anonymous functions used as listeners in the lib/ folder. Refs: https://github.com/nodejs/node/issues/8913 --- lib/_http_outgoing.js | 4 ++-- lib/_tls_common.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 913935048680eb..c9ff30ce958140 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -183,7 +183,7 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) { } if (!this.socket) { - this.once('socket', function(socket) { + this.once('socket', function socketOnceCallback(socket) { socket.setTimeout(msecs); }); } else { @@ -200,7 +200,7 @@ OutgoingMessage.prototype.destroy = function destroy(error) { if (this.socket) { this.socket.destroy(error); } else { - this.once('socket', function(socket) { + this.once('socket', function socketOnceCallback(socket) { socket.destroy(error); }); } diff --git a/lib/_tls_common.js b/lib/_tls_common.js index d8f6afed0bd8fb..127ecb0fc9a168 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -240,7 +240,7 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) { c.infoAccess = Object.create(null); // XXX: More key validation? - info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, function(all, key, val) { + info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, function replacerCallback(all, key, val) { if (key in c.infoAccess) c.infoAccess[key].push(val); else From 72c257306a57fbba5553c50318ed80b0a4e697f5 Mon Sep 17 00:00:00 2001 From: Marco Levrero Date: Sun, 29 Jul 2018 19:24:32 +0100 Subject: [PATCH 2/4] Improved naming --- lib/_http_outgoing.js | 4 ++-- lib/_tls_common.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index c9ff30ce958140..d150a9d93cdf88 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -183,7 +183,7 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) { } if (!this.socket) { - this.once('socket', function socketOnceCallback(socket) { + this.once('socket', function socketSetTimeoutOnConnect(socket) { socket.setTimeout(msecs); }); } else { @@ -200,7 +200,7 @@ OutgoingMessage.prototype.destroy = function destroy(error) { if (this.socket) { this.socket.destroy(error); } else { - this.once('socket', function socketOnceCallback(socket) { + this.once('socket', function socketDestroyOnConnect(socket) { socket.destroy(error); }); } diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 127ecb0fc9a168..562a2bda8499ec 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -240,7 +240,7 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) { c.infoAccess = Object.create(null); // XXX: More key validation? - info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, function replacerCallback(all, key, val) { + info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, function (all, key, val) { if (key in c.infoAccess) c.infoAccess[key].push(val); else From fa194ca91c751604e03b10eb7f0b0f2dbd4e772e Mon Sep 17 00:00:00 2001 From: Marco Levrero Date: Sun, 29 Jul 2018 20:30:57 +0100 Subject: [PATCH 3/4] Make linter happy --- lib/_tls_common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 562a2bda8499ec..d8f6afed0bd8fb 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -240,7 +240,7 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) { c.infoAccess = Object.create(null); // XXX: More key validation? - info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, function (all, key, val) { + info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, function(all, key, val) { if (key in c.infoAccess) c.infoAccess[key].push(val); else From b1e3dc12ac0e70d09e72af06e988b30e5f917b35 Mon Sep 17 00:00:00 2001 From: Marco Levrero Date: Mon, 30 Jul 2018 18:12:44 +0100 Subject: [PATCH 4/4] Use arrow function --- lib/_tls_common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/_tls_common.js b/lib/_tls_common.js index d8f6afed0bd8fb..de96fa687dcc02 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -240,7 +240,7 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) { c.infoAccess = Object.create(null); // XXX: More key validation? - info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, function(all, key, val) { + info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, (all, key, val) => { if (key in c.infoAccess) c.infoAccess[key].push(val); else