Title: [108324] trunk/Source/WebCore
Revision
108324
Author
[email protected]
Date
2012-02-21 01:09:39 -0800 (Tue, 21 Feb 2012)

Log Message

[V8] Web Inspector: simplify worker debugger implementation
https://bugs.webkit.org/show_bug.cgi?id=79085

There is one instance of WorkerScriptDebugServer per worker thread. We don't
need to resolve WorkerContext from V8::Context anymore.

Reviewed by Pavel Feldman.

* bindings/v8/WorkerScriptDebugServer.cpp:
(WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer):
(WebCore::WorkerScriptDebugServer::addListener):
(WebCore::WorkerScriptDebugServer::removeListener):
(WebCore::WorkerScriptDebugServer::getDebugListenerForContext):
(WebCore::WorkerScriptDebugServer::runMessageLoopOnPause):
* bindings/v8/WorkerScriptDebugServer.h:
(WorkerScriptDebugServer):
* inspector/WorkerDebuggerAgent.cpp:
(WebCore::WorkerDebuggerAgent::WorkerDebuggerAgent):
(WebCore::WorkerDebuggerAgent::startListeningScriptDebugServer):
(WebCore::WorkerDebuggerAgent::stopListeningScriptDebugServer):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (108323 => 108324)


--- trunk/Source/WebCore/ChangeLog	2012-02-21 09:09:22 UTC (rev 108323)
+++ trunk/Source/WebCore/ChangeLog	2012-02-21 09:09:39 UTC (rev 108324)
@@ -1,3 +1,26 @@
+2012-02-21  Yury Semikhatsky  <[email protected]>
+
+        [V8] Web Inspector: simplify worker debugger implementation
+        https://bugs.webkit.org/show_bug.cgi?id=79085
+
+        There is one instance of WorkerScriptDebugServer per worker thread. We don't
+        need to resolve WorkerContext from V8::Context anymore.
+
+        Reviewed by Pavel Feldman.
+
+        * bindings/v8/WorkerScriptDebugServer.cpp:
+        (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer):
+        (WebCore::WorkerScriptDebugServer::addListener):
+        (WebCore::WorkerScriptDebugServer::removeListener):
+        (WebCore::WorkerScriptDebugServer::getDebugListenerForContext):
+        (WebCore::WorkerScriptDebugServer::runMessageLoopOnPause):
+        * bindings/v8/WorkerScriptDebugServer.h:
+        (WorkerScriptDebugServer):
+        * inspector/WorkerDebuggerAgent.cpp:
+        (WebCore::WorkerDebuggerAgent::WorkerDebuggerAgent):
+        (WebCore::WorkerDebuggerAgent::startListeningScriptDebugServer):
+        (WebCore::WorkerDebuggerAgent::stopListeningScriptDebugServer):
+
 2012-02-21  Kentaro Hara  <[email protected]>
 
         Enable the IDL attribute checker in Chromium

Modified: trunk/Source/WebCore/bindings/js/WorkerScriptDebugServer.cpp (108323 => 108324)


--- trunk/Source/WebCore/bindings/js/WorkerScriptDebugServer.cpp	2012-02-21 09:09:22 UTC (rev 108323)
+++ trunk/Source/WebCore/bindings/js/WorkerScriptDebugServer.cpp	2012-02-21 09:09:39 UTC (rev 108324)
@@ -34,22 +34,20 @@
 
 #include "WorkerScriptDebugServer.h"
 
-#include "WorkerContext.h"
-
 namespace WebCore {
 
 const char* WorkerScriptDebugServer::debuggerTaskMode = "debugger";
 
-WorkerScriptDebugServer::WorkerScriptDebugServer()
+WorkerScriptDebugServer::WorkerScriptDebugServer(WorkerContext*)
     : ScriptDebugServer()
 {
 }
 
-void WorkerScriptDebugServer::addListener(ScriptDebugListener*, WorkerContext*)
+void WorkerScriptDebugServer::addListener(ScriptDebugListener*)
 {
 }
 
-void WorkerScriptDebugServer::removeListener(ScriptDebugListener*, WorkerContext*)
+void WorkerScriptDebugServer::removeListener(ScriptDebugListener*)
 {
 }
 

Modified: trunk/Source/WebCore/bindings/js/WorkerScriptDebugServer.h (108323 => 108324)


--- trunk/Source/WebCore/bindings/js/WorkerScriptDebugServer.h	2012-02-21 09:09:22 UTC (rev 108323)
+++ trunk/Source/WebCore/bindings/js/WorkerScriptDebugServer.h	2012-02-21 09:09:39 UTC (rev 108324)
@@ -42,11 +42,11 @@
 class WorkerScriptDebugServer : public ScriptDebugServer {
     WTF_MAKE_NONCOPYABLE(WorkerScriptDebugServer);
 public:
-    WorkerScriptDebugServer();
+    explicit WorkerScriptDebugServer(WorkerContext*);
     ~WorkerScriptDebugServer() { }
 
-    void addListener(ScriptDebugListener*, WorkerContext*);
-    void removeListener(ScriptDebugListener*, WorkerContext*);
+    void addListener(ScriptDebugListener*);
+    void removeListener(ScriptDebugListener*);
 
     static const char* debuggerTaskMode;
 

Modified: trunk/Source/WebCore/bindings/v8/WorkerScriptDebugServer.cpp (108323 => 108324)


--- trunk/Source/WebCore/bindings/v8/WorkerScriptDebugServer.cpp	2012-02-21 09:09:22 UTC (rev 108323)
+++ trunk/Source/WebCore/bindings/v8/WorkerScriptDebugServer.cpp	2012-02-21 09:09:39 UTC (rev 108324)
@@ -34,9 +34,6 @@
 #if ENABLE(_javascript__DEBUGGER) && ENABLE(WORKERS)
 
 #include "ScriptDebugListener.h"
-#include "V8DOMWrapper.h"
-#include "V8DedicatedWorkerContext.h"
-#include "V8SharedWorkerContext.h"
 #include "WorkerContext.h"
 #include "WorkerContextExecutionProxy.h"
 #include "WorkerDebuggerAgent.h"
@@ -46,50 +43,28 @@
 
 namespace WebCore {
 
-static WorkerContext* retrieveWorkerContext(v8::Handle<v8::Context> context)
-{
-    v8::Handle<v8::Object> global = context->Global();
-    ASSERT(!global.IsEmpty());
-
-    v8::Handle<v8::Object> prototype = v8::Handle<v8::Object>::Cast(global->GetPrototype());
-    ASSERT(!prototype.IsEmpty());
-
-    prototype = v8::Handle<v8::Object>::Cast(prototype->GetPrototype());
-    ASSERT(!prototype.IsEmpty());
-
-    WrapperTypeInfo* typeInfo = V8DOMWrapper::domWrapperType(prototype);
-    if (&V8DedicatedWorkerContext::info == typeInfo)
-        return V8DedicatedWorkerContext::toNative(prototype);
-#if ENABLE(SHARED_WORKERS)
-    if (&V8SharedWorkerContext::info == typeInfo)
-        return V8SharedWorkerContext::toNative(prototype);
-#endif
-    ASSERT_NOT_REACHED();
-    return 0;
-}
-
-WorkerScriptDebugServer::WorkerScriptDebugServer()
+WorkerScriptDebugServer::WorkerScriptDebugServer(WorkerContext* workerContext)
     : ScriptDebugServer()
-    , m_pausedWorkerContext(0)
+    , m_listener(0)
+    , m_workerContext(workerContext)
 {
 }
 
-void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener, WorkerContext* workerContext)
+void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener)
 {
     v8::HandleScope scope;
     v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
     v8::Context::Scope contextScope(debuggerContext);
 
-    if (!m_listenersMap.size()) {
-        // FIXME: synchronize access to this code.
-        ensureDebuggerScriptCompiled();
-        ASSERT(!m_debuggerScript.get()->IsUndefined());
-        v8::Debug::SetDebugEventListener2(&WorkerScriptDebugServer::v8DebugEventCallback, v8::External::New(this));
-    }
-    m_listenersMap.set(workerContext, listener);
+    ASSERT(!m_listener);
+    m_listener = listener;
+
+    ensureDebuggerScriptCompiled();
+    ASSERT(!m_debuggerScript.get()->IsUndefined());
+    v8::Debug::SetDebugEventListener2(&WorkerScriptDebugServer::v8DebugEventCallback, v8::External::New(this));
     
     // TODO: Should we remove |proxy|? It looks like unused now.
-    WorkerContextExecutionProxy* proxy = workerContext->script()->proxy();
+    WorkerContextExecutionProxy* proxy = m_workerContext->script()->proxy();
     if (!proxy)
         return;
 
@@ -104,45 +79,31 @@
         dispatchDidParseSource(listener, v8::Handle<v8::Object>::Cast(scriptsArray->Get(v8::Integer::New(i))));
 }
 
-void WorkerScriptDebugServer::removeListener(ScriptDebugListener* listener, WorkerContext* workerContext)
+void WorkerScriptDebugServer::removeListener(ScriptDebugListener* listener)
 {
-    if (!m_listenersMap.contains(workerContext))
-        return;
-
-    if (m_pausedWorkerContext == workerContext)
-        continueProgram();
-
-    m_listenersMap.remove(workerContext);
-
-    if (m_listenersMap.isEmpty())
-        v8::Debug::SetDebugEventListener2(0);
+    ASSERT(m_listener == listener);
+    continueProgram();
+    m_listener = 0;
+    v8::Debug::SetDebugEventListener2(0);
 }
 
-ScriptDebugListener* WorkerScriptDebugServer::getDebugListenerForContext(v8::Handle<v8::Context> context)
+ScriptDebugListener* WorkerScriptDebugServer::getDebugListenerForContext(v8::Handle<v8::Context>)
 {
-    WorkerContext* workerContext = retrieveWorkerContext(context);
-    if (!workerContext)
-        return 0;
-    return m_listenersMap.get(workerContext);
+    // There is only one worker context in isolate.
+    return m_listener;
 }
 
-void WorkerScriptDebugServer::runMessageLoopOnPause(v8::Handle<v8::Context> context)
+void WorkerScriptDebugServer::runMessageLoopOnPause(v8::Handle<v8::Context>)
 {
-    WorkerContext* workerContext = retrieveWorkerContext(context);
-    WorkerThread* workerThread = workerContext->thread();
-
-    m_pausedWorkerContext = workerContext;
-
     MessageQueueWaitResult result;
     do {
-        result = workerThread->runLoop().runInMode(workerContext, WorkerDebuggerAgent::debuggerTaskMode);
+        result = m_workerContext->thread()->runLoop().runInMode(m_workerContext, WorkerDebuggerAgent::debuggerTaskMode);
     // Keep waiting until execution is resumed.
     } while (result == MessageQueueMessageReceived && isPaused());
-    m_pausedWorkerContext = 0;
     
     // The listener may have been removed in the nested loop.
-    if (ScriptDebugListener* listener = m_listenersMap.get(workerContext))
-        listener->didContinue();
+    if (m_listener)
+        m_listener->didContinue();
 }
 
 void WorkerScriptDebugServer::quitMessageLoopOnPause()

Modified: trunk/Source/WebCore/bindings/v8/WorkerScriptDebugServer.h (108323 => 108324)


--- trunk/Source/WebCore/bindings/v8/WorkerScriptDebugServer.h	2012-02-21 09:09:22 UTC (rev 108323)
+++ trunk/Source/WebCore/bindings/v8/WorkerScriptDebugServer.h	2012-02-21 09:09:39 UTC (rev 108324)
@@ -42,11 +42,11 @@
 class WorkerScriptDebugServer : public ScriptDebugServer {
     WTF_MAKE_NONCOPYABLE(WorkerScriptDebugServer);
 public:
-    WorkerScriptDebugServer();
+    explicit WorkerScriptDebugServer(WorkerContext*);
     ~WorkerScriptDebugServer() { }
 
-    void addListener(ScriptDebugListener*, WorkerContext*);
-    void removeListener(ScriptDebugListener*, WorkerContext*);
+    void addListener(ScriptDebugListener*);
+    void removeListener(ScriptDebugListener*);
 
 private:
     virtual ScriptDebugListener* getDebugListenerForContext(v8::Handle<v8::Context>);
@@ -54,8 +54,8 @@
     virtual void quitMessageLoopOnPause();
 
     typedef HashMap<WorkerContext*, ScriptDebugListener*> ListenersMap;
-    ListenersMap m_listenersMap;
-    WorkerContext* m_pausedWorkerContext;
+    ScriptDebugListener* m_listener;
+    WorkerContext* m_workerContext;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/inspector/WorkerDebuggerAgent.cpp (108323 => 108324)


--- trunk/Source/WebCore/inspector/WorkerDebuggerAgent.cpp	2012-02-21 09:09:22 UTC (rev 108323)
+++ trunk/Source/WebCore/inspector/WorkerDebuggerAgent.cpp	2012-02-21 09:09:39 UTC (rev 108324)
@@ -46,6 +46,7 @@
 
 WorkerDebuggerAgent::WorkerDebuggerAgent(InstrumentingAgents* instrumentingAgents, InspectorState* inspectorState, WorkerContext* inspectedWorkerContext, InjectedScriptManager* injectedScriptManager)
     : InspectorDebuggerAgent(instrumentingAgents, inspectorState, injectedScriptManager)
+    , m_scriptDebugServer(inspectedWorkerContext)
     , m_inspectedWorkerContext(inspectedWorkerContext)
 {
 }
@@ -56,12 +57,12 @@
 
 void WorkerDebuggerAgent::startListeningScriptDebugServer()
 {
-    scriptDebugServer().addListener(this, m_inspectedWorkerContext);
+    scriptDebugServer().addListener(this);
 }
 
 void WorkerDebuggerAgent::stopListeningScriptDebugServer()
 {
-    scriptDebugServer().removeListener(this, m_inspectedWorkerContext);
+    scriptDebugServer().removeListener(this);
 }
 
 WorkerScriptDebugServer& WorkerDebuggerAgent::scriptDebugServer()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to