Skip to content

Commit 52cbe89

Browse files
aduh95targos
authored andcommitted
net: refactor to use more primordials
PR-URL: #36303 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5daeac6 commit 52cbe89

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎lib/internal/net.js‎

Lines changed: 3 additions & 2 deletions
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
functionisIPv4(s){
31-
returnIPv4Reg.test(s);
32+
returnRegExpPrototypeTest(IPv4Reg,s);
3233
}
3334

3435
functionisIPv6(s){
35-
returnIPv6Reg.test(s);
36+
returnRegExpPrototypeTest(IPv6Reg,s);
3637
}
3738

3839
functionisIP(s){

‎lib/net.js‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@
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,
3136
ObjectDefineProperty,
3237
ObjectSetPrototypeOf,
38+
ReflectApply,
3339
Symbol,
3440
}=primordials;
3541

@@ -123,7 +129,7 @@ const DEFAULT_IPV6_ADDR = '::';
123129

124130
constisWindows=process.platform==='win32';
125131

126-
functionnoop(){}
132+
constnoop=FunctionPrototype;
127133

128134
functiongetFlags(ipv6Only){
129135
returnipv6Only===true ? TCPConstants.UV_TCP_IPV6ONLY : 0;
@@ -298,7 +304,7 @@ function Socket(options) {
298304
options.autoDestroy=false;
299305
// Handle strings directly.
300306
options.decodeStrings=false;
301-
stream.Duplex.call(this,options);
307+
ReflectApply(stream.Duplex,this,[options]);
302308

303309
// Default to *not* allowing half open sockets.
304310
this.allowHalfOpen=Boolean(allowHalfOpen);
@@ -588,7 +594,7 @@ Socket.prototype._read = function(n) {
588594

589595

590596
Socket.prototype.end=function(data,encoding,callback){
591-
stream.Duplex.prototype.end.call(this,data,encoding,callback);
597+
ReflectApply(stream.Duplex.prototype.end,this,[data,encoding,callback]);
592598
DTRACE_NET_STREAM_END(this);
593599
returnthis;
594600
};
@@ -604,7 +610,7 @@ Socket.prototype.pause = function() {
604610
this.destroy(errnoException(err,'read'));
605611
}
606612
}
607-
returnstream.Duplex.prototype.pause.call(this);
613+
returnFunctionPrototypeCall(stream.Duplex.prototype.pause,this);
608614
};
609615

610616

@@ -613,7 +619,7 @@ Socket.prototype.resume = function() {
613619
!this._handle.reading){
614620
tryReadStart(this);
615621
}
616-
returnstream.Duplex.prototype.resume.call(this);
622+
returnFunctionPrototypeCall(stream.Duplex.prototype.resume,this);
617623
};
618624

619625

@@ -622,7 +628,7 @@ Socket.prototype.read = function(n) {
622628
!this._handle.reading){
623629
tryReadStart(this);
624630
}
625-
returnstream.Duplex.prototype.read.call(this,n);
631+
returnReflectApply(stream.Duplex.prototype.read,this,[n]);
626632
};
627633

628634

@@ -1161,7 +1167,7 @@ function Server(options, connectionListener) {
11611167
if(!(thisinstanceofServer))
11621168
returnnewServer(options,connectionListener);
11631169

1164-
EventEmitter.call(this);
1170+
FunctionPrototypeCall(EventEmitter,this);
11651171

11661172
if(typeofoptions==='function'){
11671173
connectionListener=options;
@@ -1687,10 +1693,10 @@ ObjectDefineProperty(Socket.prototype, '_handle', {
16871693

16881694
Server.prototype._setupWorker=function(socketList){
16891695
this._usingWorkers=true;
1690-
this._workers.push(socketList);
1696+
ArrayPrototypePush(this._workers,socketList);
16911697
socketList.once('exit',(socketList)=>{
1692-
constindex=this._workers.indexOf(socketList);
1693-
this._workers.splice(index,1);
1698+
constindex=ArrayPrototypeIndexOf(this._workers,socketList);
1699+
ArrayPrototypeSplice(this._workers,index,1);
16941700
});
16951701
};
16961702

0 commit comments

Comments
 (0)