test: fix common.mustCall length and name properties

Reassign `name` and `length` properties to the returned function to not
break code that relies on it.

PR-URL: https://github.com/nodejs/node/pull/38464
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Antoine du Hamel 2021-04-27 16:03:54 +02:00
parent 99099f9147
commit 5cee7cbe02

View File

@ -387,10 +387,28 @@ function _mustCallInner(fn, criteria = 1, field) {
mustCallChecks.push(context);
return function() {
const _return = function() { // eslint-disable-line func-style
context.actual++;
return fn.apply(this, arguments);
};
// Function instances have own properties that may be relevant.
// Let's replicate those properties to the returned function.
// Refs: https://tc39.es/ecma262/#sec-function-instances
Object.defineProperties(_return, {
name: {
value: fn.name,
writable: false,
enumerable: false,
configurable: true,
},
length: {
value: fn.length,
writable: false,
enumerable: false,
configurable: true,
},
});
return _return;
}
function hasMultiLocalhost() {