Skip to content

Commit

Permalink
test: fix common.mustCall length and name properties
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
aduh95 authored and targos committed Jun 11, 2021
1 parent 4c54d81 commit 52f3837
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,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() {
Expand Down

0 comments on commit 52f3837

Please sign in to comment.