diff --git a/lib/net_uv.js b/lib/net_uv.js index 6fb09342303..29a23519831 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -363,29 +363,26 @@ Socket.prototype.__defineGetter__('remotePort', function() { }); -Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) { - var encoding, fd, cb; +/* + * Arguments data, [encoding], [cb] + */ +Socket.prototype.write = function(data, arg1, arg2) { + var encoding, cb; // parse arguments - if (typeof arguments[3] == 'function') { - cb = arguments[3]; - fd = arguments[2]; - encoding = arguments[1]; - } else if (typeof arguments[2] == 'function') { - cb = arguments[2]; - if (typeof arguments[1] == 'number') { - fd = arguments[1]; - } else { - encoding = arguments[1]; - } - } else if (typeof arguments[1] == 'function') { - cb = arguments[1]; - } else { - if (typeof arguments[1] == 'number') { - fd = arguments[1]; - } else { - encoding = arguments[1]; - fd = arguments[2]; + if (arg1) { + switch (typeof arg1) { + case 'string': + encoding = arg1; + cb = arg2; + break; + + case 'function': + cb = arg1; + break; + + default: + throw new Error("bad arg"); } } @@ -400,9 +397,9 @@ Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) { if (this._connecting) { this._connectQueueSize += data.length; if (this._connectQueue) { - this._connectQueue.push([data, encoding, fd, cb]); + this._connectQueue.push([data, encoding, cb]); } else { - this._connectQueue = [[data, encoding, fd, cb]]; + this._connectQueue = [[data, encoding, cb]]; } return false; }