aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2020-11-20 00:15:02 +0100
committerNode.js GitHub Bot <github-bot@iojs.org>2020-12-04 18:34:22 +0000
commite074bee7da4941dac9e688bbdb328e167589e0e7 (patch)
tree1538bf21be5b3030c1be08abdac8b4078a843ae3 /lib
parentd1e4d34afa1667e752795aeb5ca95700f5d9fd78 (diff)
downloadios-node-v8-e074bee7da4941dac9e688bbdb328e167589e0e7.tar.gz
ios-node-v8-e074bee7da4941dac9e688bbdb328e167589e0e7.tar.bz2
ios-node-v8-e074bee7da4941dac9e688bbdb328e167589e0e7.zip
dgram: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/36286 Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/dgram.js26
-rw-r--r--lib/internal/dgram.js5
2 files changed, 19 insertions, 12 deletions
diff --git a/lib/dgram.js b/lib/dgram.js
index 1c1b478161..7950184778 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -24,8 +24,12 @@
const {
Array,
ArrayIsArray,
+ ArrayPrototypePush,
+ FunctionPrototypeBind,
+ FunctionPrototypeCall,
ObjectDefineProperty,
ObjectSetPrototypeOf,
+ ReflectApply,
} = primordials;
const errors = require('internal/errors');
@@ -87,7 +91,7 @@ const exceptionWithHostPort = errors.exceptionWithHostPort;
function Socket(type, listener) {
- EventEmitter.call(this);
+ FunctionPrototypeCall(EventEmitter, this);
let lookup;
let recvBufferSize;
let sendBufferSize;
@@ -220,8 +224,8 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
}
function onListening() {
- removeListeners.call(this);
- cb.call(this);
+ FunctionPrototypeCall(removeListeners, this);
+ FunctionPrototypeCall(cb, this);
}
this.on('error', removeListeners);
@@ -369,11 +373,12 @@ Socket.prototype.connect = function(port, address, callback) {
this.bind({ port: 0, exclusive: true }, null);
if (state.bindState !== BIND_STATE_BOUND) {
- enqueue(this, _connect.bind(this, port, address, callback));
+ enqueue(this, FunctionPrototypeBind(_connect, this,
+ port, address, callback));
return;
}
- _connect.call(this, port, address, callback);
+ ReflectApply(_connect, this, [port, address, callback]);
};
@@ -498,13 +503,13 @@ function enqueue(self, toEnqueue) {
self.once(EventEmitter.errorMonitor, onListenError);
self.once('listening', onListenSuccess);
}
- state.queue.push(toEnqueue);
+ ArrayPrototypePush(state.queue, toEnqueue);
}
function onListenSuccess() {
this.removeListener(EventEmitter.errorMonitor, onListenError);
- clearQueue.call(this);
+ FunctionPrototypeCall(clearQueue, this);
}
@@ -625,12 +630,13 @@ Socket.prototype.send = function(buffer,
this.bind({ port: 0, exclusive: true }, null);
if (list.length === 0)
- list.push(Buffer.alloc(0));
+ ArrayPrototypePush(list, Buffer.alloc(0));
// If the socket hasn't been bound yet, push the outbound packet onto the
// send queue and send after binding is complete.
if (state.bindState !== BIND_STATE_BOUND) {
- enqueue(this, this.send.bind(this, list, port, address, callback));
+ enqueue(this, FunctionPrototypeBind(this.send, this,
+ list, port, address, callback));
return;
}
@@ -712,7 +718,7 @@ Socket.prototype.close = function(callback) {
this.on('close', callback);
if (queue !== undefined) {
- queue.push(this.close.bind(this));
+ ArrayPrototypePush(queue, FunctionPrototypeBind(this.close, this));
return this;
}
diff --git a/lib/internal/dgram.js b/lib/internal/dgram.js
index 8a8d9ba8c0..950a82392c 100644
--- a/lib/internal/dgram.js
+++ b/lib/internal/dgram.js
@@ -1,6 +1,7 @@
'use strict';
const {
+ FunctionPrototypeBind,
Symbol,
} = primordials;
@@ -37,14 +38,14 @@ function newHandle(type, lookup) {
if (type === 'udp4') {
const handle = new UDP();
- handle.lookup = lookup4.bind(handle, lookup);
+ handle.lookup = FunctionPrototypeBind(lookup4, handle, lookup);
return handle;
}
if (type === 'udp6') {
const handle = new UDP();
- handle.lookup = lookup6.bind(handle, lookup);
+ handle.lookup = FunctionPrototypeBind(lookup6, handle, lookup);
handle.bind = handle.bind6;
handle.connect = handle.connect6;
handle.send = handle.send6;