From ad5b71525d8ed6978f042458373b51faf631a54b Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Fri, 7 Jun 2019 23:46:35 +0200 Subject: [PATCH] fs: remove unnecessary bind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't use Function.prototype.bind where it isn't necessary. Rely on event emitter context instead and on arrow function as class property. PR-URL: https://github.com/nodejs/node/pull/28131 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: Tobias Nießen Reviewed-By: Ruben Bridgewater --- lib/internal/fs/promises.js | 8 ++++---- lib/internal/fs/streams.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index cc3f98268c7e55..785d0b082cc1a2 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -121,7 +121,7 @@ class FileHandle { return writeFile(this, data, options); } - close() { + close = () => { return this[kHandle].close(); } } @@ -425,7 +425,7 @@ async function lchmod(path, mode) { throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()'); const fd = await open(path, O_WRONLY | O_SYMLINK); - return fchmod(fd, mode).finally(fd.close.bind(fd)); + return fchmod(fd, mode).finally(fd.close); } async function lchown(path, uid, gid) { @@ -490,7 +490,7 @@ async function writeFile(path, data, options) { return writeFileHandle(path, data, options); const fd = await open(path, flag, options.mode); - return writeFileHandle(fd, data, options).finally(fd.close.bind(fd)); + return writeFileHandle(fd, data, options).finally(fd.close); } async function appendFile(path, data, options) { @@ -508,7 +508,7 @@ async function readFile(path, options) { return readFileHandle(path, options); const fd = await open(path, flag, 0o666); - return readFileHandle(fd, options).finally(fd.close.bind(fd)); + return readFileHandle(fd, options).finally(fd.close); } module.exports = { diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 880828e0d7ae57..b17ebe5cb4317e 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -442,7 +442,7 @@ WriteStream.prototype.close = function(cb) { // If we are not autoClosing, we should call // destroy on 'finish'. if (!this.autoClose) { - this.on('finish', this.destroy.bind(this)); + this.on('finish', this.destroy); } // We use end() instead of destroy() because of