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 <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
aduh95 authored and targos committed May 3, 2021
1 parent 3b0480d commit 7ce39b8
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 @@ -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() {
Expand Down

0 comments on commit 7ce39b8

Please sign in to comment.