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: nodejs#18668 Refs: nodejs#12562 Refs: nodejs#12976 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
1 parent e9f2cec commit c3eb3ef

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

lib/fs.js

+2-2
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

+1
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

+2-1
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)