summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2020-11-18 00:19:12 +0100
committerJames M Snell <jasnell@gmail.com>2020-12-07 10:08:03 -0800
commit0869b829fa6be2934c5a2e7fe8eaeb2e89490a8f (patch)
tree7f8f1cec8fcec1edc258355a9625a3f7f9699718 /lib
parent5f1bf80b5e0f33040f108b7bc83e2e72e425727f (diff)
downloadios-node-v8-0869b829fa6be2934c5a2e7fe8eaeb2e89490a8f.tar.gz
ios-node-v8-0869b829fa6be2934c5a2e7fe8eaeb2e89490a8f.tar.bz2
ios-node-v8-0869b829fa6be2934c5a2e7fe8eaeb2e89490a8f.zip
net: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/36303 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/net.js5
-rw-r--r--lib/net.js25
2 files changed, 18 insertions, 12 deletions
diff --git a/lib/internal/net.js b/lib/internal/net.js
index 2df1d5d5f6..8ae3170228 100644
--- a/lib/internal/net.js
+++ b/lib/internal/net.js
@@ -2,6 +2,7 @@
const {
RegExp,
+ RegExpPrototypeTest,
Symbol,
} = primordials;
@@ -28,11 +29,11 @@ const IPv6Reg = new RegExp('^(' +
')(%[0-9a-zA-Z-.:]{1,})?$');
function isIPv4(s) {
- return IPv4Reg.test(s);
+ return RegExpPrototypeTest(IPv4Reg, s);
}
function isIPv6(s) {
- return IPv6Reg.test(s);
+ return RegExpPrototypeTest(IPv6Reg, s);
}
function isIP(s) {
diff --git a/lib/net.js b/lib/net.js
index 4b3b96c8cd..149e4df20f 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -23,8 +23,13 @@
const {
ArrayIsArray,
+ ArrayPrototypeIndexOf,
+ ArrayPrototypePush,
+ ArrayPrototypeSplice,
Boolean,
Error,
+ FunctionPrototype,
+ FunctionPrototypeCall,
Number,
NumberIsNaN,
NumberParseInt,
@@ -127,7 +132,7 @@ const DEFAULT_IPV6_ADDR = '::';
const isWindows = process.platform === 'win32';
-function noop() {}
+const noop = FunctionPrototype;
function getFlags(ipv6Only) {
return ipv6Only === true ? TCPConstants.UV_TCP_IPV6ONLY : 0;
@@ -300,7 +305,7 @@ function Socket(options) {
options.autoDestroy = true;
// Handle strings directly.
options.decodeStrings = false;
- stream.Duplex.call(this, options);
+ ReflectApply(stream.Duplex, this, [options]);
if (options.handle) {
this._handle = options.handle; // private
@@ -581,7 +586,7 @@ Socket.prototype._read = function(n) {
Socket.prototype.end = function(data, encoding, callback) {
- stream.Duplex.prototype.end.call(this, data, encoding, callback);
+ ReflectApply(stream.Duplex.prototype.end, this, [data, encoding, callback]);
DTRACE_NET_STREAM_END(this);
return this;
};
@@ -597,7 +602,7 @@ Socket.prototype.pause = function() {
this.destroy(errnoException(err, 'read'));
}
}
- return stream.Duplex.prototype.pause.call(this);
+ return FunctionPrototypeCall(stream.Duplex.prototype.pause, this);
};
@@ -606,7 +611,7 @@ Socket.prototype.resume = function() {
!this._handle.reading) {
tryReadStart(this);
}
- return stream.Duplex.prototype.resume.call(this);
+ return FunctionPrototypeCall(stream.Duplex.prototype.resume, this);
};
@@ -615,7 +620,7 @@ Socket.prototype.read = function(n) {
!this._handle.reading) {
tryReadStart(this);
}
- return stream.Duplex.prototype.read.call(this, n);
+ return ReflectApply(stream.Duplex.prototype.read, this, [n]);
};
@@ -1148,7 +1153,7 @@ function Server(options, connectionListener) {
if (!(this instanceof Server))
return new Server(options, connectionListener);
- EventEmitter.call(this);
+ FunctionPrototypeCall(EventEmitter, this);
if (typeof options === 'function') {
connectionListener = options;
@@ -1659,10 +1664,10 @@ ObjectDefineProperty(Socket.prototype, '_handle', {
Server.prototype._setupWorker = function(socketList) {
this._usingWorkers = true;
- this._workers.push(socketList);
+ ArrayPrototypePush(this._workers, socketList);
socketList.once('exit', (socketList) => {
- const index = this._workers.indexOf(socketList);
- this._workers.splice(index, 1);
+ const index = ArrayPrototypeIndexOf(this._workers, socketList);
+ ArrayPrototypeSplice(this._workers, index, 1);
});
};