-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: prefer param function check over args length #23835
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 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/fs.js
Outdated
@@ -412,7 +412,7 @@ function open(path, flags, mode, callback) { | |||
path = toPathIfFileURL(path); | |||
validatePath(path); | |||
const flagsNumber = stringToFlags(flags); | |||
if (arguments.length < 4) { | |||
if (typeof mode === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will conflict with @bnoordhuis's work on #23767
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
fs
methods 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