Skip to content

Commit c3eb3ef

Browse files
committed
fs: fix functions executed in wrong context
The callback should run in the global scope and not in the FSReqWrap context. PR-URL: #18668 Refs: #12562 Refs: #12976 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent e9f2cec commit c3eb3ef

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

lib/fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ fs.ftruncateSync = function(fd, len = 0) {
737737
};
738738

739739
fs.rmdir = function(path, callback) {
740-
callback = maybeCallback(callback);
740+
callback = makeCallback(callback);
741741
path = getPathFromURL(path);
742742
validatePath(path);
743743
const req = new FSReqWrap();
@@ -1784,7 +1784,7 @@ fs.realpath = function realpath(p, options, callback) {
17841784

17851785

17861786
fs.realpath.native = function(path, options, callback) {
1787-
callback = maybeCallback(callback || options);
1787+
callback = makeCallback(callback || options);
17881788
options = getOptions(options, {});
17891789
path = getPathFromURL(path);
17901790
validatePath(path);

test/parallel/test-fs-mkdir-rmdir.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fs.mkdir(d, 0o666, common.mustCall(function(err) {
2929
assert.ifError(err);
3030

3131
fs.mkdir(d, 0o666, common.mustCall(function(err) {
32+
assert.strictEqual(this, undefined);
3233
assert.ok(err, 'got no error');
3334
assert.ok(/^EEXIST/.test(err.message), 'got no EEXIST message');
3435
assert.strictEqual(err.code, 'EEXIST', 'got no EEXIST code');

test/parallel/test-fs-realpath-native.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const fs = require('fs');
66
if (!common.isOSX) common.skip('MacOS-only test.');
77

88
assert.strictEqual(fs.realpathSync.native('/users'), '/Users');
9-
fs.realpath.native('/users', common.mustCall((err, res) => {
9+
fs.realpath.native('/users', common.mustCall(function(err, res) {
1010
assert.ifError(err);
1111
assert.strictEqual(res, '/Users');
12+
assert.strictEqual(this, undefined);
1213
}));

0 commit comments

Comments
 (0)