mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 21:46:48 +00:00
util: preserve length
of deprecated functions
PR-URL: https://github.com/nodejs/node/pull/57806 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
parent
795dd8eb79
commit
86f86a25e1
@ -142,6 +142,12 @@ function pendingDeprecate(fn, msg, code) {
|
||||
emitDeprecationWarning();
|
||||
return ReflectApply(fn, this, args);
|
||||
}
|
||||
|
||||
ObjectDefineProperty(deprecated, 'length', {
|
||||
__proto__: null,
|
||||
...ObjectGetOwnPropertyDescriptor(fn, 'length'),
|
||||
});
|
||||
|
||||
return deprecated;
|
||||
}
|
||||
|
||||
@ -180,6 +186,11 @@ function deprecate(fn, msg, code, useEmitSync) {
|
||||
deprecated.prototype = fn.prototype;
|
||||
}
|
||||
|
||||
ObjectDefineProperty(deprecated, 'length', {
|
||||
__proto__: null,
|
||||
...ObjectGetOwnPropertyDescriptor(fn, 'length'),
|
||||
});
|
||||
|
||||
return deprecated;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
@ -6,9 +7,27 @@ require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const util = require('util');
|
||||
const internalUtil = require('internal/util');
|
||||
|
||||
const expectedWarnings = new Map();
|
||||
|
||||
// Deprecated function length is preserved
|
||||
for (const fn of [
|
||||
function() {},
|
||||
function(a) {},
|
||||
function(a, b, c) {},
|
||||
function(...args) {},
|
||||
function(a, b, c, ...args) {},
|
||||
() => {},
|
||||
(a) => {},
|
||||
(a, b, c) => {},
|
||||
(...args) => {},
|
||||
(a, b, c, ...args) => {},
|
||||
]) {
|
||||
assert.strictEqual(util.deprecate(fn).length, fn.length);
|
||||
assert.strictEqual(internalUtil.pendingDeprecate(fn).length, fn.length);
|
||||
}
|
||||
|
||||
// Emits deprecation only once if same function is called.
|
||||
{
|
||||
const msg = 'fhqwhgads';
|
||||
|
Loading…
Reference in New Issue
Block a user