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

[v11.x] backport of #25105, #25149 and #25150 #25406

Closed
Closed
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function Agent(options) {
this.defaultPort = 80;
this.protocol = 'http:';

this.options = util._extend({}, options);
this.options = { ...options };

// Don't confuse net and make it think that we're connecting to a pipe
this.options.path = null;
Expand Down Expand Up @@ -146,8 +146,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
};
}

options = util._extend({}, options);
util._extend(options, this.options);
options = { ...options, ...this.options };
if (options.socketPath)
options.path = options.socketPath;

Expand Down Expand Up @@ -194,8 +193,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
};

Agent.prototype.createSocket = function createSocket(req, options, cb) {
options = util._extend({}, options);
util._extend(options, this.options);
options = { ...options, ...this.options };
if (options.socketPath)
options.path = options.socketPath;

Expand Down
6 changes: 3 additions & 3 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ function ClientRequest(input, options, cb) {

if (typeof options === 'function') {
cb = options;
options = null;
options = input || {};
} else {
options = Object.assign(input || {}, options);
}

options = util._extend(input || {}, options || {});

var agent = options.agent;
var defaultAgent = options._defaultAgent || Agent.globalAgent;
if (agent === false) {
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function Server(options, requestListener) {
requestListener = options;
options = {};
} else if (options == null || typeof options === 'object') {
options = util._extend({}, options);
options = { ...options };
}

this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
Expand Down
18 changes: 9 additions & 9 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,22 +1108,22 @@ function SNICallback(servername, callback) {
//
//
function normalizeConnectArgs(listArgs) {
var args = net._normalizeArgs(listArgs);
var options = args[0];
var cb = args[1];
const args = net._normalizeArgs(listArgs);
const options = args[0];
const cb = args[1];

// If args[0] was options, then normalize dealt with it.
// If args[0] is port, or args[0], args[1] is host, port, we need to
// find the options and merge them in, normalize's options has only
// the host/port/path args that it knows about, not the tls options.
// This means that options.host overrides a host arg.
if (listArgs[1] !== null && typeof listArgs[1] === 'object') {
util._extend(options, listArgs[1]);
Object.assign(options, listArgs[1]);
} else if (listArgs[2] !== null && typeof listArgs[2] === 'object') {
util._extend(options, listArgs[2]);
Object.assign(options, listArgs[2]);
}

return (cb) ? [options, cb] : [options];
return cb ? [options, cb] : [options];
}

function onConnectSecure() {
Expand Down Expand Up @@ -1204,14 +1204,14 @@ exports.connect = function connect(...args) {
'certificate verification.');
}

var defaults = {
options = {
rejectUnauthorized: !allowUnauthorized,
ciphers: tls.DEFAULT_CIPHERS,
checkServerIdentity: tls.checkServerIdentity,
minDHSize: 1024
minDHSize: 1024,
...options
};

options = util._extend(defaults, options || {});
if (!options.keepAlive)
options.singleUse = true;

Expand Down
26 changes: 24 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,32 @@ const {
kMaxLength,
kStringMaxLength
} = internalBinding('buffer');
const { isAnyArrayBuffer } = internalBinding('types');
const {
getOwnNonIndexProperties,
propertyFilter: {
ALL_PROPERTIES,
ONLY_ENUMERABLE
}
} = internalBinding('util');
const {
customInspectSymbol,
isInsideNodeModules,
normalizeEncoding,
kIsEncodingSymbol
} = require('internal/util');
const {
isAnyArrayBuffer,
isArrayBufferView,
isUint8Array
} = require('internal/util/types');
const {
pendingDeprecation
} = internalBinding('config');
const {
formatProperty,
kObjectType
} = require('internal/util/inspect');

const {
ERR_BUFFER_OUT_OF_BOUNDS,
ERR_OUT_OF_RANGE,
Expand Down Expand Up @@ -670,10 +682,20 @@ Buffer.prototype.equals = function equals(otherBuffer) {
Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) {
const max = exports.INSPECT_MAX_BYTES;
const actualMax = Math.min(max, this.length);
let str = this.hexSlice(0, actualMax).replace(/(.{2})/g, '$1 ').trim();
const remaining = this.length - max;
let str = this.hexSlice(0, actualMax).replace(/(.{2})/g, '$1 ').trim();
if (remaining > 0)
str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`;
// Inspect special properties as well, if possible.
if (ctx) {
const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE;
str += getOwnNonIndexProperties(this, filter).reduce((str, key) => {
// Using `formatProperty()` expects an indentationLvl to be set.
ctx.indentationLvl = 0;
str += `, ${formatProperty(ctx, this, recurseTimes, key, kObjectType)}`;
return str;
}, '');
}
return `<${this.constructor.name} ${str}>`;
};
Buffer.prototype.inspect = Buffer.prototype[customInspectSymbol];
Expand Down
35 changes: 19 additions & 16 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ exports.fork = function fork(modulePath /* , args, options */) {
throw new ERR_INVALID_ARG_VALUE(`arguments[${pos}]`, arguments[pos]);
}

options = util._extend({}, arguments[pos++]);
options = { ...arguments[pos++] };
}

// Prepare arguments for fork:
Expand Down Expand Up @@ -176,28 +176,20 @@ Object.defineProperty(exports.exec, util.promisify.custom, {
});

exports.execFile = function execFile(file /* , args, options, callback */) {
var args = [];
var callback;
var options = {
encoding: 'utf8',
timeout: 0,
maxBuffer: 200 * 1024,
killSignal: 'SIGTERM',
cwd: null,
env: null,
shell: false
};
let args = [];
let callback;
let options;

// Parse the optional positional parameters.
var pos = 1;
let pos = 1;
if (pos < arguments.length && Array.isArray(arguments[pos])) {
args = arguments[pos++];
} else if (pos < arguments.length && arguments[pos] == null) {
pos++;
}

if (pos < arguments.length && typeof arguments[pos] === 'object') {
util._extend(options, arguments[pos++]);
options = arguments[pos++];
} else if (pos < arguments.length && arguments[pos] == null) {
pos++;
}
Expand All @@ -210,6 +202,17 @@ exports.execFile = function execFile(file /* , args, options, callback */) {
throw new ERR_INVALID_ARG_VALUE('args', arguments[pos]);
}

options = {
encoding: 'utf8',
timeout: 0,
maxBuffer: 200 * 1024,
killSignal: 'SIGTERM',
cwd: null,
env: null,
shell: false,
...options
};

// Validate the timeout, if present.
validateTimeout(options.timeout);

Expand Down Expand Up @@ -580,15 +583,15 @@ function spawnSync(file, args, options) {
options.stdio = _validateStdio(options.stdio || 'pipe', true).stdio;

if (options.input) {
var stdin = options.stdio[0] = util._extend({}, options.stdio[0]);
var stdin = options.stdio[0] = { ...options.stdio[0] };
stdin.input = options.input;
}

// We may want to pass data in on any given fd, ensure it is a valid buffer
for (var i = 0; i < options.stdio.length; i++) {
var input = options.stdio[i] && options.stdio[i].input;
if (input != null) {
var pipe = options.stdio[i] = util._extend({}, options.stdio[i]);
var pipe = options.stdio[i] = { ...options.stdio[i] };
if (isArrayBufferView(input)) {
pipe.input = input;
} else if (typeof input === 'string') {
Expand Down
8 changes: 3 additions & 5 deletions lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,9 @@ Domain.prototype.run = function(fn) {
function intercepted(_this, self, cb, fnargs) {
if (fnargs[0] && fnargs[0] instanceof Error) {
var er = fnargs[0];
util._extend(er, {
domainBound: cb,
domainThrown: false,
domain: self
});
er.domainBound = cb;
er.domainThrown = false;
er.domain = self;
self.emit('error', er);
return;
}
Expand Down
18 changes: 8 additions & 10 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const {
O_SYMLINK
} = constants;

const { _extend } = require('util');
const pathModule = require('path');
const { isArrayBufferView } = require('internal/util/types');
const binding = process.binding('fs');
Expand Down Expand Up @@ -1294,21 +1293,20 @@ function watchFile(filename, options, listener) {
filename = pathModule.resolve(filename);
let stat;

const defaults = {
if (options === null || typeof options !== 'object') {
listener = options;
options = null;
}

options = {
// Poll interval in milliseconds. 5007 is what libev used to use. It's
// a little on the slow side but let's stick with it for now to keep
// behavioral changes to a minimum.
interval: 5007,
persistent: true
persistent: true,
...options
};

if (options !== null && typeof options === 'object') {
options = _extend(defaults, options);
} else {
listener = options;
options = defaults;
}

if (typeof listener !== 'function') {
throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
}
Expand Down
11 changes: 6 additions & 5 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Server(opts, requestListener) {
requestListener = opts;
opts = undefined;
}
opts = util._extend({}, opts);
opts = { ...opts };

if (!opts.ALPNProtocols) {
// http/1.0 is not defined as Protocol IDs in IANA
Expand Down Expand Up @@ -110,9 +110,10 @@ function createConnection(port, host, options) {
const session = this._getSession(options._agentKey);
if (session) {
debug('reuse session for %j', options._agentKey);
options = util._extend({
session: session
}, options);
options = {
session,
...options
};
}
}

Expand Down Expand Up @@ -291,7 +292,7 @@ function request(...args) {
}

if (args[0] && typeof args[0] !== 'function') {
options = util._extend(options, args.shift());
Object.assign(options, args.shift());
}

options._defaultAgent = module.exports.globalAgent;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
// TODO(addaleax): Turn into a full runtime deprecation.
const { pendingDeprecation } = internalBinding('config');
const utilBinding = internalBinding('util');
const types = internalBinding('types');
const types = NativeModule.require('internal/util/types');
for (const name of [
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator',
Expand Down
10 changes: 5 additions & 5 deletions lib/internal/cluster/child.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const assert = require('assert');
const util = require('util');
const path = require('path');
const EventEmitter = require('events');
const { owner_symbol } = require('internal/async_hooks').symbols;
Expand Down Expand Up @@ -71,11 +70,12 @@ cluster._getServer = function(obj, options, cb) {

indexes.set(indexesKey, index);

const message = util._extend({
const message = {
act: 'queryServer',
index,
data: null
}, options);
data: null,
...options
};

message.address = address;

Expand Down Expand Up @@ -151,7 +151,7 @@ function rr(message, indexesKey, cb) {

function getsockname(out) {
if (key)
util._extend(out, message.sockname);
Object.assign(out, message.sockname);

return 0;
}
Expand Down
Loading