Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: use object destructuring #20959

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
15 changes: 6 additions & 9 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
let cluster;
let dns;

const errnoException = errors.errnoException;
const exceptionWithHostPort = errors.exceptionWithHostPort;
const { errnoException, exceptionWithHostPort } = errors;

const {
kTimeout,
Expand Down Expand Up @@ -244,7 +243,7 @@ function Socket(options) {

options.readable = options.readable || false;
options.writable = options.writable || false;
const allowHalfOpen = options.allowHalfOpen;
const { allowHalfOpen } = options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there consensus that changes like this are desirable? It's not obvious to me that destructuring is better (or worse) than the existing straightforward assignment in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm... It's just personal preference. I'm free to revert it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott I just guessed that you do not block this and it is author-ready. If that is not the case, please remove the label again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR Correct, not blocking. Thanks for checking.


// Prevent the "no-half-open enforcer" from being inherited from `Duplex`.
options.allowHalfOpen = true;
Expand All @@ -259,7 +258,7 @@ function Socket(options) {
this._handle = options.handle; // private
this[async_id_symbol] = getNewAsyncId(this._handle);
} else if (options.fd !== undefined) {
const fd = options.fd;
const { fd } = options;
this._handle = createHandle(fd, false);
this._handle.open(fd);
this[async_id_symbol] = this._handle.getAsyncId();
Expand Down Expand Up @@ -434,7 +433,7 @@ Socket.prototype._onTimeout = function() {
if (lastWriteQueueSize > 0 && handle) {
// `lastWriteQueueSize !== writeQueueSize` means there is
// an active write in progress, so we suppress the timeout.
const writeQueueSize = handle.writeQueueSize;
const { writeQueueSize } = handle;
if (lastWriteQueueSize !== writeQueueSize) {
this[kLastWriteQueueSize] = writeQueueSize;
this._unrefTimer();
Expand Down Expand Up @@ -956,7 +955,7 @@ Socket.prototype.connect = function(...args) {
this._sockname = null;
}

const path = options.path;
const { path } = options;
var pipe = !!path;
debug('pipe', pipe, path);

Expand Down Expand Up @@ -991,10 +990,8 @@ Socket.prototype.connect = function(...args) {


function lookupAndConnect(self, options) {
var { port, localAddress, localPort } = options;
var host = options.host || 'localhost';
var port = options.port;
var localAddress = options.localAddress;
var localPort = options.localPort;

if (localAddress && !isIP(localAddress)) {
throw new ERR_INVALID_IP_ADDRESS(localAddress);
Expand Down