Skip to content

Commit 3edb04d

Browse files
dankangMylesBorins
authored andcommitted
src: remove 2nd undefined argument in node_file.cc
In the document for fs, there are several functions that state "No arguments other than a possible exception are given to the completion callback." (ex> fs.access, fs.chmod, fs.close, ..) But, the functions are invoking the callback with two parameters (err, undefined) It causes problems in using several API like [async.waterfall](https://caolan.github.io/async/docs.html#waterfall). PR-URL: #20629 Fixes: #20335 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 83119db commit 3edb04d

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/node_file.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ void FSReqWrap::Resolve(Local<Value> value) {
421421
Null(env()->isolate()),
422422
value
423423
};
424-
MakeCallback(env()->oncomplete_string(), arraysize(argv), argv);
424+
MakeCallback(env()->oncomplete_string(),
425+
value->IsUndefined() ? 1 : arraysize(argv),
426+
argv);
425427
}
426428

427429
void FSReqWrap::SetReturnValue(const FunctionCallbackInfo<Value>& args) {

test/parallel/test-fs-access.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,21 @@ assert.strictEqual(typeof fs.X_OK, 'number');
6464

6565
const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
6666

67-
fs.access(__filename, common.mustCall(assert.ifError));
67+
fs.access(__filename, common.mustCall(function(...args) {
68+
assert.deepStrictEqual(args, [null]);
69+
}));
6870
fs.promises.access(__filename)
6971
.then(common.mustCall())
7072
.catch(throwNextTick);
71-
fs.access(__filename, fs.R_OK, common.mustCall(assert.ifError));
73+
fs.access(__filename, fs.R_OK, common.mustCall(function(...args) {
74+
assert.deepStrictEqual(args, [null]);
75+
}));
7276
fs.promises.access(__filename, fs.R_OK)
7377
.then(common.mustCall())
7478
.catch(throwNextTick);
75-
fs.access(readOnlyFile, fs.F_OK | fs.R_OK, common.mustCall(assert.ifError));
79+
fs.access(readOnlyFile, fs.F_OK | fs.R_OK, common.mustCall(function(...args) {
80+
assert.deepStrictEqual(args, [null]);
81+
}));
7682
fs.promises.access(readOnlyFile, fs.F_OK | fs.R_OK)
7783
.then(common.mustCall())
7884
.catch(throwNextTick);

test/parallel/test-fs-close.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const assert = require('assert');
6+
const fs = require('fs');
7+
8+
const fd = fs.openSync(__filename, 'r');
9+
10+
fs.close(fd, common.mustCall(function(...args) {
11+
assert.deepStrictEqual(args, [null]);
12+
}));

0 commit comments

Comments
 (0)