Browse Source

net: add length check when normalizing args

This helps to prevent possible deoptimizations that arise when trying
to access nonexistent indices.

PR-URL: https://github.com/nodejs/node/pull/8112
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v4.x
Brian White 9 years ago
committed by Myles Borins
parent
commit
fe48415c60
  1. 6
      lib/net.js

6
lib/net.js

@ -73,7 +73,9 @@ exports.connect = exports.createConnection = function() {
function normalizeConnectArgs(args) { function normalizeConnectArgs(args) {
var options = {}; var options = {};
if (args[0] !== null && typeof args[0] === 'object') { if (args.length === 0) {
return [options];
} else if (args[0] !== null && typeof args[0] === 'object') {
// connect(options, [cb]) // connect(options, [cb])
options = args[0]; options = args[0];
} else if (isPipeName(args[0])) { } else if (isPipeName(args[0])) {
@ -82,7 +84,7 @@ function normalizeConnectArgs(args) {
} else { } else {
// connect(port, [host], [cb]) // connect(port, [host], [cb])
options.port = args[0]; options.port = args[0];
if (typeof args[1] === 'string') { if (args.length > 1 && typeof args[1] === 'string') {
options.host = args[1]; options.host = args[1];
} }
} }

Loading…
Cancel
Save