diff --git a/src/adapter/threads.ts b/src/adapter/threads.ts index 9df79f18c..ea631da20 100644 --- a/src/adapter/threads.ts +++ b/src/adapter/threads.ts @@ -884,11 +884,18 @@ export class Thread implements IVariableStoreLocationProvider { } async _executionContextsCleared() { + const removedContexts = [...this._executionContexts.values()]; + const pausedDetails = this._pausedDetails; this._executionContexts.clear(); await this.shutdown.shutdownContext(); - this._removeAllScripts(); + for (const context of removedContexts) { + context.remove(this._sourceContainer); + } this._breakpointManager.executionContextWasCleared(); - if (this._pausedDetails) this.onResumed(); + + if (pausedDetails && pausedDetails === this._pausedDetails) { + this.onResumed(); + } } _ensureDebuggerEnabledAndRefreshDebuggerId() {