From 76aee848762385ea3b39d1c22042ec090a74c5b8 Mon Sep 17 00:00:00 2001 From: micheleriva Date: Sat, 9 Mar 2019 20:05:20 +0100 Subject: [PATCH 1/3] Fixes: https://github.com/nodejs/node/issues/26546 --- lib/_http_agent.js | 3 +-- lib/_http_common.js | 2 +- lib/_http_outgoing.js | 13 ++++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 6d8d598ddc4a..e23b7224f156 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -22,9 +22,8 @@ 'use strict'; const net = require('net'); -const util = require('util'); const EventEmitter = require('events'); -const debug = util.debuglog('http'); +const debug = require('internal/util/debuglog').debuglog('http'); const { async_id_symbol } = require('internal/async_hooks').symbols; // New Agent code. diff --git a/lib/_http_common.js b/lib/_http_common.js index 7ecef8b83d41..8894ae6fca27 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -36,7 +36,7 @@ const { readStop } = incoming; -const debug = require('util').debuglog('http'); +const debug = require('internal/util/debuglog').debuglog('http'); const kIncomingMessage = Symbol('IncomingMessage'); const kOnHeaders = HTTPParser.kOnHeaders | 0; diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 60ed6779c479..da1dbe0ad3c7 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -23,8 +23,7 @@ const assert = require('internal/assert'); const Stream = require('stream'); -const util = require('util'); -const internalUtil = require('internal/util'); +const deprecate = require('internal/util').deprecate const { outHeadersKey, utcDate } = require('internal/http'); const { Buffer } = require('buffer'); const common = require('_http_common'); @@ -109,10 +108,10 @@ Object.setPrototypeOf(OutgoingMessage, Stream); Object.defineProperty(OutgoingMessage.prototype, '_headers', { - get: util.deprecate(function() { + get: deprecate(function() { return this.getHeaders(); }, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066'), - set: util.deprecate(function(val) { + set: deprecate(function(val) { if (val == null) { this[outHeadersKey] = null; } else if (typeof val === 'object') { @@ -127,7 +126,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', { }); Object.defineProperty(OutgoingMessage.prototype, '_headerNames', { - get: util.deprecate(function() { + get: deprecate(function() { const headers = this[outHeadersKey]; if (headers !== null) { const out = Object.create(null); @@ -141,7 +140,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headerNames', { } return null; }, 'OutgoingMessage.prototype._headerNames is deprecated', 'DEP0066'), - set: util.deprecate(function(val) { + set: deprecate(function(val) { if (typeof val === 'object' && val !== null) { const headers = this[outHeadersKey]; if (!headers) @@ -822,7 +821,7 @@ OutgoingMessage.prototype.flushHeaders = function flushHeaders() { this._send(''); }; -OutgoingMessage.prototype.flush = internalUtil.deprecate(function() { +OutgoingMessage.prototype.flush = deprecate(function() { this.flushHeaders(); }, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.', 'DEP0001'); From c45991b324da40cf8d828754b3b5dc317dfc6a06 Mon Sep 17 00:00:00 2001 From: micheleriva Date: Sat, 9 Mar 2019 20:21:41 +0100 Subject: [PATCH 2/3] Fixes: https://github.com/nodejs/node/issues/26546 --- lib/_http_server.js | 2 +- lib/assert.js | 2 +- lib/child_process.js | 8 ++++---- lib/dgram.js | 28 ++++++++++++++-------------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index 7c2798cc9a06..47e66ccb5183 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -310,7 +310,7 @@ function Server(options, requestListener) { this.maxHeadersCount = null; this.headersTimeout = 40 * 1000; // 40 seconds } -util.inherits(Server, net.Server); +Object.setPrototypeOf(Server, net.Server); Server.prototype.setTimeout = function setTimeout(msecs, callback) { diff --git a/lib/assert.js b/lib/assert.js index 94e9406393bf..cca6ee1a0331 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -29,7 +29,7 @@ const { codes: { } } = require('internal/errors'); const AssertionError = require('internal/assert/assertion_error'); const { openSync, closeSync, readSync } = require('fs'); -const { inspect, types: { isPromise, isRegExp } } = require('util'); +const { inspect, types: { isPromise, isRegExp } } = require('internal/util/inspect').inspect; const { EOL } = require('internal/constants'); const { NativeModule } = require('internal/bootstrap/loaders'); diff --git a/lib/child_process.js b/lib/child_process.js index 8060412b3f07..371a58cd22ad 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -21,10 +21,10 @@ 'use strict'; -const util = require('util'); +const promisify = require('internal/util').promisify; const { convertToValidSignal, getSystemErrorName } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); -const debug = util.debuglog('child_process'); +const debug = require('intern/util/debuglog').debuglog('child_process'); const { Buffer } = require('buffer'); const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap'); const { @@ -168,7 +168,7 @@ const customPromiseExecFunction = (orig) => { }; }; -Object.defineProperty(exports.exec, util.promisify.custom, { +Object.defineProperty(exports.exec, promisify.custom, { enumerable: false, value: customPromiseExecFunction(exports.exec) }); @@ -389,7 +389,7 @@ exports.execFile = function execFile(file /* , args, options, callback */) { return child; }; -Object.defineProperty(exports.execFile, util.promisify.custom, { +Object.defineProperty(exports.execFile, promisify.custom, { enumerable: false, value: customPromiseExecFunction(exports.execFile) }); diff --git a/lib/dgram.js b/lib/dgram.js index 621f6f1e9af8..b695d2121b0e 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -45,7 +45,7 @@ const { validateNumber } = require('internal/validators'); const { Buffer } = require('buffer'); -const util = require('util'); +const deprecate = require('internal/util').deprecate; const { isUint8Array } = require('internal/util/types'); const EventEmitter = require('events'); const { @@ -729,61 +729,61 @@ Socket.prototype.getSendBufferSize = function() { // Deprecated private APIs. Object.defineProperty(Socket.prototype, '_handle', { - get: util.deprecate(function() { + get: deprecate(function() { return this[kStateSymbol].handle; }, 'Socket.prototype._handle is deprecated', 'DEP0112'), - set: util.deprecate(function(val) { + set: deprecate(function(val) { this[kStateSymbol].handle = val; }, 'Socket.prototype._handle is deprecated', 'DEP0112') }); Object.defineProperty(Socket.prototype, '_receiving', { - get: util.deprecate(function() { + get: deprecate(function() { return this[kStateSymbol].receiving; }, 'Socket.prototype._receiving is deprecated', 'DEP0112'), - set: util.deprecate(function(val) { + set: deprecate(function(val) { this[kStateSymbol].receiving = val; }, 'Socket.prototype._receiving is deprecated', 'DEP0112') }); Object.defineProperty(Socket.prototype, '_bindState', { - get: util.deprecate(function() { + get: deprecate(function() { return this[kStateSymbol].bindState; }, 'Socket.prototype._bindState is deprecated', 'DEP0112'), - set: util.deprecate(function(val) { + set: deprecate(function(val) { this[kStateSymbol].bindState = val; }, 'Socket.prototype._bindState is deprecated', 'DEP0112') }); Object.defineProperty(Socket.prototype, '_queue', { - get: util.deprecate(function() { + get: deprecate(function() { return this[kStateSymbol].queue; }, 'Socket.prototype._queue is deprecated', 'DEP0112'), - set: util.deprecate(function(val) { + set: deprecate(function(val) { this[kStateSymbol].queue = val; }, 'Socket.prototype._queue is deprecated', 'DEP0112') }); Object.defineProperty(Socket.prototype, '_reuseAddr', { - get: util.deprecate(function() { + get: deprecate(function() { return this[kStateSymbol].reuseAddr; }, 'Socket.prototype._reuseAddr is deprecated', 'DEP0112'), - set: util.deprecate(function(val) { + set: deprecate(function(val) { this[kStateSymbol].reuseAddr = val; }, 'Socket.prototype._reuseAddr is deprecated', 'DEP0112') }); -Socket.prototype._healthCheck = util.deprecate(function() { +Socket.prototype._healthCheck = deprecate(function() { healthCheck(this); }, 'Socket.prototype._healthCheck() is deprecated', 'DEP0112'); -Socket.prototype._stopReceiving = util.deprecate(function() { +Socket.prototype._stopReceiving = deprecate(function() { stopReceiving(this); }, 'Socket.prototype._stopReceiving() is deprecated', 'DEP0112'); @@ -797,7 +797,7 @@ Object.defineProperty(UDP.prototype, 'owner', { module.exports = { - _createSocketHandle: util.deprecate( + _createSocketHandle: deprecate( _createSocketHandle, 'dgram._createSocketHandle() is deprecated', 'DEP0112' From 9ff89d24b6f032a6b7f0e15fcc008441ebbcbecf Mon Sep 17 00:00:00 2001 From: micheleriva Date: Sat, 9 Mar 2019 20:35:42 +0100 Subject: [PATCH 3/3] Fixes: https://github.com/nodejs/node/issues/26546 --- lib/https.js | 6 ++---- lib/internal/assert/assertion_error.js | 2 +- lib/internal/child_process.js | 8 ++++---- lib/internal/console/constructor.js | 5 +++-- lib/internal/encoding.js | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/https.js b/lib/https.js index 041bd41edde5..138af0f5e18a 100644 --- a/lib/https.js +++ b/lib/https.js @@ -25,7 +25,6 @@ require('internal/util').assertCrypto(); const tls = require('tls'); const url = require('url'); -const util = require('util'); const { Agent: HttpAgent } = require('_http_agent'); const { Server: HttpServer, @@ -33,8 +32,7 @@ const { kServerResponse } = require('_http_server'); const { ClientRequest } = require('_http_client'); -const { inherits } = util; -const debug = util.debuglog('https'); +const debug = require('internal/util/debuglog').debuglog('https'); const { URL, urlToOptions, searchParamsSymbol } = require('internal/url'); const { IncomingMessage, ServerResponse } = require('http'); const { kIncomingMessage } = require('_http_common'); @@ -76,7 +74,7 @@ function Server(opts, requestListener) { this.maxHeadersCount = null; this.headersTimeout = 40 * 1000; // 40 seconds } -inherits(Server, tls.Server); +Object.setPrototypeOf(Server, tls.Server); Server.prototype.setTimeout = HttpServer.prototype.setTimeout; diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index a13a610da1a7..80eec6a0c768 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -1,6 +1,6 @@ 'use strict'; -const { inspect } = require('util'); +const inspect = require('internal/util/inspect').inspect; const { codes: { ERR_INVALID_ARG_TYPE } } = require('internal/errors'); diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 2583d5d36208..7d13506b20c6 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -18,7 +18,7 @@ const { validateString } = require('internal/validators'); const EventEmitter = require('events'); const net = require('net'); const dgram = require('dgram'); -const util = require('util'); +const inspect = require('internal/util/inspect').inspect; const assert = require('internal/assert'); const { Process } = internalBinding('process_wrap'); @@ -875,7 +875,7 @@ function _validateStdio(stdio, sync) { throw new ERR_INVALID_OPT_VALUE('stdio', stdio); } } else if (!Array.isArray(stdio)) { - throw new ERR_INVALID_OPT_VALUE('stdio', util.inspect(stdio)); + throw new ERR_INVALID_OPT_VALUE('stdio', inspect(stdio)); } // At least 3 stdio will be created @@ -955,12 +955,12 @@ function _validateStdio(stdio, sync) { } else if (isArrayBufferView(stdio) || typeof stdio === 'string') { if (!sync) { cleanup(); - throw new ERR_INVALID_SYNC_FORK_INPUT(util.inspect(stdio)); + throw new ERR_INVALID_SYNC_FORK_INPUT(inspect(stdio)); } } else { // Cleanup cleanup(); - throw new ERR_INVALID_OPT_VALUE('stdio', util.inspect(stdio)); + throw new ERR_INVALID_OPT_VALUE('stdio', inspect(stdio)); } return acc; diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 2fa812d9fe1b..6714a09cc1f1 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -16,6 +16,7 @@ const { const { previewEntries } = internalBinding('util'); const { Buffer: { isBuffer } } = require('buffer'); const util = require('util'); +const inspect = require('internal/util/inspect').inspect; const { isTypedArray, isSet, isMap, isSetIterator, isMapIterator, } = util.types; @@ -291,7 +292,7 @@ const consoleMethods = { dir(object, options) { - this[kWriteToConsole](kUseStdout, util.inspect(object, { + this[kWriteToConsole](kUseStdout, inspect(object, { customInspect: false, ...this[kGetInspectOptions](this._stdout), ...options @@ -415,7 +416,7 @@ const consoleMethods = { maxArrayLength: 3, ...this[kGetInspectOptions](this._stdout) }; - return util.inspect(v, opt); + return inspect(v, opt); }; const getIndexArray = (length) => ArrayFrom( { length }, (_, i) => inspect(i)); diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index 3fbbbe1a2fef..a9cc55f70546 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -327,7 +327,7 @@ class TextEncoder { }); obj.encoding = this.encoding; // Lazy to avoid circular dependency - return require('util').inspect(obj, opts); + return require('internal/util/inspect').inspect(obj, opts); } }