Browse Source

net: refactor self=this to arrow functions

Refactor unused self=this code to code without without this pattern
making it more consistent with the rest of our code.

PR-URL: https://github.com/nodejs/node/pull/5857
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Roman Klauke <romankl@users.noreply.github.com>
process-exit-stdio-flushing
Benjamin Gruenbaum 9 years ago
parent
commit
a15906c74b
  1. 30
      lib/net.js

30
lib/net.js

@ -444,9 +444,7 @@ Socket.prototype.destroySoon = function() {
Socket.prototype._destroy = function(exception, cb) { Socket.prototype._destroy = function(exception, cb) {
debug('destroy'); debug('destroy');
var self = this; function fireErrorCallbacks(self) {
function fireErrorCallbacks() {
if (cb) cb(exception); if (cb) cb(exception);
if (exception && !self._writableState.errorEmitted) { if (exception && !self._writableState.errorEmitted) {
process.nextTick(emitErrorNT, self, exception); process.nextTick(emitErrorNT, self, exception);
@ -456,11 +454,11 @@ Socket.prototype._destroy = function(exception, cb) {
if (this.destroyed) { if (this.destroyed) {
debug('already destroyed, fire error callbacks'); debug('already destroyed, fire error callbacks');
fireErrorCallbacks(); fireErrorCallbacks(this);
return; return;
} }
self._connecting = false; this._connecting = false;
this.readable = this.writable = false; this.readable = this.writable = false;
@ -472,9 +470,9 @@ Socket.prototype._destroy = function(exception, cb) {
if (this !== process.stderr) if (this !== process.stderr)
debug('close handle'); debug('close handle');
var isException = exception ? true : false; var isException = exception ? true : false;
this._handle.close(function() { this._handle.close(() => {
debug('emit close'); debug('emit close');
self.emit('close', isException); this.emit('close', isException);
}); });
this._handle.onread = noop; this._handle.onread = noop;
this._handle = null; this._handle = null;
@ -485,7 +483,7 @@ Socket.prototype._destroy = function(exception, cb) {
// to make it re-entrance safe in case Socket.prototype.destroy() // to make it re-entrance safe in case Socket.prototype.destroy()
// is called within callbacks // is called within callbacks
this.destroyed = true; this.destroyed = true;
fireErrorCallbacks(); fireErrorCallbacks(this);
if (this._server) { if (this._server) {
COUNTER_NET_SERVER_CONNECTION_CLOSE(this); COUNTER_NET_SERVER_CONNECTION_CLOSE(this);
@ -1080,17 +1078,15 @@ function Server(options, connectionListener) {
EventEmitter.call(this); EventEmitter.call(this);
var self = this;
if (typeof options === 'function') { if (typeof options === 'function') {
connectionListener = options; connectionListener = options;
options = {}; options = {};
self.on('connection', connectionListener); this.on('connection', connectionListener);
} else if (options == null || typeof options === 'object') { } else if (options == null || typeof options === 'object') {
options = options || {}; options = options || {};
if (typeof connectionListener === 'function') { if (typeof connectionListener === 'function') {
self.on('connection', connectionListener); this.on('connection', connectionListener);
} }
} else { } else {
throw new TypeError('options must be an object'); throw new TypeError('options must be an object');
@ -1099,16 +1095,16 @@ function Server(options, connectionListener) {
this._connections = 0; this._connections = 0;
Object.defineProperty(this, 'connections', { Object.defineProperty(this, 'connections', {
get: internalUtil.deprecate(function() { get: internalUtil.deprecate(() => {
if (self._usingSlaves) { if (this._usingSlaves) {
return null; return null;
} }
return self._connections; return this._connections;
}, 'Server.connections property is deprecated. ' + }, 'Server.connections property is deprecated. ' +
'Use Server.getConnections method instead.'), 'Use Server.getConnections method instead.'),
set: internalUtil.deprecate(function(val) { set: internalUtil.deprecate((val) => {
return (self._connections = val); return (this._connections = val);
}, 'Server.connections property is deprecated.'), }, 'Server.connections property is deprecated.'),
configurable: true, enumerable: false configurable: true, enumerable: false
}); });

Loading…
Cancel
Save