mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Prevent dispose cycles
For #75304 Make sure we do not get into a loop of tyring to dispose of an object by checking `isDisposed` before calling into dispose again Also log if you try to register a disposeable on itself
This commit is contained in:
parent
af39a4d4fb
commit
9c14fecc87
|
@ -93,6 +93,10 @@ export class DisposableStore implements IDisposable {
|
||||||
* Any future disposables added to this object will be disposed of on `add`.
|
* Any future disposables added to this object will be disposed of on `add`.
|
||||||
*/
|
*/
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
|
if (this._isDisposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
markTracked(this);
|
markTracked(this);
|
||||||
this._isDisposed = true;
|
this._isDisposed = true;
|
||||||
this.clear();
|
this.clear();
|
||||||
|
@ -110,6 +114,9 @@ export class DisposableStore implements IDisposable {
|
||||||
if (!t) {
|
if (!t) {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
if ((t as any as DisposableStore) === this) {
|
||||||
|
throw new Error('Cannot register a disposable on itself!');
|
||||||
|
}
|
||||||
|
|
||||||
markTracked(t);
|
markTracked(t);
|
||||||
if (this._isDisposed) {
|
if (this._isDisposed) {
|
||||||
|
@ -140,6 +147,9 @@ export abstract class Disposable implements IDisposable {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _register<T extends IDisposable>(t: T): T {
|
protected _register<T extends IDisposable>(t: T): T {
|
||||||
|
if ((t as any as Disposable) === this) {
|
||||||
|
throw new Error('Cannot register a disposable on itself!');
|
||||||
|
}
|
||||||
return this._store.add(t);
|
return this._store.add(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue