diff options
author | OneNail <onenail@yeah.net> | 2022-05-07 01:00:53 +0300 |
---|---|---|
committer | RafaelGSS <rafael.nunu@hotmail.com> | 2022-05-10 15:13:19 +0300 |
commit | 7cac7bb806d73aafba106fd300d1f4d5849f039a (patch) | |
tree | 5f00b56067ddb1d068a6047b97ef415579654a32 /lib | |
parent | 0eb32ed976296b5082c7c5e1e13f32e91cb23400 (diff) |
assert: fix CallTracker wraps the function causes the length to be lost
PR-URL: https://github.com/nodejs/node/pull/42909
Fixes: https://github.com/nodejs/node/issues/40484
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/assert/calltracker.js | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/internal/assert/calltracker.js b/lib/internal/assert/calltracker.js index 0fbdf70e5d8..f00f2e33271 100644 --- a/lib/internal/assert/calltracker.js +++ b/lib/internal/assert/calltracker.js @@ -4,6 +4,7 @@ const { ArrayPrototypePush, Error, FunctionPrototype, + Proxy, ReflectApply, SafeSet, } = primordials; @@ -46,20 +47,23 @@ class CallTracker { const callChecks = this.#callChecks; callChecks.add(context); - return function() { - context.actual++; - if (context.actual === context.exact) { - // Once function has reached its call count remove it from - // callChecks set to prevent memory leaks. - callChecks.delete(context); - } - // If function has been called more than expected times, add back into - // callchecks. - if (context.actual === context.exact + 1) { - callChecks.add(context); - } - return ReflectApply(fn, this, arguments); - }; + return new Proxy(fn, { + __proto__: null, + apply(fn, thisArg, argList) { + context.actual++; + if (context.actual === context.exact) { + // Once function has reached its call count remove it from + // callChecks set to prevent memory leaks. + callChecks.delete(context); + } + // If function has been called more than expected times, add back into + // callchecks. + if (context.actual === context.exact + 1) { + callChecks.add(context); + } + return ReflectApply(fn, thisArg, argList); + }, + }); } report() { |