diff --git a/src/java/me/topchetoeu/jscript/runtime/debug/DebugContext.java b/src/java/me/topchetoeu/jscript/runtime/debug/DebugContext.java index 2b38b84..c87a3b4 100644 --- a/src/java/me/topchetoeu/jscript/runtime/debug/DebugContext.java +++ b/src/java/me/topchetoeu/jscript/runtime/debug/DebugContext.java @@ -36,6 +36,10 @@ public class DebugContext { this.debugger = debugger; return true; } + public boolean detachDebugger(DebugHandler debugger) { + if (this.debugger != debugger) return false; + return detachDebugger(); + } public boolean detachDebugger() { this.debugger = null; return true; diff --git a/src/java/me/topchetoeu/jscript/utils/debug/SimpleDebugger.java b/src/java/me/topchetoeu/jscript/utils/debug/SimpleDebugger.java index 8f52225..6989ad1 100644 --- a/src/java/me/topchetoeu/jscript/utils/debug/SimpleDebugger.java +++ b/src/java/me/topchetoeu/jscript/utils/debug/SimpleDebugger.java @@ -205,6 +205,7 @@ public class SimpleDebugger implements Debugger { private ObjectValue emptyObject = new ObjectValue(); + private WeakHashMap contexts = new WeakHashMap<>(); private WeakHashMap mappings = new WeakHashMap<>(); private WeakHashMap> bpLocs = new WeakHashMap<>(); @@ -642,11 +643,10 @@ public class SimpleDebugger implements Debugger { execptionType = CatchType.NONE; state = State.RESUMED; - // idToBptCand.clear(); + mappings.clear(); + bpLocs.clear(); idToBreakpoint.clear(); - // locToBreakpoint.clear(); - // tmpBreakpts.clear(); filenameToId.clear(); idToSource.clear(); @@ -664,6 +664,9 @@ public class SimpleDebugger implements Debugger { stepOutFrame = currFrame = null; stepOutPtr = 0; + for (var ctx : contexts.keySet()) ctx.detachDebugger(this); + contexts.clear(); + updateNotifier.next(); } @@ -1041,6 +1044,7 @@ public class SimpleDebugger implements Debugger { public SimpleDebugger attach(DebugContext ctx) { ctx.attachDebugger(this); + contexts.put(ctx, ctx); return this; }