diff --git a/lib/fs.js b/lib/fs.js index d01e99c21b0178..20c99e3224414e 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1099,7 +1099,8 @@ function hasNoEntryError(ctx) { function fstatSync(fd, options = { bigint: false, throwIfNoEntry: true }) { validateInt32(fd, 'fd', 0); const ctx = { fd }; - const stats = binding.fstat(fd, options.bigint, undefined, ctx); + // The fd should be `fd | 0` just for the edgecase when `fd = -0` + const stats = binding.fstat(fd | 0, options.bigint, undefined, ctx); handleErrorFromBinding(ctx); return getStatsFromBinding(stats); } diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index 31aec8fab00450..abd87f53e7f85c 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -69,6 +69,8 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { fs.close(fd, common.mustSucceed()); })); +assert.ok(fs.fstatSync(-0)); + fs.stat(__filename, common.mustSucceed((s) => { assert.strictEqual(s.isDirectory(), false); assert.strictEqual(s.isFile(), true);