Skip to content

Commit bc69c2e

Browse files
cjihrigkrydos
authored andcommitted
dgram: remove this aliases
This commit removes self = this style assignments from dgram. PR-URL: nodejs#11243 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2a95c63 commit bc69c2e

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

lib/dgram.js

+36-37
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,22 @@ function replaceHandle(self, newHandle) {
132132
}
133133

134134
Socket.prototype.bind = function(port_ /*, address, callback*/) {
135-
var self = this;
136135
let port = port_;
137136

138-
self._healthCheck();
137+
this._healthCheck();
139138

140139
if (this._bindState !== BIND_STATE_UNBOUND)
141140
throw new Error('Socket is already bound');
142141

143142
this._bindState = BIND_STATE_BINDING;
144143

145144
if (typeof arguments[arguments.length - 1] === 'function')
146-
self.once('listening', arguments[arguments.length - 1]);
145+
this.once('listening', arguments[arguments.length - 1]);
147146

148147
if (port instanceof UDP) {
149-
replaceHandle(self, port);
150-
startListening(self);
151-
return self;
148+
replaceHandle(this, port);
149+
startListening(this);
150+
return this;
152151
}
153152

154153
var address;
@@ -164,69 +163,68 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
164163
}
165164

166165
// defaulting address for bind to all interfaces
167-
if (!address && self._handle.lookup === lookup4) {
166+
if (!address && this._handle.lookup === lookup4) {
168167
address = '0.0.0.0';
169-
} else if (!address && self._handle.lookup === lookup6) {
168+
} else if (!address && this._handle.lookup === lookup6) {
170169
address = '::';
171170
}
172171

173172
// resolve address first
174-
self._handle.lookup(address, function(err, ip) {
173+
this._handle.lookup(address, (err, ip) => {
175174
if (err) {
176-
self._bindState = BIND_STATE_UNBOUND;
177-
self.emit('error', err);
175+
this._bindState = BIND_STATE_UNBOUND;
176+
this.emit('error', err);
178177
return;
179178
}
180179

181180
if (!cluster)
182181
cluster = require('cluster');
183182

184183
var flags = 0;
185-
if (self._reuseAddr)
184+
if (this._reuseAddr)
186185
flags |= UV_UDP_REUSEADDR;
187186

188187
if (cluster.isWorker && !exclusive) {
189-
function onHandle(err, handle) {
188+
const onHandle = (err, handle) => {
190189
if (err) {
191190
var ex = exceptionWithHostPort(err, 'bind', ip, port);
192-
self.emit('error', ex);
193-
self._bindState = BIND_STATE_UNBOUND;
191+
this.emit('error', ex);
192+
this._bindState = BIND_STATE_UNBOUND;
194193
return;
195194
}
196195

197-
if (!self._handle)
196+
if (!this._handle)
198197
// handle has been closed in the mean time.
199198
return handle.close();
200199

201-
replaceHandle(self, handle);
202-
startListening(self);
203-
}
204-
cluster._getServer(self, {
200+
replaceHandle(this, handle);
201+
startListening(this);
202+
};
203+
cluster._getServer(this, {
205204
address: ip,
206205
port: port,
207-
addressType: self.type,
206+
addressType: this.type,
208207
fd: -1,
209208
flags: flags
210209
}, onHandle);
211-
212210
} else {
213-
if (!self._handle)
211+
if (!this._handle)
214212
return; // handle has been closed in the mean time
215213

216-
const err = self._handle.bind(ip, port || 0, flags);
214+
const err = this._handle.bind(ip, port || 0, flags);
217215
if (err) {
218216
var ex = exceptionWithHostPort(err, 'bind', ip, port);
219-
self.emit('error', ex);
220-
self._bindState = BIND_STATE_UNBOUND;
217+
this.emit('error', ex);
218+
this._bindState = BIND_STATE_UNBOUND;
221219
// Todo: close?
222220
return;
223221
}
224222

225-
startListening(self);
223+
startListening(this);
226224
}
227225
});
228226

229-
return self;
227+
return this;
230228
};
231229

232230

@@ -326,7 +324,6 @@ Socket.prototype.send = function(buffer,
326324
port,
327325
address,
328326
callback) {
329-
const self = this;
330327
let list;
331328

332329
if (address || (port && typeof port !== 'function')) {
@@ -358,24 +355,26 @@ Socket.prototype.send = function(buffer,
358355
if (typeof callback !== 'function')
359356
callback = undefined;
360357

361-
self._healthCheck();
358+
this._healthCheck();
362359

363-
if (self._bindState === BIND_STATE_UNBOUND)
364-
self.bind({port: 0, exclusive: true}, null);
360+
if (this._bindState === BIND_STATE_UNBOUND)
361+
this.bind({port: 0, exclusive: true}, null);
365362

366363
if (list.length === 0)
367364
list.push(Buffer.alloc(0));
368365

369366
// If the socket hasn't been bound yet, push the outbound packet onto the
370367
// send queue and send after binding is complete.
371-
if (self._bindState !== BIND_STATE_BOUND) {
372-
enqueue(self, self.send.bind(self, list, port, address, callback));
368+
if (this._bindState !== BIND_STATE_BOUND) {
369+
enqueue(this, this.send.bind(this, list, port, address, callback));
373370
return;
374371
}
375372

376-
self._handle.lookup(address, function afterDns(ex, ip) {
377-
doSend(ex, self, ip, list, address, port, callback);
378-
});
373+
const afterDns = (ex, ip) => {
374+
doSend(ex, this, ip, list, address, port, callback);
375+
};
376+
377+
this._handle.lookup(address, afterDns);
379378
};
380379

381380

0 commit comments

Comments
 (0)