lib: reduce usage of self = this
Remove unnecessary `self = this`. PR-URL: https://github.com/nodejs/node/pull/5231 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
f70c71f168
commit
d2b93e55cc
@ -1026,15 +1026,14 @@ function SimpleProtocol(source, options) {
|
|||||||
// source is a readable stream, such as a socket or file
|
// source is a readable stream, such as a socket or file
|
||||||
this._source = source;
|
this._source = source;
|
||||||
|
|
||||||
var self = this;
|
|
||||||
source.on('end', () => {
|
source.on('end', () => {
|
||||||
self.push(null);
|
this.push(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
// give it a kick whenever the source is readable
|
// give it a kick whenever the source is readable
|
||||||
// read(0) will not consume any bytes
|
// read(0) will not consume any bytes
|
||||||
source.on('readable', () => {
|
source.on('readable', () => {
|
||||||
self.read(0);
|
this.read(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._rawHeader = [];
|
this._rawHeader = [];
|
||||||
|
@ -404,8 +404,7 @@ Socket.prototype.close = function(callback) {
|
|||||||
this._stopReceiving();
|
this._stopReceiving();
|
||||||
this._handle.close();
|
this._handle.close();
|
||||||
this._handle = null;
|
this._handle = null;
|
||||||
var self = this;
|
process.nextTick(socketCloseNT, this);
|
||||||
process.nextTick(socketCloseNT, self);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -60,7 +60,6 @@ Domain.prototype._disposed = undefined;
|
|||||||
// Called by process._fatalException in case an error was thrown.
|
// Called by process._fatalException in case an error was thrown.
|
||||||
Domain.prototype._errorHandler = function errorHandler(er) {
|
Domain.prototype._errorHandler = function errorHandler(er) {
|
||||||
var caught = false;
|
var caught = false;
|
||||||
var self = this;
|
|
||||||
|
|
||||||
// ignore errors on disposed domains.
|
// ignore errors on disposed domains.
|
||||||
//
|
//
|
||||||
@ -89,13 +88,13 @@ Domain.prototype._errorHandler = function errorHandler(er) {
|
|||||||
// as this would throw an error, make the process exit, and thus
|
// as this would throw an error, make the process exit, and thus
|
||||||
// prevent the process 'uncaughtException' event from being emitted
|
// prevent the process 'uncaughtException' event from being emitted
|
||||||
// if a listener is set.
|
// if a listener is set.
|
||||||
if (EventEmitter.listenerCount(self, 'error') > 0) {
|
if (EventEmitter.listenerCount(this, 'error') > 0) {
|
||||||
try {
|
try {
|
||||||
// Set the _emittingTopLevelDomainError so that we know that, even
|
// Set the _emittingTopLevelDomainError so that we know that, even
|
||||||
// if technically the top-level domain is still active, it would
|
// if technically the top-level domain is still active, it would
|
||||||
// be ok to abort on an uncaught exception at this point
|
// be ok to abort on an uncaught exception at this point
|
||||||
process._emittingTopLevelDomainError = true;
|
process._emittingTopLevelDomainError = true;
|
||||||
caught = self.emit('error', er);
|
caught = this.emit('error', er);
|
||||||
} finally {
|
} finally {
|
||||||
process._emittingTopLevelDomainError = false;
|
process._emittingTopLevelDomainError = false;
|
||||||
}
|
}
|
||||||
@ -111,7 +110,7 @@ Domain.prototype._errorHandler = function errorHandler(er) {
|
|||||||
//
|
//
|
||||||
// If caught is false after this, then there's no need to exit()
|
// If caught is false after this, then there's no need to exit()
|
||||||
// the domain, because we're going to crash the process anyway.
|
// the domain, because we're going to crash the process anyway.
|
||||||
caught = self.emit('error', er);
|
caught = this.emit('error', er);
|
||||||
} catch (er2) {
|
} catch (er2) {
|
||||||
// The domain error handler threw! oh no!
|
// The domain error handler threw! oh no!
|
||||||
// See if another domain can catch THIS error,
|
// See if another domain can catch THIS error,
|
||||||
|
@ -77,12 +77,11 @@ function createConnection(port, host, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const self = this;
|
const socket = tls.connect(options, () => {
|
||||||
const socket = tls.connect(options, function() {
|
|
||||||
if (!options._agentKey)
|
if (!options._agentKey)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self._cacheSession(options._agentKey, socket.getSession());
|
this._cacheSession(options._agentKey, socket.getSession());
|
||||||
});
|
});
|
||||||
|
|
||||||
// Evict session on error
|
// Evict session on error
|
||||||
|
47
lib/net.js
47
lib/net.js
@ -299,9 +299,8 @@ Socket.prototype.read = function(n) {
|
|||||||
|
|
||||||
Socket.prototype.listen = function() {
|
Socket.prototype.listen = function() {
|
||||||
debug('socket.listen');
|
debug('socket.listen');
|
||||||
var self = this;
|
this.on('connection', arguments[0]);
|
||||||
self.on('connection', arguments[0]);
|
listen(this, null, null, null);
|
||||||
listen(self, null, null, null);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -883,7 +882,6 @@ Socket.prototype.connect = function(options, cb) {
|
|||||||
this._sockname = null;
|
this._sockname = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
|
||||||
var pipe = !!options.path;
|
var pipe = !!options.path;
|
||||||
debug('pipe', pipe, options.path);
|
debug('pipe', pipe, options.path);
|
||||||
|
|
||||||
@ -893,21 +891,20 @@ Socket.prototype.connect = function(options, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
self.once('connect', cb);
|
this.once('connect', cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._unrefTimer();
|
this._unrefTimer();
|
||||||
|
|
||||||
self._connecting = true;
|
this._connecting = true;
|
||||||
self.writable = true;
|
this.writable = true;
|
||||||
|
|
||||||
if (pipe) {
|
if (pipe) {
|
||||||
connect(self, options.path);
|
connect(this, options.path);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
lookupAndConnect(self, options);
|
lookupAndConnect(this, options);
|
||||||
}
|
}
|
||||||
return self;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1198,11 +1195,10 @@ exports._createServerHandle = createServerHandle;
|
|||||||
|
|
||||||
Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
|
Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
|
||||||
debug('listen2', address, port, addressType, backlog, fd);
|
debug('listen2', address, port, addressType, backlog, fd);
|
||||||
var self = this;
|
|
||||||
|
|
||||||
// If there is not yet a handle, we need to create one and bind.
|
// If there is not yet a handle, we need to create one and bind.
|
||||||
// In the case of a server sent via IPC, we don't need to do this.
|
// In the case of a server sent via IPC, we don't need to do this.
|
||||||
if (self._handle) {
|
if (this._handle) {
|
||||||
debug('_listen2: have a handle already');
|
debug('_listen2: have a handle already');
|
||||||
} else {
|
} else {
|
||||||
debug('_listen2: create a handle');
|
debug('_listen2: create a handle');
|
||||||
@ -1227,22 +1223,22 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
|
|||||||
|
|
||||||
if (typeof rval === 'number') {
|
if (typeof rval === 'number') {
|
||||||
var error = exceptionWithHostPort(rval, 'listen', address, port);
|
var error = exceptionWithHostPort(rval, 'listen', address, port);
|
||||||
process.nextTick(emitErrorNT, self, error);
|
process.nextTick(emitErrorNT, this, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self._handle = rval;
|
this._handle = rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
self._handle.onconnection = onconnection;
|
this._handle.onconnection = onconnection;
|
||||||
self._handle.owner = self;
|
this._handle.owner = this;
|
||||||
|
|
||||||
var err = _listen(self._handle, backlog);
|
var err = _listen(this._handle, backlog);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
var ex = exceptionWithHostPort(err, 'listen', address, port);
|
var ex = exceptionWithHostPort(err, 'listen', address, port);
|
||||||
self._handle.close();
|
this._handle.close();
|
||||||
self._handle = null;
|
this._handle = null;
|
||||||
process.nextTick(emitErrorNT, self, ex);
|
process.nextTick(emitErrorNT, this, ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1253,7 +1249,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
|
|||||||
if (this._unref)
|
if (this._unref)
|
||||||
this.unref();
|
this.unref();
|
||||||
|
|
||||||
process.nextTick(emitListeningNT, self);
|
process.nextTick(emitListeningNT, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1522,15 +1518,14 @@ Server.prototype.close = function(cb) {
|
|||||||
|
|
||||||
Server.prototype._emitCloseIfDrained = function() {
|
Server.prototype._emitCloseIfDrained = function() {
|
||||||
debug('SERVER _emitCloseIfDrained');
|
debug('SERVER _emitCloseIfDrained');
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (self._handle || self._connections) {
|
if (this._handle || this._connections) {
|
||||||
debug('SERVER handle? %j connections? %d',
|
debug('SERVER handle? %j connections? %d',
|
||||||
!!self._handle, self._connections);
|
!!this._handle, this._connections);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
process.nextTick(emitCloseNT, self);
|
process.nextTick(emitCloseNT, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1155,7 +1155,7 @@ function regexpEscape(s) {
|
|||||||
REPLServer.prototype.convertToContext = function(cmd) {
|
REPLServer.prototype.convertToContext = function(cmd) {
|
||||||
const scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m;
|
const scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m;
|
||||||
const scopeFunc = /^\s*function\s*([_\w\$]+)/;
|
const scopeFunc = /^\s*function\s*([_\w\$]+)/;
|
||||||
var self = this, matches;
|
var matches;
|
||||||
|
|
||||||
// Replaces: var foo = "bar"; with: self.context.foo = bar;
|
// Replaces: var foo = "bar"; with: self.context.foo = bar;
|
||||||
matches = scopeVar.exec(cmd);
|
matches = scopeVar.exec(cmd);
|
||||||
@ -1164,9 +1164,9 @@ REPLServer.prototype.convertToContext = function(cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Replaces: function foo() {}; with: foo = function foo() {};
|
// Replaces: function foo() {}; with: foo = function foo() {};
|
||||||
matches = scopeFunc.exec(self.bufferedCommand);
|
matches = scopeFunc.exec(this.bufferedCommand);
|
||||||
if (matches && matches.length === 2) {
|
if (matches && matches.length === 2) {
|
||||||
return matches[1] + ' = ' + self.bufferedCommand;
|
return matches[1] + ' = ' + this.bufferedCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
|
@ -125,11 +125,10 @@ SlowStream.prototype.resume = function() {
|
|||||||
|
|
||||||
SlowStream.prototype.end = function(chunk) {
|
SlowStream.prototype.end = function(chunk) {
|
||||||
// walk over the chunk in blocks.
|
// walk over the chunk in blocks.
|
||||||
var self = this;
|
this.chunk = chunk;
|
||||||
self.chunk = chunk;
|
this.length = chunk.length;
|
||||||
self.length = chunk.length;
|
this.resume();
|
||||||
self.resume();
|
return this.ended;
|
||||||
return self.ended;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user