* Add a new IDisposable disposable to the collection.
(o: T)
| 133 | * Add a new {@link IDisposable disposable} to the collection. |
| 134 | */ |
| 135 | public add<T extends IDisposable>(o: T): T { |
| 136 | if (!o) { |
| 137 | return o; |
| 138 | } |
| 139 | if ((o as unknown as DisposableStore) === this) { |
| 140 | throw new Error('Cannot register a disposable on itself!'); |
| 141 | } |
| 142 | |
| 143 | if (this._isDisposed) { |
| 144 | if (!DisposableStore.DISABLE_DISPOSED_WARNING) { |
| 145 | console.warn( |
| 146 | new Error( |
| 147 | 'Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!' |
| 148 | ).stack |
| 149 | ); |
| 150 | } |
| 151 | } else { |
| 152 | this._toDispose.add(o); |
| 153 | } |
| 154 | |
| 155 | return o; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |