Simplify arg parsing in String.write
This commit is contained in:
parent
1bb820a339
commit
29ec850478
@ -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
|
// parse arguments
|
||||||
if (typeof arguments[3] == 'function') {
|
if (arg1) {
|
||||||
cb = arguments[3];
|
switch (typeof arg1) {
|
||||||
fd = arguments[2];
|
case 'string':
|
||||||
encoding = arguments[1];
|
encoding = arg1;
|
||||||
} else if (typeof arguments[2] == 'function') {
|
cb = arg2;
|
||||||
cb = arguments[2];
|
break;
|
||||||
if (typeof arguments[1] == 'number') {
|
|
||||||
fd = arguments[1];
|
case 'function':
|
||||||
} else {
|
cb = arg1;
|
||||||
encoding = arguments[1];
|
break;
|
||||||
}
|
|
||||||
} else if (typeof arguments[1] == 'function') {
|
default:
|
||||||
cb = arguments[1];
|
throw new Error("bad arg");
|
||||||
} else {
|
|
||||||
if (typeof arguments[1] == 'number') {
|
|
||||||
fd = arguments[1];
|
|
||||||
} else {
|
|
||||||
encoding = arguments[1];
|
|
||||||
fd = arguments[2];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,9 +397,9 @@ Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) {
|
|||||||
if (this._connecting) {
|
if (this._connecting) {
|
||||||
this._connectQueueSize += data.length;
|
this._connectQueueSize += data.length;
|
||||||
if (this._connectQueue) {
|
if (this._connectQueue) {
|
||||||
this._connectQueue.push([data, encoding, fd, cb]);
|
this._connectQueue.push([data, encoding, cb]);
|
||||||
} else {
|
} else {
|
||||||
this._connectQueue = [[data, encoding, fd, cb]];
|
this._connectQueue = [[data, encoding, cb]];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user