Web Inspector: Remove recompileAllJSFunctions timer in ScriptDebugServer
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jan 2014 18:57:26 +0000 (18:57 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jan 2014 18:57:26 +0000 (18:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127409

Reviewed by Timothy Hatcher.

* bindings/js/ScriptDebugServer.h:
* bindings/js/ScriptDebugServer.cpp:
(WebCore::ScriptDebugServer::ScriptDebugServer):
Remove m_recompileTimer and the recompile soon function.
We can just recompile immediately in all existing cases.

* bindings/js/PageScriptDebugServer.h:
* bindings/js/PageScriptDebugServer.cpp:
(WebCore::PageScriptDebugServer::addListener):
(WebCore::PageScriptDebugServer::removeListener):
(WebCore::PageScriptDebugServer::recompileAllJSFunctions):
(WebCore::PageScriptDebugServer::didAddFirstListener):
(WebCore::PageScriptDebugServer::didRemoveLastListener):
Add a "didAddFirstListener" to match "didRemoveLastListener".
Only recompile functions when we attach the debugger and when
we detach the last listener.

* bindings/js/WorkerScriptDebugServer.cpp:
(WebCore::WorkerScriptDebugServer::addListener):
(WebCore::WorkerScriptDebugServer::removeListener):
(WebCore::WorkerScriptDebugServer::recompileAllJSFunctions):
Same thing. Also rearrange the functions to read better.

* inspector/InspectorProfilerAgent.cpp:
Use the direct recompile function instead of the removed "soon" version.

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/PageScriptDebugServer.cpp
Source/WebCore/bindings/js/PageScriptDebugServer.h
Source/WebCore/bindings/js/ScriptDebugServer.cpp
Source/WebCore/bindings/js/ScriptDebugServer.h
Source/WebCore/bindings/js/WorkerScriptDebugServer.cpp
Source/WebCore/inspector/InspectorProfilerAgent.cpp

index 22a7b1f..a1c5583 100644 (file)
@@ -1,3 +1,36 @@
+2014-01-21  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Remove recompileAllJSFunctions timer in ScriptDebugServer
+        https://bugs.webkit.org/show_bug.cgi?id=127409
+
+        Reviewed by Timothy Hatcher.
+
+        * bindings/js/ScriptDebugServer.h:
+        * bindings/js/ScriptDebugServer.cpp:
+        (WebCore::ScriptDebugServer::ScriptDebugServer):
+        Remove m_recompileTimer and the recompile soon function.
+        We can just recompile immediately in all existing cases.
+
+        * bindings/js/PageScriptDebugServer.h:
+        * bindings/js/PageScriptDebugServer.cpp:
+        (WebCore::PageScriptDebugServer::addListener):
+        (WebCore::PageScriptDebugServer::removeListener):
+        (WebCore::PageScriptDebugServer::recompileAllJSFunctions):
+        (WebCore::PageScriptDebugServer::didAddFirstListener):
+        (WebCore::PageScriptDebugServer::didRemoveLastListener):
+        Add a "didAddFirstListener" to match "didRemoveLastListener".
+        Only recompile functions when we attach the debugger and when
+        we detach the last listener.
+
+        * bindings/js/WorkerScriptDebugServer.cpp:
+        (WebCore::WorkerScriptDebugServer::addListener):
+        (WebCore::WorkerScriptDebugServer::removeListener):
+        (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions):
+        Same thing. Also rearrange the functions to read better.
+
+        * inspector/InspectorProfilerAgent.cpp:
+        Use the direct recompile function instead of the removed "soon" version.
+
 2014-01-22  Robert Sipka  <sipka@inf.u-szeged.hu>
 
         [curl] Improve detecting and handling of SSL client certificate
index 1cec7b3..50daf26 100644 (file)
@@ -94,10 +94,12 @@ void PageScriptDebugServer::addListener(ScriptDebugListener* listener, Page* pag
     OwnPtr<ListenerSet>& listeners = m_pageListenersMap.add(page, nullptr).iterator->value;
     if (!listeners)
         listeners = adoptPtr(new ListenerSet);
+
+    bool wasEmpty = listeners->isEmpty();
     listeners->add(listener);
 
-    recompileAllJSFunctionsSoon();
-    page->setDebugger(this);
+    if (wasEmpty)
+        didAddFirstListener(page);
 }
 
 void PageScriptDebugServer::removeListener(ScriptDebugListener* listener, Page* page)
@@ -111,6 +113,7 @@ void PageScriptDebugServer::removeListener(ScriptDebugListener* listener, Page*
 
     ListenerSet* listeners = it->value.get();
     listeners->remove(listener);
+
     if (listeners->isEmpty()) {
         m_pageListenersMap.remove(it);
         didRemoveLastListener(page);
@@ -120,11 +123,7 @@ void PageScriptDebugServer::removeListener(ScriptDebugListener* listener, Page*
 void PageScriptDebugServer::recompileAllJSFunctions()
 {
     JSLockHolder lock(JSDOMWindow::commonVM());
-    // If JavaScript stack is not empty postpone recompilation.
-    if (JSDOMWindow::commonVM()->entryScope)
-        recompileAllJSFunctionsSoon();
-    else
-        Debugger::recompileAllJSFunctions(JSDOMWindow::commonVM());
+    Debugger::recompileAllJSFunctions(JSDOMWindow::commonVM());
 }
 
 ScriptDebugServer::ListenerSet* PageScriptDebugServer::getListenersForGlobalObject(JSGlobalObject* globalObject)
@@ -161,6 +160,13 @@ void PageScriptDebugServer::didContinue(JSC::JSGlobalObject* globalObject)
         setJavaScriptPaused(page->group(), false);
 }
 
+void PageScriptDebugServer::didAddFirstListener(Page* page)
+{
+    // Set debugger before recompiling to get sourceParsed callbacks.
+    page->setDebugger(this);
+    recompileAllJSFunctions();
+}
+
 void PageScriptDebugServer::didRemoveLastListener(Page* page)
 {
     ASSERT(page);
@@ -168,8 +174,9 @@ void PageScriptDebugServer::didRemoveLastListener(Page* page)
     if (m_pausedPage == page)
         m_doneProcessingDebuggerEvents = true;
 
-    recompileAllJSFunctionsSoon();
-    page->setDebugger(0);
+    // Clear debugger before recompiling because we do not need sourceParsed callbacks.
+    page->setDebugger(nullptr);
+    recompileAllJSFunctions();
 }
 
 void PageScriptDebugServer::runEventLoopWhilePaused()
index ed7f24e..c702cfa 100644 (file)
@@ -65,6 +65,7 @@ private:
 
     virtual void runEventLoopWhilePaused();
 
+    void didAddFirstListener(Page*);
     void didRemoveLastListener(Page*);
 
     void setJavaScriptPaused(const PageGroup&, bool paused);
index dac52a2..403dfe9 100644 (file)
@@ -40,6 +40,7 @@
 #include "JavaScriptCallFrame.h"
 #include "PageConsole.h"
 #include "Sound.h"
+#include "Timer.h"
 #include <bindings/ScriptValue.h>
 #include <debugger/DebuggerCallFrame.h>
 #include <parser/SourceProvider.h>
@@ -57,7 +58,6 @@ ScriptDebugServer::ScriptDebugServer(bool isInWorkerThread)
     : Debugger(isInWorkerThread)
     , m_doneProcessingDebuggerEvents(true)
     , m_callingListeners(false)
-    , m_recompileTimer(this, &ScriptDebugServer::recompileAllJSFunctionsTimerFired)
 {
 }
 
@@ -313,16 +313,6 @@ void ScriptDebugServer::handlePause(Debugger::ReasonForPause, JSGlobalObject* vm
     dispatchFunctionToListeners(&ScriptDebugServer::dispatchDidContinue, vmEntryGlobalObject);
 }
 
-void ScriptDebugServer::recompileAllJSFunctionsSoon()
-{
-    m_recompileTimer.startOneShot(0);
-}
-
-void ScriptDebugServer::recompileAllJSFunctionsTimerFired(Timer<ScriptDebugServer>&)
-{
-    recompileAllJSFunctions();
-}
-
 const Vector<ScriptBreakpointAction>& ScriptDebugServer::getActionsForBreakpoint(JSC::BreakpointID breakpointID)
 {
     ASSERT(breakpointID != JSC::noBreakpointID);
index fa0ee5d..93540ae 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "ScriptBreakpoint.h"
 #include "ScriptDebugListener.h"
-#include "Timer.h"
 #include <bindings/ScriptObject.h>
 #include <debugger/Debugger.h>
 #include <wtf/HashMap.h>
@@ -59,7 +58,6 @@ public:
     void removeBreakpoint(JSC::BreakpointID);
     void clearBreakpoints();
 
-    void recompileAllJSFunctionsSoon();
     virtual void recompileAllJSFunctions() = 0;
 
     const Vector<ScriptBreakpointAction>& getActionsForBreakpoint(JSC::BreakpointID);
@@ -109,12 +107,9 @@ private:
     virtual void handlePause(JSC::Debugger::ReasonForPause, JSC::JSGlobalObject*) override final;
     virtual void notifyDoneProcessingDebuggerEvents() override final;
 
-    void recompileAllJSFunctionsTimerFired(Timer<ScriptDebugServer>&);
-
     unsigned m_hitCount;
     bool m_callingListeners;
     BreakpointIDToActionsMap m_breakpointIDToActions;
-    Timer<ScriptDebugServer> m_recompileTimer;
 
     friend class DebuggerCallFrameScope;
 };
index bec9e57..ed31a3a 100644 (file)
@@ -55,22 +55,13 @@ void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener)
     if (!listener)
         return;
 
-    if (m_listeners.isEmpty())
-        m_workerGlobalScope->script()->attachDebugger(this);
+    bool wasEmpty = m_listeners.isEmpty();
     m_listeners.add(listener);
-    recompileAllJSFunctions();
-}
-
-void WorkerScriptDebugServer::recompileAllJSFunctions()
-{
-    JSC::VM* vm = m_workerGlobalScope->script()->vm();
 
-    JSC::JSLockHolder lock(vm);
-    // If JavaScript stack is not empty postpone recompilation.
-    if (vm->entryScope)
-        recompileAllJSFunctionsSoon();
-    else
-        JSC::Debugger::recompileAllJSFunctions(vm);
+    if (wasEmpty) {
+        m_workerGlobalScope->script()->attachDebugger(this);
+        recompileAllJSFunctions();
+    }
 }
 
 void WorkerScriptDebugServer::removeListener(ScriptDebugListener* listener)
@@ -79,8 +70,19 @@ void WorkerScriptDebugServer::removeListener(ScriptDebugListener* listener)
         return;
 
     m_listeners.remove(listener);
-    if (m_listeners.isEmpty())
+
+    if (m_listeners.isEmpty()) {
         m_workerGlobalScope->script()->detachDebugger(this);
+        recompileAllJSFunctions();
+    }
+}
+
+void WorkerScriptDebugServer::recompileAllJSFunctions()
+{
+    JSC::VM* vm = m_workerGlobalScope->script()->vm();
+
+    JSC::JSLockHolder lock(vm);
+    JSC::Debugger::recompileAllJSFunctions(vm);
 }
 
 void WorkerScriptDebugServer::runEventLoopWhilePaused()
index 1f25a3e..b68dfbe 100644 (file)
@@ -73,7 +73,7 @@ public:
 private:
     virtual void recompileScript() override
     {
-        PageScriptDebugServer::shared().recompileAllJSFunctionsSoon();
+        PageScriptDebugServer::shared().recompileAllJSFunctions();
     }
 
     virtual void startProfiling(const String& title) override