Skip to content

Commit

Permalink
blackhole listeners for disposed emitters to avoid strange state
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jun 22, 2023
1 parent b1756f9 commit 3f2e273
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/vs/base/common/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,10 @@ class Stacktrace {
}
}

let id = 0;
class UniqueContainer<T> {
stack?: Stacktrace;
public id = id++;
constructor(public readonly value: T) { }
}
const compactionThreshold = 2;
Expand Down Expand Up @@ -977,6 +979,11 @@ export class Emitter<T> {
return Disposable.None;
}

if (this._disposed) {
// todo: should we warn if a listener is added to a disposed emitter? This happens often
return Disposable.None;
}

if (thisArgs) {
callback = callback.bind(thisArgs);
}
Expand Down Expand Up @@ -1040,6 +1047,9 @@ export class Emitter<T> {

const index = listeners.indexOf(listener);
if (index === -1) {
console.log('disposed?', this._disposed);
console.log('size?', this._size);
console.log('arr?', JSON.stringify(this._listeners));
throw new Error('Attempted to dispose unknown listener');
}

Expand Down

0 comments on commit 3f2e273

Please sign in to comment.