1012
1013
check(stack: Stacktrace, listenerCount: number): undefined | (() => void) {
1015
>
const threshold = this.threshold;
1016
>
if (threshold <= 0 || listenerCount < threshold) {
1017
>
return undefined;
1018
>
}
1019
>
1020
>
if (!this._stacks) {
1021
>
this._stacks = new Map();
1022
>
}
1023
>
const count = (this._stacks.get(stack.value) || 0);
1024
>
this._stacks.set(stack.value, count + 1);
1025
>
this._warnCountdown -= 1;
1026
>
1027
>
if (this._warnCountdown <= 0) {
1028
>
// only warn on first exceed and then every time the limit
1029
>
// is exceeded by 50% again
1030
>
this._warnCountdown = threshold * 0.5;
1031
>
1032
>
const [topStack, topCount] = this.getMostFrequentStack()!;
1033
>
const emitterName = /^[0-9a-f]+$/i.test(this.name) ? undefined : this.name;
1034
>
const message = `[${this.name}] potential listener LEAK detected, having ${listenerCount} listeners already. MOST frequent listener (${topCount}):`;
1035
>
console.warn(message);
1036
>
console.warn(topStack);
1037
>
1038
>
const kind = topCount / listenerCount > 0.3 ? 'dominated' : 'popular';
1039
>
const error = new ListenerLeakError(kind, message, topStack, listenerCount, emitterName);
1040
>
this._errorHandler(error);
1041
>
}
1042
>
1043
>
return () => {
1044
>
const count = (this._stacks!.get(stack.value) || 0);
1045
>
this._stacks!.set(stack.value, count - 1);
1046
>
};
1047
>
}
1048
1049
getMostFrequentStack(): [string, number] | undefined {
1051
return undefined;
1052
}
1053
>
let topStack: [string, number] | undefined;
event.ts
1054
>
let topCount: number = 0;
1055
>
for (const [stack, count] of this._stacks) {
1056
>
if (!topStack || topCount < count) {
1057
>
topStack = [stack, count];
1058
>
topCount = count;
1059
>
}
1060
>
}
1061
>
return topStack;
1062
>
}
1063
}
1064