Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
net: refactor to use more primordials
  • Loading branch information
aduh95 committed Nov 28, 2020
commit 01859db56336493f5c8232e1396c73544a75a9f3
5 changes: 3 additions & 2 deletions lib/internal/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
RegExp,
RegExpPrototypeTest,
Symbol,
} = primordials;

Expand All @@ -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) {
Expand Down
24 changes: 14 additions & 10 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@

const {
ArrayIsArray,
ArrayPrototypeIndexOf,
ArrayPrototypePush,
ArrayPrototypeSplice,
Boolean,
Error,
FunctionPrototype,
Number,
NumberIsNaN,
NumberParseInt,
Expand Down Expand Up @@ -127,7 +131,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;
Expand Down Expand Up @@ -300,7 +304,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
Expand Down Expand Up @@ -581,7 +585,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;
};
Expand All @@ -597,7 +601,7 @@ Socket.prototype.pause = function() {
this.destroy(errnoException(err, 'read'));
}
}
return stream.Duplex.prototype.pause.call(this);
return ReflectApply(stream.Duplex.prototype.pause, this, []);
};


Expand All @@ -606,7 +610,7 @@ Socket.prototype.resume = function() {
!this._handle.reading) {
tryReadStart(this);
}
return stream.Duplex.prototype.resume.call(this);
return ReflectApply(stream.Duplex.prototype.resume, this, []);
};


Expand All @@ -615,7 +619,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]);
};


Expand Down Expand Up @@ -1148,7 +1152,7 @@ function Server(options, connectionListener) {
if (!(this instanceof Server))
return new Server(options, connectionListener);

EventEmitter.call(this);
ReflectApply(EventEmitter, this, []);

if (typeof options === 'function') {
connectionListener = options;
Expand Down Expand Up @@ -1659,10 +1663,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);
});
};

Expand Down