Skip to content

Commit 8611b8f

Browse files
aduh95danielleadams
authored andcommitted
net: refactor to use more primordials
PR-URL: #36303 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9ae59c8 commit 8611b8f

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/internal/net.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
RegExp,
5+
RegExpPrototypeTest,
56
Symbol,
67
} = primordials;
78

@@ -28,11 +29,11 @@ const IPv6Reg = new RegExp('^(' +
2829
')(%[0-9a-zA-Z-.:]{1,})?$');
2930

3031
function isIPv4(s) {
31-
return IPv4Reg.test(s);
32+
return RegExpPrototypeTest(IPv4Reg, s);
3233
}
3334

3435
function isIPv6(s) {
35-
return IPv6Reg.test(s);
36+
return RegExpPrototypeTest(IPv6Reg, s);
3637
}
3738

3839
function isIP(s) {

lib/net.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323

2424
const {
2525
ArrayIsArray,
26+
ArrayPrototypeIndexOf,
27+
ArrayPrototypePush,
28+
ArrayPrototypeSplice,
2629
Boolean,
2730
Error,
31+
FunctionPrototype,
32+
FunctionPrototypeCall,
2833
Number,
2934
NumberIsNaN,
3035
NumberParseInt,
@@ -127,7 +132,7 @@ const DEFAULT_IPV6_ADDR = '::';
127132

128133
const isWindows = process.platform === 'win32';
129134

130-
function noop() {}
135+
const noop = FunctionPrototype;
131136

132137
function getFlags(ipv6Only) {
133138
return ipv6Only === true ? TCPConstants.UV_TCP_IPV6ONLY : 0;
@@ -300,7 +305,7 @@ function Socket(options) {
300305
options.autoDestroy = true;
301306
// Handle strings directly.
302307
options.decodeStrings = false;
303-
stream.Duplex.call(this, options);
308+
ReflectApply(stream.Duplex, this, [options]);
304309

305310
if (options.handle) {
306311
this._handle = options.handle; // private
@@ -581,7 +586,7 @@ Socket.prototype._read = function(n) {
581586

582587

583588
Socket.prototype.end = function(data, encoding, callback) {
584-
stream.Duplex.prototype.end.call(this, data, encoding, callback);
589+
ReflectApply(stream.Duplex.prototype.end, this, [data, encoding, callback]);
585590
DTRACE_NET_STREAM_END(this);
586591
return this;
587592
};
@@ -597,7 +602,7 @@ Socket.prototype.pause = function() {
597602
this.destroy(errnoException(err, 'read'));
598603
}
599604
}
600-
return stream.Duplex.prototype.pause.call(this);
605+
return FunctionPrototypeCall(stream.Duplex.prototype.pause, this);
601606
};
602607

603608

@@ -606,7 +611,7 @@ Socket.prototype.resume = function() {
606611
!this._handle.reading) {
607612
tryReadStart(this);
608613
}
609-
return stream.Duplex.prototype.resume.call(this);
614+
return FunctionPrototypeCall(stream.Duplex.prototype.resume, this);
610615
};
611616

612617

@@ -615,7 +620,7 @@ Socket.prototype.read = function(n) {
615620
!this._handle.reading) {
616621
tryReadStart(this);
617622
}
618-
return stream.Duplex.prototype.read.call(this, n);
623+
return ReflectApply(stream.Duplex.prototype.read, this, [n]);
619624
};
620625

621626

@@ -1148,7 +1153,7 @@ function Server(options, connectionListener) {
11481153
if (!(this instanceof Server))
11491154
return new Server(options, connectionListener);
11501155

1151-
EventEmitter.call(this);
1156+
FunctionPrototypeCall(EventEmitter, this);
11521157

11531158
if (typeof options === 'function') {
11541159
connectionListener = options;
@@ -1659,10 +1664,10 @@ ObjectDefineProperty(Socket.prototype, '_handle', {
16591664

16601665
Server.prototype._setupWorker = function(socketList) {
16611666
this._usingWorkers = true;
1662-
this._workers.push(socketList);
1667+
ArrayPrototypePush(this._workers, socketList);
16631668
socketList.once('exit', (socketList) => {
1664-
const index = this._workers.indexOf(socketList);
1665-
this._workers.splice(index, 1);
1669+
const index = ArrayPrototypeIndexOf(this._workers, socketList);
1670+
ArrayPrototypeSplice(this._workers, index, 1);
16661671
});
16671672
};
16681673

0 commit comments

Comments
 (0)