Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Simplify arg parsing in String.write
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Oct 7, 2011
1 parent 1bb820a commit 29ec850
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions lib/net_uv.js
Expand Up @@ -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");
}
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 29ec850

Please sign in to comment.