Web Inspector: Remove duplication among ScriptDebugServer subclasses
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 00:43:58 +0000 (00:43 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 00:43:58 +0000 (00:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150860

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-11-03
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

ScriptDebugServer expects a list of listeners to dispatch events to.
However each of its subclasses had their own implementation of the
list because of different handling when the first was added or when
the last was removed. Extract common code into ScriptDebugServer
which simplifies things.

Subclasses now only implement a virtual methods "attachDebugger"
and "detachDebugger" which is the unique work done when the first
listener is added or last is removed.

* inspector/JSGlobalObjectScriptDebugServer.cpp:
(Inspector::JSGlobalObjectScriptDebugServer::attachDebugger):
(Inspector::JSGlobalObjectScriptDebugServer::detachDebugger):
(Inspector::JSGlobalObjectScriptDebugServer::addListener): Deleted.
(Inspector::JSGlobalObjectScriptDebugServer::removeListener): Deleted.
* inspector/JSGlobalObjectScriptDebugServer.h:
* inspector/ScriptDebugServer.cpp:
(Inspector::ScriptDebugServer::dispatchBreakpointActionLog):
(Inspector::ScriptDebugServer::dispatchBreakpointActionSound):
(Inspector::ScriptDebugServer::dispatchBreakpointActionProbe):
(Inspector::ScriptDebugServer::sourceParsed):
(Inspector::ScriptDebugServer::dispatchFunctionToListeners):
(Inspector::ScriptDebugServer::addListener):
(Inspector::ScriptDebugServer::removeListener):
* inspector/ScriptDebugServer.h:
* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::enable):
(Inspector::InspectorDebuggerAgent::disable):
* inspector/agents/InspectorDebuggerAgent.h:
* inspector/agents/JSGlobalObjectDebuggerAgent.cpp:
(Inspector::JSGlobalObjectDebuggerAgent::startListeningScriptDebugServer): Deleted.
(Inspector::JSGlobalObjectDebuggerAgent::stopListeningScriptDebugServer): Deleted.
* inspector/agents/JSGlobalObjectDebuggerAgent.h:

* inspector/ScriptDebugListener.h:
(Inspector::ScriptDebugListener::Script::Script):
Drive-by convert Script to a struct, it has public fields and is used as such.

Source/WebCore:

Refactoring covered by existing tests.

* bindings/js/WorkerScriptDebugServer.cpp:
(WebCore::WorkerScriptDebugServer::attachDebugger):
(WebCore::WorkerScriptDebugServer::detachDebugger):
(WebCore::WorkerScriptDebugServer::addListener): Deleted.
(WebCore::WorkerScriptDebugServer::removeListener): Deleted.
* bindings/js/WorkerScriptDebugServer.h:
* inspector/PageDebuggerAgent.cpp:
(WebCore::PageDebuggerAgent::startListeningScriptDebugServer): Deleted.
(WebCore::PageDebuggerAgent::stopListeningScriptDebugServer): Deleted.
* inspector/PageDebuggerAgent.h:
* inspector/PageScriptDebugServer.cpp:
(WebCore::PageScriptDebugServer::attachDebugger):
(WebCore::PageScriptDebugServer::detachDebugger):
(WebCore::PageScriptDebugServer::addListener): Deleted.
(WebCore::PageScriptDebugServer::removeListener): Deleted.
* inspector/PageScriptDebugServer.h:
* inspector/WorkerDebuggerAgent.cpp:
(WebCore::WorkerDebuggerAgent::startListeningScriptDebugServer): Deleted.
(WebCore::WorkerDebuggerAgent::stopListeningScriptDebugServer): Deleted.
* inspector/WorkerDebuggerAgent.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191997 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/JSGlobalObjectScriptDebugServer.cpp
Source/JavaScriptCore/inspector/JSGlobalObjectScriptDebugServer.h
Source/JavaScriptCore/inspector/ScriptDebugListener.h
Source/JavaScriptCore/inspector/ScriptDebugServer.cpp
Source/JavaScriptCore/inspector/ScriptDebugServer.h
Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp
Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.h
Source/JavaScriptCore/inspector/agents/JSGlobalObjectDebuggerAgent.cpp
Source/JavaScriptCore/inspector/agents/JSGlobalObjectDebuggerAgent.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/WorkerScriptDebugServer.cpp
Source/WebCore/bindings/js/WorkerScriptDebugServer.h
Source/WebCore/inspector/PageDebuggerAgent.cpp
Source/WebCore/inspector/PageDebuggerAgent.h
Source/WebCore/inspector/PageScriptDebugServer.cpp
Source/WebCore/inspector/PageScriptDebugServer.h
Source/WebCore/inspector/WorkerDebuggerAgent.cpp
Source/WebCore/inspector/WorkerDebuggerAgent.h

index 90af471..e172cd4 100644 (file)
@@ -1,3 +1,48 @@
+2015-11-03  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Remove duplication among ScriptDebugServer subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=150860
+
+        Reviewed by Timothy Hatcher.
+
+        ScriptDebugServer expects a list of listeners to dispatch events to.
+        However each of its subclasses had their own implementation of the
+        list because of different handling when the first was added or when
+        the last was removed. Extract common code into ScriptDebugServer
+        which simplifies things.
+
+        Subclasses now only implement a virtual methods "attachDebugger"
+        and "detachDebugger" which is the unique work done when the first
+        listener is added or last is removed.
+
+        * inspector/JSGlobalObjectScriptDebugServer.cpp:
+        (Inspector::JSGlobalObjectScriptDebugServer::attachDebugger):
+        (Inspector::JSGlobalObjectScriptDebugServer::detachDebugger):
+        (Inspector::JSGlobalObjectScriptDebugServer::addListener): Deleted.
+        (Inspector::JSGlobalObjectScriptDebugServer::removeListener): Deleted.
+        * inspector/JSGlobalObjectScriptDebugServer.h:
+        * inspector/ScriptDebugServer.cpp:
+        (Inspector::ScriptDebugServer::dispatchBreakpointActionLog):
+        (Inspector::ScriptDebugServer::dispatchBreakpointActionSound):
+        (Inspector::ScriptDebugServer::dispatchBreakpointActionProbe):
+        (Inspector::ScriptDebugServer::sourceParsed):
+        (Inspector::ScriptDebugServer::dispatchFunctionToListeners):
+        (Inspector::ScriptDebugServer::addListener):
+        (Inspector::ScriptDebugServer::removeListener):
+        * inspector/ScriptDebugServer.h:
+        * inspector/agents/InspectorDebuggerAgent.cpp:
+        (Inspector::InspectorDebuggerAgent::enable):
+        (Inspector::InspectorDebuggerAgent::disable):
+        * inspector/agents/InspectorDebuggerAgent.h:
+        * inspector/agents/JSGlobalObjectDebuggerAgent.cpp:
+        (Inspector::JSGlobalObjectDebuggerAgent::startListeningScriptDebugServer): Deleted.
+        (Inspector::JSGlobalObjectDebuggerAgent::stopListeningScriptDebugServer): Deleted.
+        * inspector/agents/JSGlobalObjectDebuggerAgent.h:
+
+        * inspector/ScriptDebugListener.h:
+        (Inspector::ScriptDebugListener::Script::Script):
+        Drive-by convert Script to a struct, it has public fields and is used as such.
+
 2015-11-03  Filip Pizlo  <fpizlo@apple.com>
 
         B3::LowerToAir should recognize Neg (i.e. Sub($0, value))
index 9b255bb..6d8ce20 100644 (file)
@@ -40,34 +40,17 @@ JSGlobalObjectScriptDebugServer::JSGlobalObjectScriptDebugServer(JSGlobalObject&
 {
 }
 
-void JSGlobalObjectScriptDebugServer::addListener(ScriptDebugListener* listener)
+void JSGlobalObjectScriptDebugServer::attachDebugger()
 {
-    if (!listener)
-        return;
-
-    bool wasEmpty = m_listeners.isEmpty();
-    m_listeners.add(listener);
-
-    // First listener. Attach the debugger to the JSGlobalObject.
-    if (wasEmpty) {
-        attach(&m_globalObject);
-        recompileAllJSFunctions();
-    }
+    attach(&m_globalObject);
+    recompileAllJSFunctions();
 }
 
-void JSGlobalObjectScriptDebugServer::removeListener(ScriptDebugListener* listener, bool isBeingDestroyed)
+void JSGlobalObjectScriptDebugServer::detachDebugger(bool isBeingDestroyed)
 {
-    if (!listener)
-        return;
-
-    m_listeners.remove(listener);
-
-    // Last listener. Detach the debugger from the JSGlobalObject.
-    if (m_listeners.isEmpty()) {
-        detach(&m_globalObject, isBeingDestroyed ? Debugger::GlobalObjectIsDestructing : Debugger::TerminatingDebuggingSession);
-        if (!isBeingDestroyed)
-            recompileAllJSFunctions();
-    }
+    detach(&m_globalObject, isBeingDestroyed ? Debugger::GlobalObjectIsDestructing : Debugger::TerminatingDebuggingSession);
+    if (!isBeingDestroyed)
+        recompileAllJSFunctions();
 }
 
 void JSGlobalObjectScriptDebugServer::runEventLoopWhilePaused()
@@ -81,4 +64,3 @@ void JSGlobalObjectScriptDebugServer::runEventLoopWhilePaused()
 }
 
 } // namespace Inspector
-
index 3cf6c72..d808aa5 100644 (file)
@@ -27,7 +27,6 @@
 #define JSGlobalObjectScriptDebugServer_h
 
 #include "ScriptDebugServer.h"
-#include <wtf/Forward.h>
 
 namespace Inspector {
 
@@ -37,13 +36,12 @@ public:
     JSGlobalObjectScriptDebugServer(JSC::JSGlobalObject&);
     virtual ~JSGlobalObjectScriptDebugServer() { }
 
-    void addListener(ScriptDebugListener*);
-    void removeListener(ScriptDebugListener*, bool isBeingDestroyed);
-
     JSC::JSGlobalObject& globalObject() const { return m_globalObject; }
 
 private:
-    virtual ListenerSet& getListeners() override { return m_listeners; }
+    virtual void attachDebugger() override;
+    virtual void detachDebugger(bool isBeingDestroyed) override;
+
     virtual void didPause(JSC::JSGlobalObject*) override { }
     virtual void didContinue(JSC::JSGlobalObject*) override { }
     virtual void runEventLoopWhilePaused() override;
@@ -54,7 +52,6 @@ private:
     // or some other async operation in a pure JSContext) we can ignore exceptions reported here.
     virtual void reportException(JSC::ExecState*, JSC::Exception*) const override { }
 
-    ListenerSet m_listeners;
     JSC::JSGlobalObject& m_globalObject;
 };
 
index dfd9e0a..43ff237 100644 (file)
@@ -31,7 +31,6 @@
 #define ScriptDebugListener_h
 
 #include "debugger/Debugger.h"
-#include <wtf/Forward.h>
 #include <wtf/text/WTFString.h>
 
 namespace Deprecated {
@@ -44,26 +43,16 @@ struct ScriptBreakpointAction;
 
 class ScriptDebugListener {
 public:
-    class Script {
-    public:
-        Script()
-            : startLine(0)
-            , startColumn(0)
-            , endLine(0)
-            , endColumn(0)
-            , isContentScript(false)
-        {
-        }
-
+    struct Script {
         String url;
         String source;
         String sourceURL;
         String sourceMappingURL;
-        int startLine;
-        int startColumn;
-        int endLine;
-        int endColumn;
-        bool isContentScript;
+        int startLine {0};
+        int startColumn {0};
+        int endLine {0};
+        int endColumn {0};
+        bool isContentScript {false};
     };
 
     virtual ~ScriptDebugListener() { }
index 93b88c8..4644630 100644 (file)
@@ -41,7 +41,6 @@
 #include "SourceProvider.h"
 #include <wtf/NeverDestroyed.h>
 #include <wtf/TemporaryChange.h>
-#include <wtf/text/WTFString.h>
 
 using namespace JSC;
 
@@ -144,14 +143,13 @@ void ScriptDebugServer::dispatchBreakpointActionLog(ExecState* exec, const Strin
     if (m_callingListeners)
         return;
 
-    ListenerSet& listeners = getListeners();
-    if (listeners.isEmpty())
+    if (m_listeners.isEmpty())
         return;
 
     TemporaryChange<bool> change(m_callingListeners, true);
 
     Vector<ScriptDebugListener*> listenersCopy;
-    copyToVector(listeners, listenersCopy);
+    copyToVector(m_listeners, listenersCopy);
     for (auto* listener : listenersCopy)
         listener->breakpointActionLog(exec, message);
 }
@@ -161,14 +159,13 @@ void ScriptDebugServer::dispatchBreakpointActionSound(ExecState*, int breakpoint
     if (m_callingListeners)
         return;
 
-    ListenerSet& listeners = getListeners();
-    if (listeners.isEmpty())
+    if (m_listeners.isEmpty())
         return;
 
     TemporaryChange<bool> change(m_callingListeners, true);
 
     Vector<ScriptDebugListener*> listenersCopy;
-    copyToVector(listeners, listenersCopy);
+    copyToVector(m_listeners, listenersCopy);
     for (auto* listener : listenersCopy)
         listener->breakpointActionSound(breakpointActionIdentifier);
 }
@@ -178,8 +175,7 @@ void ScriptDebugServer::dispatchBreakpointActionProbe(ExecState* exec, const Scr
     if (m_callingListeners)
         return;
 
-    ListenerSet& listeners = getListeners();
-    if (listeners.isEmpty())
+    if (m_listeners.isEmpty())
         return;
 
     TemporaryChange<bool> change(m_callingListeners, true);
@@ -187,7 +183,7 @@ void ScriptDebugServer::dispatchBreakpointActionProbe(ExecState* exec, const Scr
     unsigned sampleId = m_nextProbeSampleId++;
 
     Vector<ScriptDebugListener*> listenersCopy;
-    copyToVector(listeners, listenersCopy);
+    copyToVector(m_listeners, listenersCopy);
     for (auto* listener : listenersCopy)
         listener->breakpointActionProbe(exec, action, m_currentProbeBatchId, sampleId, sampleValue);
 }
@@ -249,17 +245,16 @@ void ScriptDebugServer::sourceParsed(ExecState* exec, SourceProvider* sourceProv
     if (m_callingListeners)
         return;
 
-    ListenerSet& listeners = getListeners();
-    if (listeners.isEmpty())
+    if (m_listeners.isEmpty())
         return;
 
     TemporaryChange<bool> change(m_callingListeners, true);
 
     bool isError = errorLine != -1;
     if (isError)
-        dispatchFailedToParseSource(listeners, sourceProvider, errorLine, errorMessage);
+        dispatchFailedToParseSource(m_listeners, sourceProvider, errorLine, errorMessage);
     else
-        dispatchDidParseSource(listeners, sourceProvider, isContentScript(exec));
+        dispatchDidParseSource(m_listeners, sourceProvider, isContentScript(exec));
 }
 
 void ScriptDebugServer::dispatchFunctionToListeners(JavaScriptExecutionCallback callback)
@@ -267,11 +262,12 @@ void ScriptDebugServer::dispatchFunctionToListeners(JavaScriptExecutionCallback
     if (m_callingListeners)
         return;
 
+    if (m_listeners.isEmpty())
+        return;
+
     TemporaryChange<bool> change(m_callingListeners, true);
 
-    ListenerSet& listeners = getListeners();
-    if (!listeners.isEmpty())
-        dispatchFunctionToListeners(listeners, callback);
+    dispatchFunctionToListeners(m_listeners, callback);
 }
 
 void ScriptDebugServer::dispatchFunctionToListeners(const ListenerSet& listeners, JavaScriptExecutionCallback callback)
@@ -333,6 +329,29 @@ const BreakpointActions& ScriptDebugServer::getActionsForBreakpoint(JSC::Breakpo
     return emptyActionVector;
 }
 
+void ScriptDebugServer::addListener(ScriptDebugListener* listener)
+{
+    ASSERT(listener);
+
+    bool wasEmpty = m_listeners.isEmpty();
+    m_listeners.add(listener);
+
+    // First listener. Attach the debugger.
+    if (wasEmpty)
+        attachDebugger();
+}
+
+void ScriptDebugServer::removeListener(ScriptDebugListener* listener, bool isBeingDestroyed)
+{
+    ASSERT(listener);
+
+    m_listeners.remove(listener);
+
+    // Last listener. Detach the debugger.
+    if (m_listeners.isEmpty())
+        detachDebugger(isBeingDestroyed);
+}
+
 Deprecated::ScriptValue ScriptDebugServer::exceptionOrCaughtValue(JSC::ExecState* state)
 {
     if (reasonForPause() == PausedForException)
index e9a99b7..e0670ff 100644 (file)
@@ -36,9 +36,6 @@
 #include "debugger/Debugger.h"
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/TextPosition.h>
 #include <wtf/text/WTFString.h>
 
 namespace JSC {
@@ -59,6 +56,9 @@ public:
 
     const BreakpointActions& getActionsForBreakpoint(JSC::BreakpointID);
 
+    void addListener(ScriptDebugListener*);
+    void removeListener(ScriptDebugListener*, bool isBeingDestroyed);
+
 protected:
     typedef HashSet<ScriptDebugListener*> ListenerSet;
     typedef void (ScriptDebugServer::*JavaScriptExecutionCallback)(ScriptDebugListener*);
@@ -66,7 +66,9 @@ protected:
     ScriptDebugServer(JSC::VM&, bool isInWorkerThread = false);
     ~ScriptDebugServer();
 
-    virtual ListenerSet& getListeners() = 0;
+    virtual void attachDebugger() = 0;
+    virtual void detachDebugger(bool isBeingDestroyed) = 0;
+
     virtual void didPause(JSC::JSGlobalObject*) = 0;
     virtual void didContinue(JSC::JSGlobalObject*) = 0;
     virtual void runEventLoopWhilePaused() = 0;
@@ -99,10 +101,11 @@ private:
 
     Deprecated::ScriptValue exceptionOrCaughtValue(JSC::ExecState*);
 
-    bool m_callingListeners {false};
-
     BreakpointIDToActionsMap m_breakpointIDToActions;
 
+    ListenerSet m_listeners;
+    bool m_callingListeners {false};
+
     unsigned m_nextProbeSampleId {1};
     unsigned m_currentProbeBatchId {0};
 };
index cb9f916..1c09152 100644 (file)
@@ -87,7 +87,7 @@ void InspectorDebuggerAgent::enable()
         return;
 
     scriptDebugServer().setBreakpointsActivated(true);
-    startListeningScriptDebugServer();
+    scriptDebugServer().addListener(this);
 
     if (m_listener)
         m_listener->debuggerWasEnabled();
@@ -100,7 +100,7 @@ void InspectorDebuggerAgent::disable(bool isBeingDestroyed)
     if (!m_enabled)
         return;
 
-    stopListeningScriptDebugServer(isBeingDestroyed);
+    scriptDebugServer().removeListener(this, isBeingDestroyed);
     clearInspectorBreakpointState();
 
     ASSERT(m_javaScriptBreakpoints.isEmpty());
index 5df0843..1b86c37 100644 (file)
@@ -116,8 +116,6 @@ protected:
     InjectedScriptManager& injectedScriptManager() const { return m_injectedScriptManager; }
     virtual InjectedScript injectedScriptForEval(ErrorString&, const int* executionContextId) = 0;
 
-    virtual void startListeningScriptDebugServer() = 0;
-    virtual void stopListeningScriptDebugServer(bool skipRecompile) = 0;
     virtual void muteConsole() = 0;
     virtual void unmuteConsole() = 0;
 
index f6912a6..6c14cfc 100644 (file)
@@ -45,16 +45,6 @@ JSGlobalObjectDebuggerAgent::JSGlobalObjectDebuggerAgent(JSAgentContext& context
 {
 }
 
-void JSGlobalObjectDebuggerAgent::startListeningScriptDebugServer()
-{
-    scriptDebugServer().addListener(this);
-}
-
-void JSGlobalObjectDebuggerAgent::stopListeningScriptDebugServer(bool isBeingDestroyed)
-{
-    scriptDebugServer().removeListener(this, isBeingDestroyed);
-}
-
 InjectedScript JSGlobalObjectDebuggerAgent::injectedScriptForEval(ErrorString& error, const int* executionContextId)
 {
     if (executionContextId) {
index 1dd4a20..f105e95 100644 (file)
@@ -42,8 +42,6 @@ public:
 
     virtual JSGlobalObjectScriptDebugServer& scriptDebugServer() override { return m_scriptDebugServer; }
 
-    virtual void startListeningScriptDebugServer() override;
-    virtual void stopListeningScriptDebugServer(bool isBeingDestroyed) override;
     virtual InjectedScript injectedScriptForEval(ErrorString&, const int* executionContextId) override;
 
     virtual void breakpointActionLog(JSC::ExecState*, const String&) override;
index dd93eb0..dd61009 100644 (file)
@@ -1,3 +1,33 @@
+2015-11-03  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Remove duplication among ScriptDebugServer subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=150860
+
+        Reviewed by Timothy Hatcher.
+
+        Refactoring covered by existing tests.
+
+        * bindings/js/WorkerScriptDebugServer.cpp:
+        (WebCore::WorkerScriptDebugServer::attachDebugger):
+        (WebCore::WorkerScriptDebugServer::detachDebugger):
+        (WebCore::WorkerScriptDebugServer::addListener): Deleted.
+        (WebCore::WorkerScriptDebugServer::removeListener): Deleted.
+        * bindings/js/WorkerScriptDebugServer.h:
+        * inspector/PageDebuggerAgent.cpp:
+        (WebCore::PageDebuggerAgent::startListeningScriptDebugServer): Deleted.
+        (WebCore::PageDebuggerAgent::stopListeningScriptDebugServer): Deleted.
+        * inspector/PageDebuggerAgent.h:
+        * inspector/PageScriptDebugServer.cpp:
+        (WebCore::PageScriptDebugServer::attachDebugger):
+        (WebCore::PageScriptDebugServer::detachDebugger):
+        (WebCore::PageScriptDebugServer::addListener): Deleted.
+        (WebCore::PageScriptDebugServer::removeListener): Deleted.
+        * inspector/PageScriptDebugServer.h:
+        * inspector/WorkerDebuggerAgent.cpp:
+        (WebCore::WorkerDebuggerAgent::startListeningScriptDebugServer): Deleted.
+        (WebCore::WorkerDebuggerAgent::stopListeningScriptDebugServer): Deleted.
+        * inspector/WorkerDebuggerAgent.h:
+
 2015-11-03  Jiewen Tan  <jiewen_tan@apple.com>
 
         Null dereference loading Blink layout test scrollbars/custom-scrollbar-appearance-property.html
index ef59c40..ea859a9 100644 (file)
@@ -51,33 +51,18 @@ WorkerScriptDebugServer::WorkerScriptDebugServer(WorkerGlobalScope& context, con
 {
 }
 
-void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener)
+void WorkerScriptDebugServer::attachDebugger()
 {
-    if (!listener)
-        return;
-
-    bool wasEmpty = m_listeners.isEmpty();
-    m_listeners.add(listener);
-
-    if (wasEmpty) {
-        m_workerGlobalScope.script()->attachDebugger(this);
-        recompileAllJSFunctions();
-    }
+    m_workerGlobalScope.script()->attachDebugger(this);
+    recompileAllJSFunctions();
 }
 
-void WorkerScriptDebugServer::removeListener(ScriptDebugListener* listener, bool skipRecompile)
+void WorkerScriptDebugServer::detachDebugger(bool skipRecompile)
 {
-    if (!listener)
-        return;
-
-    m_listeners.remove(listener);
-
-    if (m_listeners.isEmpty()) {
-        if (m_workerGlobalScope.script())
-            m_workerGlobalScope.script()->detachDebugger(this);
-        if (!skipRecompile)
-            recompileAllJSFunctions();
-    }
+    if (m_workerGlobalScope.script())
+        m_workerGlobalScope.script()->detachDebugger(this);
+    if (!skipRecompile)
+        recompileAllJSFunctions();
 }
 
 void WorkerScriptDebugServer::recompileAllJSFunctions()
index c9a01a7..a3198ab 100644 (file)
@@ -52,13 +52,12 @@ public:
 
     virtual void recompileAllJSFunctions() override;
 
-    void addListener(Inspector::ScriptDebugListener*);
-    void removeListener(Inspector::ScriptDebugListener*, bool skipRecompile);
-
     void interruptAndRunTask(std::unique_ptr<Task>);
 
 private:
-    virtual ListenerSet& getListeners() override { return m_listeners; }
+    virtual void attachDebugger() override;
+    virtual void detachDebugger(bool isBeingDestroyed) override;
+
     virtual void didPause(JSC::JSGlobalObject*) override { }
     virtual void didContinue(JSC::JSGlobalObject*) override { }
     virtual void runEventLoopWhilePaused() override;
@@ -66,7 +65,6 @@ private:
     virtual void reportException(JSC::ExecState*, JSC::Exception*) const override;
 
     WorkerGlobalScope& m_workerGlobalScope;
-    ListenerSet m_listeners;
     String m_debuggerTaskMode;
 };
 
index 50f67b5..193489e 100644 (file)
@@ -93,16 +93,6 @@ String PageDebuggerAgent::sourceMapURLForScript(const Script& script)
     return InspectorDebuggerAgent::sourceMapURLForScript(script);
 }
 
-void PageDebuggerAgent::startListeningScriptDebugServer()
-{
-    scriptDebugServer().addListener(this);
-}
-
-void PageDebuggerAgent::stopListeningScriptDebugServer(bool isBeingDestroyed)
-{
-    scriptDebugServer().removeListener(this, isBeingDestroyed);
-}
-
 PageScriptDebugServer& PageDebuggerAgent::scriptDebugServer()
 {
     return m_scriptDebugServer;
index 2d38c33..7816730 100644 (file)
@@ -64,8 +64,6 @@ protected:
     virtual String sourceMapURLForScript(const Script&) override;
 
 private:
-    virtual void startListeningScriptDebugServer() override;
-    virtual void stopListeningScriptDebugServer(bool isBeingDestroyed) override;
     virtual void muteConsole() override;
     virtual void unmuteConsole() override;
 
index 63b5b54..e7c5f93 100644 (file)
@@ -57,32 +57,17 @@ PageScriptDebugServer::PageScriptDebugServer(Page& page)
 {
 }
 
-void PageScriptDebugServer::addListener(ScriptDebugListener* listener)
+void PageScriptDebugServer::attachDebugger()
 {
-    if (!listener)
-        return;
-
-    bool wasEmpty = m_listeners.isEmpty();
-    m_listeners.add(listener);
-
-    if (wasEmpty) {
-        m_page.setDebugger(this);
-        recompileAllJSFunctions();
-    }
+    m_page.setDebugger(this);
+    recompileAllJSFunctions();
 }
 
-void PageScriptDebugServer::removeListener(ScriptDebugListener* listener, bool isBeingDestroyed)
+void PageScriptDebugServer::detachDebugger(bool isBeingDestroyed)
 {
-    if (!listener)
-        return;
-
-    m_listeners.remove(listener);
-
-    if (m_listeners.isEmpty()) {
-        m_page.setDebugger(nullptr);
-        if (!isBeingDestroyed)
-            recompileAllJSFunctions();
-    }
+    m_page.setDebugger(nullptr);
+    if (!isBeingDestroyed)
+        recompileAllJSFunctions();
 }
 
 void PageScriptDebugServer::recompileAllJSFunctions()
index d224f67..4478eae 100644 (file)
@@ -28,7 +28,6 @@
 #define PageScriptDebugServer_h
 
 #include <inspector/ScriptDebugServer.h>
-#include <wtf/Forward.h>
 
 namespace WebCore {
 
@@ -43,13 +42,12 @@ public:
     PageScriptDebugServer(Page&);
     virtual ~PageScriptDebugServer() { }
 
-    void addListener(Inspector::ScriptDebugListener*);
-    void removeListener(Inspector::ScriptDebugListener*, bool isBeingDestroyed);
-
     virtual void recompileAllJSFunctions() override;
 
 private:
-    virtual ListenerSet& getListeners() override { return m_listeners; }
+    virtual void attachDebugger() override;
+    virtual void detachDebugger(bool isBeingDestroyed) override;
+
     virtual void didPause(JSC::JSGlobalObject*) override;
     virtual void didContinue(JSC::JSGlobalObject*) override;
     virtual void runEventLoopWhilePaused() override;
@@ -63,7 +61,6 @@ private:
     void setJavaScriptPaused(Frame*, bool paused);
     void setJavaScriptPaused(FrameView*, bool paused);
 
-    ListenerSet m_listeners;
     Page& m_page;
 };
 
index cc844e3..859461f 100644 (file)
@@ -106,16 +106,6 @@ void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(WorkerThread* th
         agent->m_scriptDebugServer.interruptAndRunTask(std::make_unique<RunInspectorCommandsTask>(thread, &agent->m_inspectedWorkerGlobalScope));
 }
 
-void WorkerDebuggerAgent::startListeningScriptDebugServer()
-{
-    scriptDebugServer().addListener(this);
-}
-
-void WorkerDebuggerAgent::stopListeningScriptDebugServer(bool isBeingDestroyed)
-{
-    scriptDebugServer().removeListener(this, isBeingDestroyed);
-}
-
 void WorkerDebuggerAgent::breakpointActionLog(JSC::ExecState*, const String& message)
 {
     m_inspectedWorkerGlobalScope.addConsoleMessage(MessageSource::JS, MessageLevel::Log, message);
index 3e17681..ac19080 100644 (file)
@@ -50,8 +50,6 @@ public:
     static const char* debuggerTaskMode;
     static void interruptAndDispatchInspectorCommands(WorkerThread*);
 
-    virtual void startListeningScriptDebugServer() override;
-    virtual void stopListeningScriptDebugServer(bool isBeingDestroyed) override;
     virtual WorkerScriptDebugServer& scriptDebugServer() override;
     virtual Inspector::InjectedScript injectedScriptForEval(ErrorString&, const int* executionContextId) override;
     virtual void muteConsole() override;