Skip to content

Commit 0536afc

Browse files
tuanaiseofatso83
andauthored
Quality: Global mutable call id can grow unbounded across long-lived processes (#2691)
* refactor: global mutable call id can grow unbounded across l `callId` is module-scoped and incremented on every invocation. In long-running test runners or embedded usage, this can grow indefinitely and eventually lose integer precision semantics for strict ordering comparisons. Affected files: proxy-invoke.js Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com> * Wrap around for all values that are too high --------- Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com> Co-authored-by: Carl-Erik Kopseng <carlerik@gmail.com>
1 parent f4f7d93 commit 0536afc

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/sinon/proxy-invoke.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const ErrorConstructor = Error.prototype.constructor;
88
const { bind } = Function.prototype;
99

1010
let callId = 0;
11+
const maxSafeInteger = Number.MAX_SAFE_INTEGER;
1112

1213
/**
1314
* @callback SinonFunction
@@ -25,7 +26,8 @@ let callId = 0;
2526
*/
2627
export default function invoke(func, thisValue, args) {
2728
const matchings = this.matchingFakes(args);
28-
const currentCallId = callId++;
29+
const currentCallId = callId;
30+
callId = callId >= maxSafeInteger ? 0 : callId + 1;
2931
let exception, returnValue;
3032

3133
proxyCallUtil.incrementCallCount(this);

0 commit comments

Comments
 (0)