From c3eb3efa315382d1073d6a126f4d888cf3e121ec Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 9 Feb 2018 16:31:26 +0100 Subject: [PATCH] fs: fix functions executed in wrong context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The callback should run in the global scope and not in the FSReqWrap context. PR-URL: https://github.com/nodejs/node/pull/18668 Refs: https://github.com/nodejs/node/pull/12562 Refs: https://github.com/nodejs/node/pull/12976 Reviewed-By: Matteo Collina Reviewed-By: Michaƫl Zasso Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Joyee Cheung Reviewed-By: Gus Caplan --- lib/fs.js | 4 ++-- test/parallel/test-fs-mkdir-rmdir.js | 1 + test/parallel/test-fs-realpath-native.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index abffde7b9ec9e6..543e6b8c618f55 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -737,7 +737,7 @@ fs.ftruncateSync = function(fd, len = 0) { }; fs.rmdir = function(path, callback) { - callback = maybeCallback(callback); + callback = makeCallback(callback); path = getPathFromURL(path); validatePath(path); const req = new FSReqWrap(); @@ -1784,7 +1784,7 @@ fs.realpath = function realpath(p, options, callback) { fs.realpath.native = function(path, options, callback) { - callback = maybeCallback(callback || options); + callback = makeCallback(callback || options); options = getOptions(options, {}); path = getPathFromURL(path); validatePath(path); diff --git a/test/parallel/test-fs-mkdir-rmdir.js b/test/parallel/test-fs-mkdir-rmdir.js index 865a5dba951555..6427dbd34034d9 100644 --- a/test/parallel/test-fs-mkdir-rmdir.js +++ b/test/parallel/test-fs-mkdir-rmdir.js @@ -29,6 +29,7 @@ fs.mkdir(d, 0o666, common.mustCall(function(err) { assert.ifError(err); fs.mkdir(d, 0o666, common.mustCall(function(err) { + assert.strictEqual(this, undefined); assert.ok(err, 'got no error'); assert.ok(/^EEXIST/.test(err.message), 'got no EEXIST message'); assert.strictEqual(err.code, 'EEXIST', 'got no EEXIST code'); diff --git a/test/parallel/test-fs-realpath-native.js b/test/parallel/test-fs-realpath-native.js index 43d6b8ca80734b..93b5a278cf4f1e 100644 --- a/test/parallel/test-fs-realpath-native.js +++ b/test/parallel/test-fs-realpath-native.js @@ -6,7 +6,8 @@ const fs = require('fs'); if (!common.isOSX) common.skip('MacOS-only test.'); assert.strictEqual(fs.realpathSync.native('/users'), '/Users'); -fs.realpath.native('/users', common.mustCall((err, res) => { +fs.realpath.native('/users', common.mustCall(function(err, res) { assert.ifError(err); assert.strictEqual(res, '/Users'); + assert.strictEqual(this, undefined); }));