-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
lib: consistent callback checking across project #3539
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,11 +90,12 @@ exports.OutgoingMessage = OutgoingMessage; | |
|
||
OutgoingMessage.prototype.setTimeout = function(msecs, callback) { | ||
|
||
if (callback) { | ||
if (typeof callback !== 'function') | ||
throw new TypeError('callback must be a function'); | ||
if (typeof callback === 'function') { | ||
this.on('timeout', callback); | ||
} | ||
else if (callback) { | ||
throw new TypeError('callback must be a function'); | ||
} | ||
|
||
if (!this.socket) { | ||
this.once('socket', function(socket) { | ||
|
@@ -482,7 +483,7 @@ OutgoingMessage.prototype.write = function(chunk, encoding, callback) { | |
|
||
function writeAfterEndNT(self, err, callback) { | ||
self.emit('error', err); | ||
if (callback) callback(err); | ||
if (typeof callback === 'function') callback(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting one. Prior to the change a callback that isn't a function would throw. In this instance it would fail silently There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably needs an |
||
} | ||
|
||
|
||
|
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.
continuing https://github.com/nodejs/node/pull/3539/files#r43079350
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.
@thefourtheye so you are suggesting that this Type check shouldn't be done.
@Trott suggested otherwise in --> #3539 (comment)
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.
@jasnell was for it as well --> #3539 (comment)
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'm for it if there is the
typeof
check. I think @thefourtheye is saying that you can discard thetypeof
check and theelse
block and just pass blindly to.on()
because.on()
will throw aTypeError
if the callback is not a function. At least, that's my understanding. So I'm for either approach, really. Don't make no neither nor to me.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.
In other words, I think @thefourtheye is saying this would be fine:
Which throws a wrench in the whole "standardize on
typeof
checks" approach.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.
We need that
if
guard if and only ifcallback
might be optional and thereforeundefined
. I didn't look at the code to see if that is actually possible.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.
Right... At least the event handler code doesn't need this if block as it is done anyway in
on
,once
,{add,remove}listener
functions