#include "config.h"
#include "core/inspector/WorkerDebuggerAgent.h"
-#include "bindings/v8/ScriptDebugServer.h"
+#include "bindings/core/v8/ScriptDebugServer.h"
+#include "core/inspector/WorkerInspectorController.h"
#include "core/workers/WorkerGlobalScope.h"
#include "core/workers/WorkerThread.h"
#include "wtf/MessageQueue.h"
-namespace WebCore {
+namespace blink {
namespace {
-Mutex& workerDebuggerAgentsMutex()
-{
- AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
- return mutex;
-}
-
-typedef HashMap<WorkerThread*, WorkerDebuggerAgent*> WorkerDebuggerAgents;
-
-WorkerDebuggerAgents& workerDebuggerAgents()
-{
- DEFINE_STATIC_LOCAL(WorkerDebuggerAgents, agents, ());
- return agents;
-}
-
-
-class RunInspectorCommandsTask FINAL : public ScriptDebugServer::Task {
+class RunInspectorCommandsTask final : public ScriptDebugServer::Task {
public:
- RunInspectorCommandsTask(WorkerThread* thread, WorkerGlobalScope* workerGlobalScope)
- : m_thread(thread)
- , m_workerGlobalScope(workerGlobalScope) { }
+ explicit RunInspectorCommandsTask(WorkerThread* thread)
+ : m_thread(thread) { }
virtual ~RunInspectorCommandsTask() { }
- virtual void run() OVERRIDE
+ virtual void run() override
{
- // Process all queued debugger commands. It is safe to use m_workerGlobalScope here
- // because it is alive if RunWorkerLoop is not terminated, otherwise it will
- // just be ignored. WorkerThread is certainly alive if this task is being executed.
- while (MessageQueueMessageReceived == m_thread->runLoop().runInMode(m_workerGlobalScope, WorkerDebuggerAgent::debuggerTaskMode, WorkerRunLoop::DontWaitForMessage)) { }
+ // Process all queued debugger commands. WorkerThread is certainly
+ // alive if this task is being executed.
+ m_thread->willEnterNestedLoop();
+ while (MessageQueueMessageReceived == m_thread->runDebuggerTask(WorkerThread::DontWaitForMessage)) { }
+ m_thread->didLeaveNestedLoop();
}
private:
WorkerThread* m_thread;
- WorkerGlobalScope* m_workerGlobalScope;
};
} // namespace
-const char WorkerDebuggerAgent::debuggerTaskMode[] = "debugger";
-
-PassOwnPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
+PassOwnPtrWillBeRawPtr<WorkerDebuggerAgent> WorkerDebuggerAgent::create(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
{
- return adoptPtr(new WorkerDebuggerAgent(scriptDebugServer, inspectedWorkerGlobalScope, injectedScriptManager));
+ return adoptPtrWillBeNoop(new WorkerDebuggerAgent(scriptDebugServer, inspectedWorkerGlobalScope, injectedScriptManager));
}
WorkerDebuggerAgent::WorkerDebuggerAgent(WorkerScriptDebugServer* scriptDebugServer, WorkerGlobalScope* inspectedWorkerGlobalScope, InjectedScriptManager* injectedScriptManager)
, m_scriptDebugServer(scriptDebugServer)
, m_inspectedWorkerGlobalScope(inspectedWorkerGlobalScope)
{
- MutexLocker lock(workerDebuggerAgentsMutex());
- workerDebuggerAgents().set(inspectedWorkerGlobalScope->thread(), this);
}
WorkerDebuggerAgent::~WorkerDebuggerAgent()
{
- MutexLocker lock(workerDebuggerAgentsMutex());
- ASSERT(workerDebuggerAgents().contains(m_inspectedWorkerGlobalScope->thread()));
- workerDebuggerAgents().remove(m_inspectedWorkerGlobalScope->thread());
}
-void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(WorkerThread* thread)
+void WorkerDebuggerAgent::trace(Visitor* visitor)
{
- MutexLocker lock(workerDebuggerAgentsMutex());
- WorkerDebuggerAgent* agent = workerDebuggerAgents().get(thread);
- if (agent)
- agent->m_scriptDebugServer->interruptAndRunTask(adoptPtr(new RunInspectorCommandsTask(thread, agent->m_inspectedWorkerGlobalScope)));
+ visitor->trace(m_inspectedWorkerGlobalScope);
+ InspectorDebuggerAgent::trace(visitor);
+}
+
+void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands()
+{
+ scriptDebugServer().interruptAndRunTask(adoptPtr(new RunInspectorCommandsTask(m_inspectedWorkerGlobalScope->thread())));
}
void WorkerDebuggerAgent::startListeningScriptDebugServer()
InjectedScript WorkerDebuggerAgent::injectedScriptForEval(ErrorString* error, const int* executionContextId)
{
- if (executionContextId) {
- *error = "Execution context id is not supported for workers as there is only one execution context.";
- return InjectedScript();
- }
- ScriptState* scriptState = scriptStateFromWorkerGlobalScope(m_inspectedWorkerGlobalScope);
- return injectedScriptManager()->injectedScriptFor(scriptState);
+ if (!executionContextId)
+ return injectedScriptManager()->injectedScriptFor(m_inspectedWorkerGlobalScope->script()->scriptState());
+
+ InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId);
+ if (injectedScript.isEmpty())
+ *error = "Execution context with given id not found.";
+ return injectedScript;
}
void WorkerDebuggerAgent::muteConsole()
// We don't need to mute console for workers.
}
-} // namespace WebCore
+} // namespace blink