()
| 246 | } |
| 247 | |
| 248 | endScope(): void { |
| 249 | if (this.autoDisposeScope.length === 0) { |
| 250 | throw Error("tvm.endScope called when the stack is empty."); |
| 251 | } |
| 252 | // automatically dispose all the tracked values in the current scope. |
| 253 | const currScope = this.autoDisposeScope.pop() as Array<Disposable | undefined>; |
| 254 | for (let i = 0; i < currScope.length; ++i) { |
| 255 | const val = currScope[i]; |
| 256 | if (val !== undefined) { |
| 257 | val.dispose(); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Track object for dispose in current scope. |