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: #20629Fixes: #20335 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 83119db commit 3edb04d

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎src/node_file.cc‎

Lines changed: 3 additions & 1 deletion
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
voidFSReqWrap::SetReturnValue(const FunctionCallbackInfo<Value>& args) {

‎test/parallel/test-fs-access.js‎

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

6565
constthrowNextTick=(e)=>{process.nextTick(()=>{throwe;});};
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‎

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

0 commit comments

Comments
 (0)