Skip to content
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

net: avoid use of arguments #11411

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ exports.createServer = function(options, connectionListener) {
// connect(port, [host], [cb])
// connect(path, [cb]);
//
exports.connect = exports.createConnection = function() {
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++)
args[i] = arguments[i];
exports.connect = exports.createConnection = function(...args) {
args = normalizeArgs(args);
debug('createConnection', args);
var s = new Socket(args[0]);
Expand Down Expand Up @@ -887,17 +884,15 @@ function connect(self, address, port, addressType, localAddress, localPort) {
}


Socket.prototype.connect = function(options, cb) {
Socket.prototype.connect = function(options, cb, ...args) {
if (this.write !== Socket.prototype.write)
this.write = Socket.prototype.write;

if (options === null || typeof options !== 'object') {
// Old API:
// connect(port, [host], [cb])
// connect(path, [cb]);
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++)
args[i] = arguments[i];
args.unshift(options, cb);
args = normalizeArgs(args);
return Socket.prototype.connect.apply(this, args);
}
Expand Down Expand Up @@ -1334,10 +1329,7 @@ function listen(self, address, port, addressType, backlog, fd, exclusive) {
}


Server.prototype.listen = function() {
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++)
args[i] = arguments[i];
Server.prototype.listen = function(...args) {
var [options, cb] = normalizeArgs(args);

if (typeof cb === 'function') {
Expand Down