mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
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
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user