|
24 | 24 | const { |
25 | 25 | Array, |
26 | 26 | ArrayIsArray, |
| 27 | + ArrayPrototypePush, |
| 28 | + FunctionPrototypeBind, |
| 29 | + FunctionPrototypeCall, |
27 | 30 | ObjectDefineProperty, |
28 | 31 | ObjectSetPrototypeOf, |
| 32 | + ReflectApply, |
29 | 33 | } = primordials; |
30 | 34 |
|
31 | 35 | const errors = require('internal/errors'); |
@@ -87,7 +91,7 @@ const exceptionWithHostPort = errors.exceptionWithHostPort; |
87 | 91 |
|
88 | 92 |
|
89 | 93 | function Socket(type, listener) { |
90 | | - EventEmitter.call(this); |
| 94 | + FunctionPrototypeCall(EventEmitter, this); |
91 | 95 | let lookup; |
92 | 96 | let recvBufferSize; |
93 | 97 | let sendBufferSize; |
@@ -220,8 +224,8 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { |
220 | 224 | } |
221 | 225 |
|
222 | 226 | function onListening() { |
223 | | - removeListeners.call(this); |
224 | | - cb.call(this); |
| 227 | + FunctionPrototypeCall(removeListeners, this); |
| 228 | + FunctionPrototypeCall(cb, this); |
225 | 229 | } |
226 | 230 |
|
227 | 231 | this.on('error', removeListeners); |
@@ -369,11 +373,12 @@ Socket.prototype.connect = function(port, address, callback) { |
369 | 373 | this.bind({ port: 0, exclusive: true }, null); |
370 | 374 |
|
371 | 375 | if (state.bindState !== BIND_STATE_BOUND) { |
372 | | - enqueue(this, _connect.bind(this, port, address, callback)); |
| 376 | + enqueue(this, FunctionPrototypeBind(_connect, this, |
| 377 | + port, address, callback)); |
373 | 378 | return; |
374 | 379 | } |
375 | 380 |
|
376 | | - _connect.call(this, port, address, callback); |
| 381 | + ReflectApply(_connect, this, [port, address, callback]); |
377 | 382 | }; |
378 | 383 |
|
379 | 384 |
|
@@ -498,13 +503,13 @@ function enqueue(self, toEnqueue) { |
498 | 503 | self.once(EventEmitter.errorMonitor, onListenError); |
499 | 504 | self.once('listening', onListenSuccess); |
500 | 505 | } |
501 | | - state.queue.push(toEnqueue); |
| 506 | + ArrayPrototypePush(state.queue, toEnqueue); |
502 | 507 | } |
503 | 508 |
|
504 | 509 |
|
505 | 510 | function onListenSuccess() { |
506 | 511 | this.removeListener(EventEmitter.errorMonitor, onListenError); |
507 | | - clearQueue.call(this); |
| 512 | + FunctionPrototypeCall(clearQueue, this); |
508 | 513 | } |
509 | 514 |
|
510 | 515 |
|
@@ -625,12 +630,13 @@ Socket.prototype.send = function(buffer, |
625 | 630 | this.bind({ port: 0, exclusive: true }, null); |
626 | 631 |
|
627 | 632 | if (list.length === 0) |
628 | | - list.push(Buffer.alloc(0)); |
| 633 | + ArrayPrototypePush(list, Buffer.alloc(0)); |
629 | 634 |
|
630 | 635 | // If the socket hasn't been bound yet, push the outbound packet onto the |
631 | 636 | // send queue and send after binding is complete. |
632 | 637 | if (state.bindState !== BIND_STATE_BOUND) { |
633 | | - enqueue(this, this.send.bind(this, list, port, address, callback)); |
| 638 | + enqueue(this, FunctionPrototypeBind(this.send, this, |
| 639 | + list, port, address, callback)); |
634 | 640 | return; |
635 | 641 | } |
636 | 642 |
|
@@ -712,7 +718,7 @@ Socket.prototype.close = function(callback) { |
712 | 718 | this.on('close', callback); |
713 | 719 |
|
714 | 720 | if (queue !== undefined) { |
715 | | - queue.push(this.close.bind(this)); |
| 721 | + ArrayPrototypePush(queue, FunctionPrototypeBind(this.close, this)); |
716 | 722 | return this; |
717 | 723 | } |
718 | 724 |
|
|
0 commit comments