Skip to content

Commit 7ce39b8

Browse files
aduh95targos
authored andcommitted
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: #38464 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 3b0480d commit 7ce39b8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/common/index.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,28 @@ function _mustCallInner(fn, criteria = 1, field) {
387387

388388
mustCallChecks.push(context);
389389

390-
return function() {
390+
const _return = function() { // eslint-disable-line func-style
391391
context.actual++;
392392
return fn.apply(this, arguments);
393393
};
394+
// Function instances have own properties that may be relevant.
395+
// Let's replicate those properties to the returned function.
396+
// Refs: https://tc39.es/ecma262/#sec-function-instances
397+
Object.defineProperties(_return, {
398+
name: {
399+
value: fn.name,
400+
writable: false,
401+
enumerable: false,
402+
configurable: true,
403+
},
404+
length: {
405+
value: fn.length,
406+
writable: false,
407+
enumerable: false,
408+
configurable: true,
409+
},
410+
});
411+
return _return;
394412
}
395413

396414
function hasMultiLocalhost() {

0 commit comments

Comments
 (0)