Skip to content

Commit ae333d7

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

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
@@ -135,23 +135,22 @@ function replaceHandle(self, newHandle) {
135135
}
136136

137137
Socket.prototype.bind = function(port_ /*, address, callback*/) {
138-
var self = this;
139138
let port = port_;
140139

141-
self._healthCheck();
140+
this._healthCheck();
142141

143142
if (this._bindState != BIND_STATE_UNBOUND)
144143
throw new Error('Socket is already bound');
145144

146145
this._bindState = BIND_STATE_BINDING;
147146

148147
if (typeof arguments[arguments.length - 1] === 'function')
149-
self.once('listening', arguments[arguments.length - 1]);
148+
this.once('listening', arguments[arguments.length - 1]);
150149

151150
if (port instanceof UDP) {
152-
replaceHandle(self, port);
153-
startListening(self);
154-
return self;
151+
replaceHandle(this, port);
152+
startListening(this);
153+
return this;
155154
}
156155

157156
var address;
@@ -167,69 +166,68 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
167166
}
168167

169168
// defaulting address for bind to all interfaces
170-
if (!address && self._handle.lookup === lookup4) {
169+
if (!address && this._handle.lookup === lookup4) {
171170
address = '0.0.0.0';
172-
} else if (!address && self._handle.lookup === lookup6) {
171+
} else if (!address && this._handle.lookup === lookup6) {
173172
address = '::';
174173
}
175174

176175
// resolve address first
177-
self._handle.lookup(address, function(err, ip) {
176+
this._handle.lookup(address, (err, ip) => {
178177
if (err) {
179-
self._bindState = BIND_STATE_UNBOUND;
180-
self.emit('error', err);
178+
this._bindState = BIND_STATE_UNBOUND;
179+
this.emit('error', err);
181180
return;
182181
}
183182

184183
if (!cluster)
185184
cluster = require('cluster');
186185

187186
var flags = 0;
188-
if (self._reuseAddr)
187+
if (this._reuseAddr)
189188
flags |= UV_UDP_REUSEADDR;
190189

191190
if (cluster.isWorker && !exclusive) {
192-
function onHandle(err, handle) {
191+
const onHandle = (err, handle) => {
193192
if (err) {
194193
var ex = exceptionWithHostPort(err, 'bind', ip, port);
195-
self.emit('error', ex);
196-
self._bindState = BIND_STATE_UNBOUND;
194+
this.emit('error', ex);
195+
this._bindState = BIND_STATE_UNBOUND;
197196
return;
198197
}
199198

200-
if (!self._handle)
199+
if (!this._handle)
201200
// handle has been closed in the mean time.
202201
return handle.close();
203202

204-
replaceHandle(self, handle);
205-
startListening(self);
206-
}
207-
cluster._getServer(self, {
203+
replaceHandle(this, handle);
204+
startListening(this);
205+
};
206+
cluster._getServer(this, {
208207
address: ip,
209208
port: port,
210-
addressType: self.type,
209+
addressType: this.type,
211210
fd: -1,
212211
flags: flags
213212
}, onHandle);
214-
215213
} else {
216-
if (!self._handle)
214+
if (!this._handle)
217215
return; // handle has been closed in the mean time
218216

219-
const err = self._handle.bind(ip, port || 0, flags);
217+
const err = this._handle.bind(ip, port || 0, flags);
220218
if (err) {
221219
var ex = exceptionWithHostPort(err, 'bind', ip, port);
222-
self.emit('error', ex);
223-
self._bindState = BIND_STATE_UNBOUND;
220+
this.emit('error', ex);
221+
this._bindState = BIND_STATE_UNBOUND;
224222
// Todo: close?
225223
return;
226224
}
227225

228-
startListening(self);
226+
startListening(this);
229227
}
230228
});
231229

232-
return self;
230+
return this;
233231
};
234232

235233

@@ -315,7 +313,6 @@ Socket.prototype.send = function(buffer,
315313
port,
316314
address,
317315
callback) {
318-
const self = this;
319316
let list;
320317

321318
if (address || (port && typeof port !== 'function')) {
@@ -347,24 +344,26 @@ Socket.prototype.send = function(buffer,
347344
if (typeof callback !== 'function')
348345
callback = undefined;
349346

350-
self._healthCheck();
347+
this._healthCheck();
351348

352-
if (self._bindState == BIND_STATE_UNBOUND)
353-
self.bind({port: 0, exclusive: true}, null);
349+
if (this._bindState === BIND_STATE_UNBOUND)
350+
this.bind({port: 0, exclusive: true}, null);
354351

355352
if (list.length === 0)
356353
list.push(Buffer.alloc(0));
357354

358355
// If the socket hasn't been bound yet, push the outbound packet onto the
359356
// send queue and send after binding is complete.
360-
if (self._bindState != BIND_STATE_BOUND) {
361-
enqueue(self, self.send.bind(self, list, port, address, callback));
357+
if (this._bindState !== BIND_STATE_BOUND) {
358+
enqueue(this, this.send.bind(this, list, port, address, callback));
362359
return;
363360
}
364361

365-
self._handle.lookup(address, function afterDns(ex, ip) {
366-
doSend(ex, self, ip, list, address, port, callback);
367-
});
362+
const afterDns = (ex, ip) => {
363+
doSend(ex, this, ip, list, address, port, callback);
364+
};
365+
366+
this._handle.lookup(address, afterDns);
368367
};
369368

370369

0 commit comments

Comments
 (0)