Skip to content

Commit

Permalink
fs: invoke callbacks with undefined context
Browse files Browse the repository at this point in the history
Many callbacks appear to be invoked with `this` set to `undefined`
including `fs.stat()`, `fs.lstat()`, and `fs.fstat()`.

However, some such as `fs.open()` and `fs.mkdtemp()` invoke their
callbacks with `this` set to `null`. Change to `undefined`.

PR-URL: #14645
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
Trott committed Aug 10, 2017
1 parent c6126b1 commit 2249234
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function makeCallback(cb) {
}

return function() {
return cb.apply(null, arguments);
return cb.apply(undefined, arguments);
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-mkdtemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ assert(common.fileExists(utf8));
function handler(err, folder) {
assert.ifError(err);
assert(common.fileExists(folder));
assert.strictEqual(this, null);
assert.strictEqual(this, undefined);
}

fs.mkdtemp(path.join(common.tmpDir, 'bar.'), common.mustCall(handler));
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
// Confirm that we are not running in the context of the internal binding
// layer.
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
assert.strictEqual(this, null);
assert.strictEqual(this, undefined);
}));

// fstatSync
Expand Down

1 comment on commit 2249234

@mikermcneil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Please sign in to comment.