-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
net: refactor Server.prototype.listen #4039
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
Changes from 1 commit
d5452a6
88c44c1
df8d8c8
959582c
d1c6f7b
708e1b4
150723d
5ab4028
0bffc03
db798ea
e772fa3
3fb1435
4a65449
3848eae
4bb5770
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This is mostly preparation, `options` will be used later.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1326,9 +1326,20 @@ function listen(self, address, port, addressType, backlog, fd, exclusive) { | |
|
|
||
|
|
||
| Server.prototype.listen = function() { | ||
| var lastArg = arguments[arguments.length - 1]; | ||
| if (typeof lastArg === 'function') { | ||
| this.once('listening', lastArg); | ||
| const argsLen = arguments.length; | ||
| var args = new Array(argsLen); | ||
| for (var i = 0; i < argsLen; i++) | ||
| args[i] = arguments[i]; | ||
| args = normalizeConnectArgs(args); | ||
|
||
|
|
||
| if (args[1]) { | ||
|
||
| this.once('listening', args[1]); | ||
| } | ||
|
|
||
| var options = args[0]; | ||
| if (arguments.length === 0 || typeof arguments[0] === 'function') { | ||
|
||
| // Bind to a random port. | ||
| options.port = 0; | ||
| } | ||
|
|
||
| var port = toNumber(arguments[0]); | ||
|
|
@@ -1337,6 +1348,8 @@ Server.prototype.listen = function() { | |
| // When the ip is omitted it can be the second argument. | ||
| var backlog = toNumber(arguments[1]) || toNumber(arguments[2]); | ||
|
||
|
|
||
| options = options._handle || options.handle || options; | ||
|
|
||
| if (arguments.length === 0 || typeof arguments[0] === 'function') { | ||
| // Bind to a random port. | ||
| listen(this, null, 0, null, backlog); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
This line is unnecessary, just use
arguments.lengthin both places below. V8 is smart enough to optimize thecase.
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 just copied this snippet; it was introduced in d0582ef. If you want to change this, I'd say it should be changed everywhere, and I think that doesn't fit into this PR.
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 disagree that it has to be all or nothing for this type of change. I do not see any harm in changing it in this PR.