Skip to content

Commit 52f3837

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 <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 4c54d81 commit 52f3837

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)