Skip to content

Commit

Permalink
util: move util._extend to eol
Browse files Browse the repository at this point in the history
PR-URL: #52744
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Ulises Gascón <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
marco-ippolito authored and nodejs-github-bot committed May 6, 2024
1 parent bbace72 commit ac97a53
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 93 deletions.
9 changes: 1 addition & 8 deletions benchmark/es/spread-assign.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const common = require('../common.js');
const util = require('util');

const bench = common.createBenchmark(main, {
method: ['spread', 'assign', '_extend'],
method: ['spread', 'assign'],
count: [5, 10, 20],
n: [1e6],
});
Expand All @@ -18,12 +17,6 @@ function main({ n, context, count, rest, method }) {
let obj;

switch (method) {
case '_extend':
bench.start();
for (let i = 0; i < n; i++)
obj = util._extend({}, src);
bench.end(n);
break;
case 'assign':
bench.start();
for (let i = 0; i < n; i++)
Expand Down
30 changes: 0 additions & 30 deletions benchmark/misc/util-extend-vs-object-assign.js

This file was deleted.

8 changes: 5 additions & 3 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,9 @@ requirements and complexity of your application.

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/52744
description: End-of-Life deprecation.
- version: v22.0.0
pr-url: https://github.com/nodejs/node/pull/50488
description: Runtime deprecation.
Expand All @@ -1374,9 +1377,9 @@ changes:
description: Documentation-only deprecation.
-->

Type: Runtime
Type: End-of-Life

The [`util._extend()`][] API is deprecated because it's an unmaintained
The `util._extend()` API has been removed because it's an unmaintained
legacy API that was exposed to user land by accident.
Please use `target = Object.assign(target, source)` instead.

Expand Down Expand Up @@ -3769,7 +3772,6 @@ is deprecated to better align with recommendations per [NIST SP 800-38D][].
[`url.format()`]: url.md#urlformaturlobject
[`url.parse()`]: url.md#urlparseurlstring-parsequerystring-slashesdenotehost
[`url.resolve()`]: url.md#urlresolvefrom-to
[`util._extend()`]: util.md#util_extendtarget-source
[`util.getSystemErrorName()`]: util.md#utilgetsystemerrornameerr
[`util.inspect()`]: util.md#utilinspectobject-options
[`util.inspect.custom`]: util.md#utilinspectcustom
Expand Down
19 changes: 0 additions & 19 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -2923,24 +2923,6 @@ util.types.isWeakSet(new WeakSet()); // Returns true
The following APIs are deprecated and should no longer be used. Existing
applications and modules should be updated to find alternative approaches.
### `util._extend(target, source)`
<!-- YAML
added: v0.7.5
deprecated: v6.0.0
-->
> Stability: 0 - Deprecated: Use [`Object.assign()`][] instead.
* `target` {Object}
* `source` {Object}
The `util._extend()` method was never intended to be used outside of internal
Node.js modules. The community found and used it anyway.
It is deprecated and should not be used in new code. JavaScript comes with very
similar built-in functionality through [`Object.assign()`][].
### `util.isArray(object)`
<!-- YAML
Expand Down Expand Up @@ -3410,7 +3392,6 @@ util.log('Timestamped message.');
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
[`MIMEparams`]: #class-utilmimeparams
[`Map`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
[`Object.assign()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
[`Object.freeze()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
[`Promise`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[`Proxy`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
Expand Down
23 changes: 0 additions & 23 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,6 @@ function inherits(ctor, superCtor) {
ObjectSetPrototypeOf(ctor.prototype, superCtor.prototype);
}

/**
* @deprecated since v6.0.0
* @template T
* @template S
* @param {T} target
* @param {S} source
* @returns {S extends null ? T : (T & S)}
*/
function _extend(target, source) {
// Don't do anything if source isn't an object
if (source === null || typeof source !== 'object') return target;

const keys = ObjectKeys(source);
let i = keys.length;
while (i--) {
target[keys[i]] = source[keys[i]];
}
return target;
}

const callbackifyOnRejected = (reason, cb) => {
// `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
// Because `null` is a special error value in callbacks which means "no error
Expand Down Expand Up @@ -425,9 +405,6 @@ function parseEnv(content) {
module.exports = {
_errnoException,
_exceptionWithHostPort,
_extend: deprecate(_extend,
'The `util._extend` API is deprecated. Please use Object.assign() instead.',
'DEP0060'),
callbackify,
debug: debuglog,
debuglog,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/tls-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exports.connect = function connect(options, callback) {
}).listen(0, function() {
server.server = this;

const optClient = util._extend({
const optClient = Object.assign({
port: this.address().port,
}, options.client);

Expand Down
9 changes: 0 additions & 9 deletions test/parallel/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ assert.strictEqual(util.isPrimitive(Symbol('symbol')), true);
assert.strictEqual(util.isBuffer('foo'), false);
assert.strictEqual(util.isBuffer(Buffer.from('foo')), true);

// _extend
assert.deepStrictEqual(util._extend({ a: 1 }), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, []), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, null), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, true), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, false), { a: 1 });
assert.deepStrictEqual(util._extend({ a: 1 }, { b: 2 }), { a: 1, b: 2 });
assert.deepStrictEqual(util._extend({ a: 1, b: 2 }, { b: 3 }), { a: 1, b: 3 });

// deprecated
assert.strictEqual(util.isBoolean(true), true);
assert.strictEqual(util.isBoolean(false), true);
Expand Down

0 comments on commit ac97a53

Please sign in to comment.