Skip to content

Commit fed4fec

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 6fa4834 commit fed4fec

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
@@ -371,10 +371,28 @@ function _mustCallInner(fn, criteria = 1, field) {
371371

372372
mustCallChecks.push(context);
373373

374-
return function() {
374+
const _return = function() { // eslint-disable-line func-style
375375
context.actual++;
376376
return fn.apply(this, arguments);
377377
};
378+
// Function instances have own properties that may be relevant.
379+
// Let's replicate those properties to the returned function.
380+
// Refs: https://tc39.es/ecma262/#sec-function-instances
381+
Object.defineProperties(_return, {
382+
name: {
383+
value: fn.name,
384+
writable: false,
385+
enumerable: false,
386+
configurable: true,
387+
},
388+
length: {
389+
value: fn.length,
390+
writable: false,
391+
enumerable: false,
392+
configurable: true,
393+
},
394+
});
395+
return _return;
378396
}
379397

380398
function hasMultiLocalhost() {

0 commit comments

Comments
 (0)