Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 96e8250

Browse filesBrowse files
starkwanggibfahn
authored andcommitted
lib: use destructuring for some constants
This change is to unify the declaration for constants into using destructuring on the top-level-module scope, reducing some redundant code. PR-URL: #16063 Backport-PR-URL: #16494 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent fdc072b commit 96e8250
Copy full SHA for 96e8250
Expand file treeCollapse file tree

34 files changed

+131
-134
lines changed
Open diff view settings
Collapse file

‎lib/_http_agent.js‎

Copy file name to clipboardExpand all lines: lib/_http_agent.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const net = require('net');
2525
const util = require('util');
2626
const EventEmitter = require('events');
2727
const debug = util.debuglog('http');
28-
const async_id_symbol = process.binding('async_wrap').async_id_symbol;
29-
const nextTick = require('internal/process/next_tick').nextTick;
28+
const { async_id_symbol } = process.binding('async_wrap');
29+
const { nextTick } = require('internal/process/next_tick');
3030

3131
// New Agent code.
3232

Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@
2424
const util = require('util');
2525
const net = require('net');
2626
const url = require('url');
27-
const HTTPParser = process.binding('http_parser').HTTPParser;
27+
const { HTTPParser } = process.binding('http_parser');
2828
const assert = require('assert').ok;
29-
const common = require('_http_common');
30-
const httpSocketSetup = common.httpSocketSetup;
31-
const parsers = common.parsers;
32-
const freeParser = common.freeParser;
33-
const debug = common.debug;
34-
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
29+
const {
30+
_checkIsHttpToken: checkIsHttpToken,
31+
debug,
32+
freeParser,
33+
httpSocketSetup,
34+
parsers
35+
} = require('_http_common');
36+
const { OutgoingMessage } = require('_http_outgoing');
3537
const Agent = require('_http_agent');
36-
const Buffer = require('buffer').Buffer;
38+
const { Buffer } = require('buffer');
3739
const { urlToOptions, searchParamsSymbol } = require('internal/url');
38-
const outHeadersKey = require('internal/http').outHeadersKey;
39-
const nextTick = require('internal/process/next_tick').nextTick;
40+
const { outHeadersKey } = require('internal/http');
41+
const { nextTick } = require('internal/process/next_tick');
4042

4143
// The actual list of disallowed characters in regexp form is more like:
4244
// /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/
@@ -149,7 +151,7 @@ function ClientRequest(options, cb) {
149151
}
150152

151153
if (methodIsString && method) {
152-
if (!common._checkIsHttpToken(method)) {
154+
if (!checkIsHttpToken(method)) {
153155
throw new TypeError('Method must be a valid HTTP token');
154156
}
155157
method = this.method = method.toUpperCase();
Collapse file

‎lib/_http_common.js‎

Copy file name to clipboardExpand all lines: lib/_http_common.js
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
'use strict';
2323

2424
const binding = process.binding('http_parser');
25-
const methods = binding.methods;
26-
const HTTPParser = binding.HTTPParser;
25+
const { methods, HTTPParser } = binding;
2726

2827
const FreeList = require('internal/freelist');
29-
const ondrain = require('internal/http').ondrain;
28+
const { ondrain } = require('internal/http');
3029
const incoming = require('_http_incoming');
31-
const emitDestroy = require('async_hooks').emitDestroy;
32-
const IncomingMessage = incoming.IncomingMessage;
33-
const readStart = incoming.readStart;
34-
const readStop = incoming.readStop;
30+
const { emitDestroy } = require('async_hooks');
31+
const {
32+
IncomingMessage,
33+
readStart,
34+
readStop
35+
} = incoming;
3536

3637
const debug = require('util').debuglog('http');
3738

Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@ const Stream = require('stream');
2626
const util = require('util');
2727
const internalUtil = require('internal/util');
2828
const internalHttp = require('internal/http');
29-
const Buffer = require('buffer').Buffer;
29+
const { Buffer } = require('buffer');
3030
const common = require('_http_common');
3131
const checkIsHttpToken = common._checkIsHttpToken;
3232
const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
33-
const outHeadersKey = require('internal/http').outHeadersKey;
34-
const async_id_symbol = process.binding('async_wrap').async_id_symbol;
35-
const nextTick = require('internal/process/next_tick').nextTick;
33+
const { outHeadersKey } = require('internal/http');
34+
const { async_id_symbol } = process.binding('async_wrap');
35+
const { nextTick } = require('internal/process/next_tick');
3636

37-
const CRLF = common.CRLF;
38-
const debug = common.debug;
39-
const utcDate = internalHttp.utcDate;
37+
const { CRLF, debug } = common;
38+
const { utcDate } = internalHttp;
4039

4140
var RE_FIELDS =
4241
/^(?:Connection|Transfer-Encoding|Content-Length|Date|Expect|Trailer|Upgrade)$/i;
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@
2323

2424
const util = require('util');
2525
const net = require('net');
26-
const HTTPParser = process.binding('http_parser').HTTPParser;
26+
const { HTTPParser } = process.binding('http_parser');
2727
const assert = require('assert').ok;
28-
const common = require('_http_common');
29-
const parsers = common.parsers;
30-
const freeParser = common.freeParser;
31-
const debug = common.debug;
32-
const CRLF = common.CRLF;
33-
const continueExpression = common.continueExpression;
34-
const chunkExpression = common.chunkExpression;
35-
const httpSocketSetup = common.httpSocketSetup;
36-
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
28+
const {
29+
parsers,
30+
freeParser,
31+
debug,
32+
CRLF,
33+
continueExpression,
34+
chunkExpression,
35+
httpSocketSetup,
36+
_checkInvalidHeaderChar: checkInvalidHeaderChar
37+
} = require('_http_common');
38+
const { OutgoingMessage } = require('_http_outgoing');
3739
const { outHeadersKey, ondrain } = require('internal/http');
3840

3941
const STATUS_CODES = {
@@ -222,7 +224,7 @@ function writeHead(statusCode, reason, obj) {
222224
headers = obj;
223225
}
224226

225-
if (common._checkInvalidHeaderChar(this.statusMessage))
227+
if (checkInvalidHeaderChar(this.statusMessage))
226228
throw new Error('Invalid character in statusMessage.');
227229

228230
var statusLine = 'HTTP/1.1 ' + statusCode + ' ' + this.statusMessage + CRLF;
Collapse file

‎lib/_stream_readable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_readable.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Readable.ReadableState = ReadableState;
2626

2727
const EE = require('events');
2828
const Stream = require('stream');
29-
const Buffer = require('buffer').Buffer;
29+
const { Buffer } = require('buffer');
3030
const util = require('util');
3131
const debug = util.debuglog('stream');
3232
const BufferList = require('internal/streams/BufferList');
Collapse file

‎lib/_stream_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_stream_wrap.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
const assert = require('assert');
44
const util = require('util');
5-
const Socket = require('net').Socket;
6-
const JSStream = process.binding('js_stream').JSStream;
75
// TODO(bmeurer): Change this back to const once hole checks are
86
// properly optimized away early in Ignition+TurboFan.
97
var Buffer = require('buffer').Buffer;
8+
const { Socket } = require('net');
9+
const { JSStream } = process.binding('js_stream');
1010
const uv = process.binding('uv');
1111
const debug = util.debuglog('stream_wrap');
1212

Collapse file

‎lib/_stream_writable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_writable.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Writable.WritableState = WritableState;
3131
const util = require('util');
3232
const internalUtil = require('internal/util');
3333
const Stream = require('stream');
34-
const Buffer = require('buffer').Buffer;
34+
const { Buffer } = require('buffer');
3535
const destroyImpl = require('internal/streams/destroy');
3636

3737
util.inherits(Writable, Stream);
Collapse file

‎lib/_tls_common.js‎

Copy file name to clipboardExpand all lines: lib/_tls_common.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424
const tls = require('tls');
2525

26-
const SSL_OP_CIPHER_SERVER_PREFERENCE =
27-
process.binding('constants').crypto.SSL_OP_CIPHER_SERVER_PREFERENCE;
26+
const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;
2827

2928
// Lazily loaded
3029
var crypto = null;
Collapse file

‎lib/_tls_legacy.js‎

Copy file name to clipboardExpand all lines: lib/_tls_legacy.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ const internalUtil = require('internal/util');
2525
internalUtil.assertCrypto();
2626

2727
const assert = require('assert');
28-
const Buffer = require('buffer').Buffer;
28+
const { Buffer } = require('buffer');
2929
const common = require('_tls_common');
30-
const Connection = process.binding('crypto').Connection;
30+
const { Connection } = process.binding('crypto');
3131
const EventEmitter = require('events');
3232
const stream = require('stream');
33-
const Timer = process.binding('timer_wrap').Timer;
33+
const { Timer } = process.binding('timer_wrap');
3434
const tls = require('tls');
3535
const util = require('util');
3636

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.