diff options
author | koichik <koichik@improvement.jp> | 2011-07-05 00:34:58 +0900 |
---|---|---|
committer | koichik <koichik@improvement.jp> | 2011-07-05 00:52:16 +0900 |
commit | c60cdcda4e39081fa56568df941aff1a4b56b39c (patch) | |
tree | bd103f0b2965e4bcf76cc64b16cb7299b85ea793 /lib | |
parent | bd0baf23383951182b10261b076cf6268152a68b (diff) | |
download | android-node-v8-c60cdcda4e39081fa56568df941aff1a4b56b39c.tar.gz android-node-v8-c60cdcda4e39081fa56568df941aff1a4b56b39c.tar.bz2 android-node-v8-c60cdcda4e39081fa56568df941aff1a4b56b39c.zip |
Fix net.Socket.connect argument parsing
Fixes #1251.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net_legacy.js | 13 | ||||
-rw-r--r-- | lib/net_uv.js | 16 |
2 files changed, 20 insertions, 9 deletions
diff --git a/lib/net_legacy.js b/lib/net_legacy.js index 4254dc9a44..52f4e9405b 100644 --- a/lib/net_legacy.js +++ b/lib/net_legacy.js @@ -700,9 +700,14 @@ Socket.prototype.connect = function() { self._connecting = true; // set false in doConnect self.writable = true; - var lastArg = arguments[arguments.length - 1]; - if (typeof lastArg == 'function') { - self.addListener('connect', lastArg); + var host; + if (typeof arguments[1] === 'function') { + self.on('connect', arguments[1]); + } else { + host = arguments[1]; + if (typeof arguments[2] === 'function') { + self.on('connect', arguments[2]); + } } var port = toPort(arguments[0]); @@ -715,7 +720,7 @@ Socket.prototype.connect = function() { doConnect(self, arguments[0]); } else { // TCP - require('dns').lookup(arguments[1], function(err, ip, addressType) { + require('dns').lookup(host, function(err, ip, addressType) { if (err) { self.emit('error', err); } else { diff --git a/lib/net_uv.js b/lib/net_uv.js index 63f0a15080..e9db1b2cba 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -24,9 +24,9 @@ exports.createServer = function() { }; -exports.connect = exports.createConnection = function(port, host /* [cb] */ ) { +exports.connect = exports.createConnection = function(port /* [host], [cb] */) { var s = new Socket(); - s.connect(port, host, arguments[2]); + s.connect(port, arguments[1], arguments[2]); return s; }; @@ -340,7 +340,7 @@ function connectip(self, port, ip) { } -Socket.prototype.connect = function(port, host /* [cb] */) { +Socket.prototype.connect = function(port /* [host], [cb] */) { var self = this; if (this.destroyed) { @@ -348,8 +348,14 @@ Socket.prototype.connect = function(port, host /* [cb] */) { initSocketHandle(this); } - if (typeof arguments[2] === 'function') { - self.on('connect', arguments[2]); + var host; + if (typeof arguments[1] === 'function') { + self.on('connect', arguments[1]); + } else { + host = arguments[1]; + if (typeof arguments[2] === 'function') { + self.on('connect', arguments[2]); + } } timers.active(this); |