Permalink
Browse files

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
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>
  • Loading branch information...
starkwang authored and tniessen committed Oct 7, 2017
1 parent a3a1068 commit 212de3c5ec429a580d2e79ce3c2516b93b52b8f5
View
@@ -25,8 +25,8 @@ const net = require('net');
const util = require('util');
const EventEmitter = require('events');
const debug = util.debuglog('http');
const async_id_symbol = process.binding('async_wrap').async_id_symbol;
const nextTick = require('internal/process/next_tick').nextTick;
const { async_id_symbol } = process.binding('async_wrap');
const { nextTick } = require('internal/process/next_tick');
// New Agent code.
View
@@ -24,19 +24,21 @@
const util = require('util');
const net = require('net');
const url = require('url');
const HTTPParser = process.binding('http_parser').HTTPParser;
const { HTTPParser } = process.binding('http_parser');
const assert = require('assert').ok;
const common = require('_http_common');
const httpSocketSetup = common.httpSocketSetup;
const parsers = common.parsers;
const freeParser = common.freeParser;
const debug = common.debug;
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
const {
_checkIsHttpToken: checkIsHttpToken,
debug,
freeParser,
httpSocketSetup,
parsers
} = require('_http_common');
const { OutgoingMessage } = require('_http_outgoing');
const Agent = require('_http_agent');
const Buffer = require('buffer').Buffer;
const { Buffer } = require('buffer');
const { urlToOptions, searchParamsSymbol } = require('internal/url');
const outHeadersKey = require('internal/http').outHeadersKey;
const nextTick = require('internal/process/next_tick').nextTick;
const { outHeadersKey } = require('internal/http');
const { nextTick } = require('internal/process/next_tick');
const errors = require('internal/errors');
// The actual list of disallowed characters in regexp form is more like:
@@ -149,7 +151,7 @@ function ClientRequest(options, cb) {
}
if (methodIsString && method) {
if (!common._checkIsHttpToken(method)) {
if (!checkIsHttpToken(method)) {
throw new errors.TypeError('ERR_INVALID_HTTP_TOKEN', 'Method', method);
}
method = this.method = method.toUpperCase();
View
@@ -22,16 +22,17 @@
'use strict';
const binding = process.binding('http_parser');
const methods = binding.methods;
const HTTPParser = binding.HTTPParser;
const { methods, HTTPParser } = binding;
const FreeList = require('internal/freelist');
const ondrain = require('internal/http').ondrain;
const { ondrain } = require('internal/http');
const incoming = require('_http_incoming');
const emitDestroy = require('async_hooks').emitDestroy;
const IncomingMessage = incoming.IncomingMessage;
const readStart = incoming.readStart;
const readStop = incoming.readStop;
const { emitDestroy } = require('async_hooks');
const {
IncomingMessage,
readStart,
readStop
} = incoming;
const debug = require('util').debuglog('http');
View
@@ -26,18 +26,17 @@ const Stream = require('stream');
const util = require('util');
const internalUtil = require('internal/util');
const internalHttp = require('internal/http');
const Buffer = require('buffer').Buffer;
const { Buffer } = require('buffer');
const common = require('_http_common');
const checkIsHttpToken = common._checkIsHttpToken;
const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
const outHeadersKey = require('internal/http').outHeadersKey;
const async_id_symbol = process.binding('async_wrap').async_id_symbol;
const nextTick = require('internal/process/next_tick').nextTick;
const { outHeadersKey } = require('internal/http');
const { async_id_symbol } = process.binding('async_wrap');
const { nextTick } = require('internal/process/next_tick');
const errors = require('internal/errors');
const CRLF = common.CRLF;
const debug = common.debug;
const utcDate = internalHttp.utcDate;
const { CRLF, debug } = common;
const { utcDate } = internalHttp;
var RE_FIELDS =
/^(?:Connection|Transfer-Encoding|Content-Length|Date|Expect|Trailer|Upgrade)$/i;
View
@@ -23,17 +23,19 @@
const util = require('util');
const net = require('net');
const HTTPParser = process.binding('http_parser').HTTPParser;
const { HTTPParser } = process.binding('http_parser');
const assert = require('assert').ok;
const common = require('_http_common');
const parsers = common.parsers;
const freeParser = common.freeParser;
const debug = common.debug;
const CRLF = common.CRLF;
const continueExpression = common.continueExpression;
const chunkExpression = common.chunkExpression;
const httpSocketSetup = common.httpSocketSetup;
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
const {
parsers,
freeParser,
debug,
CRLF,
continueExpression,
chunkExpression,
httpSocketSetup,
_checkInvalidHeaderChar: checkInvalidHeaderChar
} = require('_http_common');
const { OutgoingMessage } = require('_http_outgoing');
const { outHeadersKey, ondrain } = require('internal/http');
const errors = require('internal/errors');
@@ -223,7 +225,7 @@ function writeHead(statusCode, reason, obj) {
headers = obj;
}
if (common._checkInvalidHeaderChar(this.statusMessage))
if (checkInvalidHeaderChar(this.statusMessage))
throw new errors.Error('ERR_INVALID_CHAR', 'statusMessage');
var statusLine = 'HTTP/1.1 ' + statusCode + ' ' + this.statusMessage + CRLF;
View
@@ -26,7 +26,7 @@ Readable.ReadableState = ReadableState;
const EE = require('events');
const Stream = require('stream');
const Buffer = require('buffer').Buffer;
const { Buffer } = require('buffer');
const util = require('util');
const debug = util.debuglog('stream');
const BufferList = require('internal/streams/BufferList');
View
@@ -2,8 +2,8 @@
const assert = require('assert');
const util = require('util');
const Socket = require('net').Socket;
const JSStream = process.binding('js_stream').JSStream;
const { Socket } = require('net');
const { JSStream } = process.binding('js_stream');
const uv = process.binding('uv');
const debug = util.debuglog('stream_wrap');
const errors = require('internal/errors');
View
@@ -31,7 +31,7 @@ Writable.WritableState = WritableState;
const util = require('util');
const internalUtil = require('internal/util');
const Stream = require('stream');
const Buffer = require('buffer').Buffer;
const { Buffer } = require('buffer');
const destroyImpl = require('internal/streams/destroy');
const errors = require('internal/errors');
View
@@ -26,8 +26,7 @@ const { isArrayBufferView } = require('internal/util/types');
const tls = require('tls');
const errors = require('internal/errors');
const SSL_OP_CIPHER_SERVER_PREFERENCE =
process.binding('constants').crypto.SSL_OP_CIPHER_SERVER_PREFERENCE;
const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;
// Lazily loaded
var crypto = null;
View
@@ -25,12 +25,12 @@ const internalUtil = require('internal/util');
internalUtil.assertCrypto();
const assert = require('assert');
const Buffer = require('buffer').Buffer;
const { Buffer } = require('buffer');
const common = require('_tls_common');
const Connection = process.binding('crypto').Connection;
const { Connection } = process.binding('crypto');
const EventEmitter = require('events');
const stream = require('stream');
const Timer = process.binding('timer_wrap').Timer;
const { Timer } = process.binding('timer_wrap');
const tls = require('tls');
const util = require('util');
View
@@ -29,13 +29,13 @@ const net = require('net');
const tls = require('tls');
const util = require('util');
const common = require('_tls_common');
const StreamWrap = require('_stream_wrap').StreamWrap;
const Buffer = require('buffer').Buffer;
const { StreamWrap } = require('_stream_wrap');
const { Buffer } = require('buffer');
const debug = util.debuglog('tls');
const Timer = process.binding('timer_wrap').Timer;
const { Timer } = process.binding('timer_wrap');
const tls_wrap = process.binding('tls_wrap');
const TCP = process.binding('tcp_wrap').TCP;
const Pipe = process.binding('pipe_wrap').Pipe;
const { TCP } = process.binding('tcp_wrap');
const { Pipe } = process.binding('pipe_wrap');
const errors = require('internal/errors');
const kConnectOptions = Symbol('connect-options');
const kDisableRenegotiation = Symbol('disable-renegotiation');
View
@@ -27,15 +27,17 @@ const { isUint8Array } = require('internal/util/types');
const { createPromise,
promiseResolve, promiseReject } = process.binding('util');
const debug = util.debuglog('child_process');
const Buffer = require('buffer').Buffer;
const Pipe = process.binding('pipe_wrap').Pipe;
const { Buffer } = require('buffer');
const { Pipe } = process.binding('pipe_wrap');
const { errname } = process.binding('uv');
const child_process = require('internal/child_process');
const {
_validateStdio,
setupChannel,
ChildProcess
} = child_process;
const _validateStdio = child_process._validateStdio;
const setupChannel = child_process.setupChannel;
const ChildProcess = exports.ChildProcess = child_process.ChildProcess;
exports.ChildProcess = ChildProcess;
function stdioStringToArray(option) {
switch (option) {
View
@@ -23,18 +23,17 @@
const assert = require('assert');
const errors = require('internal/errors');
const Buffer = require('buffer').Buffer;
const { Buffer } = require('buffer');
const dns = require('dns');
const util = require('util');
const { isUint8Array } = require('internal/util/types');
const EventEmitter = require('events');
const setInitTriggerId = require('async_hooks').setInitTriggerId;
const UV_UDP_REUSEADDR = process.binding('constants').os.UV_UDP_REUSEADDR;
const async_id_symbol = process.binding('async_wrap').async_id_symbol;
const nextTick = require('internal/process/next_tick').nextTick;
const { setInitTriggerId } = require('async_hooks');
const { UV_UDP_REUSEADDR } = process.binding('constants').os;
const { async_id_symbol } = process.binding('async_wrap');
const { nextTick } = require('internal/process/next_tick');
const UDP = process.binding('udp_wrap').UDP;
const SendWrap = process.binding('udp_wrap').SendWrap;
const { UDP, SendWrap } = process.binding('udp_wrap');
const BIND_STATE_UNBOUND = 0;
const BIND_STATE_BINDING = 1;
View
@@ -24,7 +24,7 @@
const util = require('util');
const cares = process.binding('cares_wrap');
const internalNet = require('internal/net');
const { isLegalPort } = require('internal/net');
const { customPromisifyArgs } = require('internal/util');
const errors = require('internal/errors');
const {
@@ -41,9 +41,6 @@ const {
isIP
} = cares;
const isLegalPort = internalNet.isLegalPort;
function errnoException(err, syscall, hostname) {
// FIXME(bnoordhuis) Remove this backwards compatibility nonsense and pass
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
View
@@ -28,7 +28,7 @@
const util = require('util');
const EventEmitter = require('events');
const inherits = util.inherits;
const { inherits } = util;
// communicate with events module, but don't require that
// module to have to load this one, since this module has
View
@@ -33,30 +33,28 @@ const { createPromise, promiseResolve } = process.binding('util');
const binding = process.binding('fs');
const fs = exports;
const Buffer = require('buffer').Buffer;
const { Buffer } = require('buffer');
const errors = require('internal/errors');
const Stream = require('stream').Stream;
const { Readable, Writable } = require('stream');
const EventEmitter = require('events');
const FSReqWrap = binding.FSReqWrap;
const FSEvent = process.binding('fs_event_wrap').FSEvent;
const { FSReqWrap } = binding;
const { FSEvent } = process.binding('fs_event_wrap');
const internalFS = require('internal/fs');
const internalURL = require('internal/url');
const { getPathFromURL } = require('internal/url');
const internalUtil = require('internal/util');
const assertEncoding = internalFS.assertEncoding;
const stringToFlags = internalFS.stringToFlags;
const getPathFromURL = internalURL.getPathFromURL;
const {
assertEncoding,
stringToFlags
} = internalFS;
Object.defineProperty(exports, 'constants', {
configurable: false,
enumerable: true,
value: constants
});
const Readable = Stream.Readable;
const Writable = Stream.Writable;
const kMinPoolSpace = 128;
const kMaxLength = require('buffer').kMaxLength;
const { kMaxLength } = require('buffer');
const isWindows = process.platform === 'win32';
View
@@ -22,14 +22,13 @@
'use strict';
const agent = require('_http_agent');
const client = require('_http_client');
const { ClientRequest } = require('_http_client');
const common = require('_http_common');
const incoming = require('_http_incoming');
const outgoing = require('_http_outgoing');
const server = require('_http_server');
const Server = server.Server;
const ClientRequest = client.ClientRequest;
const { Server } = server;
function createServer(requestListener) {
return new Server(requestListener);
View
@@ -27,7 +27,7 @@ const tls = require('tls');
const url = require('url');
const http = require('http');
const util = require('util');
const inherits = util.inherits;
const { inherits } = util;
const debug = util.debuglog('https');
const { urlToOptions, searchParamsSymbol } = require('internal/url');
const errors = require('internal/errors');
@@ -1,19 +1,19 @@
'use strict';
const errors = require('internal/errors');
const StringDecoder = require('string_decoder').StringDecoder;
const { StringDecoder } = require('string_decoder');
const EventEmitter = require('events');
const net = require('net');
const dgram = require('dgram');
const util = require('util');
const assert = require('assert');
const Process = process.binding('process_wrap').Process;
const WriteWrap = process.binding('stream_wrap').WriteWrap;
const Pipe = process.binding('pipe_wrap').Pipe;
const TTY = process.binding('tty_wrap').TTY;
const TCP = process.binding('tcp_wrap').TCP;
const UDP = process.binding('udp_wrap').UDP;
const { Process } = process.binding('process_wrap');
const { WriteWrap } = process.binding('stream_wrap');
const { Pipe } = process.binding('pipe_wrap');
const { TTY } = process.binding('tty_wrap');
const { TCP } = process.binding('tcp_wrap');
const { UDP } = process.binding('udp_wrap');
const SocketList = require('internal/socket_list');
const { convertToValidSignal } = require('internal/util');
const { isUint8Array } = require('internal/util/types');
@@ -30,8 +30,7 @@ const {
} = process.binding('uv');
const errnoException = util._errnoException;
const SocketListSend = SocketList.SocketListSend;
const SocketListReceive = SocketList.SocketListReceive;
const { SocketListSend, SocketListReceive } = SocketList;
const MAX_HANDLE_RETRANSMISSIONS = 3;
Oops, something went wrong.

0 comments on commit 212de3c

Please sign in to comment.