Fix error setting breakpoints. See #308

This commit is contained in:
Alexey Andreev 2018-01-08 14:44:43 +03:00
parent a24d628603
commit 2ae6c872db
2 changed files with 22 additions and 0 deletions

View File

@ -322,6 +322,20 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC
} }
breakpointLocationMap.remove(breakpoint.getLocation()); breakpointLocationMap.remove(breakpoint.getLocation());
breakpoints.remove(breakpoint); breakpoints.remove(breakpoint);
if (breakpoint.chromeId == null) {
synchronized (breakpoint.updateMonitor) {
while (breakpoint.updating.get()) {
try {
breakpoint.updateMonitor.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
}
}
if (breakpoint.chromeId != null) { if (breakpoint.chromeId != null) {
breakpointsByChromeId.remove(breakpoint.chromeId); breakpointsByChromeId.remove(breakpoint.chromeId);
if (logger.isInfoEnabled()) { if (logger.isInfoEnabled()) {
@ -371,10 +385,15 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC
} }
breakpoint.chromeId = null; breakpoint.chromeId = null;
} }
synchronized (breakpoint.updateMonitor) {
breakpoint.updating.set(false);
breakpoint.updateMonitor.notifyAll();
}
for (JavaScriptDebuggerListener listener : getListeners()) { for (JavaScriptDebuggerListener listener : getListeners()) {
listener.breakpointChanged(breakpoint); listener.breakpointChanged(breakpoint);
} }
}); });
breakpoint.updating.set(true);
sendMessage(message); sendMessage(message);
} }

View File

@ -15,6 +15,7 @@
*/ */
package org.teavm.chromerdp; package org.teavm.chromerdp;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.teavm.debugging.javascript.JavaScriptBreakpoint; import org.teavm.debugging.javascript.JavaScriptBreakpoint;
import org.teavm.debugging.javascript.JavaScriptLocation; import org.teavm.debugging.javascript.JavaScriptLocation;
@ -24,6 +25,8 @@ public class RDPBreakpoint implements JavaScriptBreakpoint {
ChromeRDPDebugger debugger; ChromeRDPDebugger debugger;
private JavaScriptLocation location; private JavaScriptLocation location;
AtomicInteger referenceCount = new AtomicInteger(); AtomicInteger referenceCount = new AtomicInteger();
final Object updateMonitor = new Object();
AtomicBoolean updating = new AtomicBoolean(true);
RDPBreakpoint(ChromeRDPDebugger debugger, JavaScriptLocation location) { RDPBreakpoint(ChromeRDPDebugger debugger, JavaScriptLocation location) {
this.debugger = debugger; this.debugger = debugger;