src: prefer param function check over args length#23835
src: prefer param function check over args length#23835codebytere wants to merge 1 commit intonodejs:masterfrom codebytere:update-cb-checking
Conversation
|
👍 I had a thought once about doing something like: function fstat(fd, ...args) {
const lastArg = args.pop();
const callback = (typeof lastArg === 'function') ? lastArg : throw ..;
const options = args.pop() || {};
...
}Actually what we need is a generic arg validator :dream: function fstat(...args) {
const { fd, options, callback } = validateArgs(args, { some sort of contract }); |
lib/fs.js
Outdated
There was a problem hiding this comment.
I think this will conflict with @bnoordhuis's work on #23767
There was a problem hiding this comment.
Should we land #23767 first and then adapt this PR to that change? Seems do-able. /cc @codebytere @bnoordhuis
|
@codebytere This seems ready to go if we can get a rebase to resolve the merge conflict with #23767... |
|
@Trott i'll handle first thing tomorrow! |
|
@Trott should be set! i couldn't change this line becuase if i simply checked for |
|
Landed in 7cf5679 |
PR-URL: nodejs#23835 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
PR-URL: #23835 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
PR-URL: nodejs#23835 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
PR-URL: #23835 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
PR-URL: #23835 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
PR-URL: #23835 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
We have to override some
fsmethods in Electron, and as I looked at their original impls I believe that checking the type of the second argument as opposed to simply the number of arguments passed is more consistent and reliable.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes