From 2ae6c872db4693e5793f303b08a2716e3215931e Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 8 Jan 2018 14:44:43 +0300 Subject: [PATCH] Fix error setting breakpoints. See #308 --- .../teavm/chromerdp/ChromeRDPDebugger.java | 19 +++++++++++++++++++ .../org/teavm/chromerdp/RDPBreakpoint.java | 3 +++ 2 files changed, 22 insertions(+) diff --git a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java index 7fca146a5..433d9ca5b 100644 --- a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java +++ b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java @@ -322,6 +322,20 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC } breakpointLocationMap.remove(breakpoint.getLocation()); 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) { breakpointsByChromeId.remove(breakpoint.chromeId); if (logger.isInfoEnabled()) { @@ -371,10 +385,15 @@ public class ChromeRDPDebugger implements JavaScriptDebugger, ChromeRDPExchangeC } breakpoint.chromeId = null; } + synchronized (breakpoint.updateMonitor) { + breakpoint.updating.set(false); + breakpoint.updateMonitor.notifyAll(); + } for (JavaScriptDebuggerListener listener : getListeners()) { listener.breakpointChanged(breakpoint); } }); + breakpoint.updating.set(true); sendMessage(message); } diff --git a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/RDPBreakpoint.java b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/RDPBreakpoint.java index bc58c2e2b..5987ce198 100644 --- a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/RDPBreakpoint.java +++ b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/RDPBreakpoint.java @@ -15,6 +15,7 @@ */ package org.teavm.chromerdp; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.teavm.debugging.javascript.JavaScriptBreakpoint; import org.teavm.debugging.javascript.JavaScriptLocation; @@ -24,6 +25,8 @@ public class RDPBreakpoint implements JavaScriptBreakpoint { ChromeRDPDebugger debugger; private JavaScriptLocation location; AtomicInteger referenceCount = new AtomicInteger(); + final Object updateMonitor = new Object(); + AtomicBoolean updating = new AtomicBoolean(true); RDPBreakpoint(ChromeRDPDebugger debugger, JavaScriptLocation location) { this.debugger = debugger;