-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
cb may be undefined as well #11848
cb may be undefined as well #11848
Conversation
@@ -954,7 +954,7 @@ Socket.prototype.connect = function() { | |||
initSocketHandle(this); | |||
} | |||
|
|||
if (cb !== null) { | |||
if (cb) { |
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 the best approach is probably to check if typeof cb === '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 was also going to suggest that. Yes.
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 we need to check if cb is undefined, to respect API contract: net.connect(options[,
connectListener])
I don't think that net.connect(options, 42) or
net.connect(options, 'anything')
should silently ignore the second parameter without failure, what do you think ?
Duplicate of #11762? |
BTW: |
If we do go with this, it needs a test I think. |
@vincent-tr Thanks for taking the time to submit this PR! @vincent-tr and @joyeecheung: Since #11762 landed, does that mean this PR obsolete should be closed? |
I think changing to an explicit |
@Trott #11762 also added a test, I don't think there are more tests this PR can add if it's only to make sure cb can be undefined (because now it's always normalized, so when it gets to this point cb can not be undefined anymore). If it changes to |
@Trott @joyeecheung having a look at #11762 it handles indeed this case. |
@vincent-tr I agree letting things like /~https://github.com/search?l=JavaScript&q=net.connect.apply&type=Code&utf8=%E2%9C%93 |
True. Closing then, Thanks :) |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
net (Socket.protype.connect)