Changeset 133281 in webkit


Ignore:
Timestamp:
Nov 2, 2012 3:24:40 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: [JSC] implement WorkerScriptDebugServer
https://bugs.webkit.org/show_bug.cgi?id=99801

Patch by Peter Wang <peter.wang@torchmobile.com.cn> on 2012-11-02
Reviewed by Yury Semikhatsky.

To implement Worker Inspector for JSC.
The virtual function "runEventLoopWhilePaused" is defined, since there are different ways to block
the JS running in worker-context and normal page-context.
The function "isContentScript" now is virtual because the original invoked functions are useless
and cause problem in worker-context.
In function "WebCore::WorkerScriptController::attachDebugger", we invoke "initScriptIfNeeded" to
ensure the JSGloblalObject exist in the case of attaching Debugger before executing the worker
JS code (Pause on start).

No new test case.

  • bindings/js/PageScriptDebugServer.cpp:

(WebCore::PageScriptDebugServer::runEventLoopWhilePaused):
(WebCore):

  • bindings/js/PageScriptDebugServer.h:

(PageScriptDebugServer):

  • bindings/js/ScriptDebugServer.cpp:

(WebCore::ScriptDebugServer::isContentScript):
(WebCore::ScriptDebugServer::pauseIfNeeded):

  • bindings/js/ScriptDebugServer.h:

(JSC):
(ScriptDebugServer):

  • bindings/js/WorkerScriptController.cpp:

(WebCore::WorkerScriptController::attachDebugger):
(WebCore):
(WebCore::WorkerScriptController::detachDebugger):

  • bindings/js/WorkerScriptController.h:

(WorkerScriptController):

  • bindings/js/WorkerScriptDebugServer.cpp:

(WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer):
(WebCore):
(WebCore::WorkerScriptDebugServer::addListener):
(WebCore::WorkerScriptDebugServer::recompileAllJSFunctions):
(WebCore::WorkerScriptDebugServer::removeListener):
(WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused):

  • bindings/js/WorkerScriptDebugServer.h:

(WorkerScriptDebugServer):
(WebCore::WorkerScriptDebugServer::getListenersForGlobalObject):
(WebCore::WorkerScriptDebugServer::isContentScript):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r133279 r133281  
     12012-11-02  Peter Wang  <peter.wang@torchmobile.com.cn>
     2
     3        Web Inspector: [JSC] implement WorkerScriptDebugServer
     4        https://bugs.webkit.org/show_bug.cgi?id=99801
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        To implement Worker Inspector for JSC.
     9        The virtual function "runEventLoopWhilePaused" is defined, since there are different ways to block
     10        the JS running in worker-context and normal page-context.
     11        The function "isContentScript" now is virtual because the original invoked functions are useless
     12        and cause problem in worker-context.
     13        In function "WebCore::WorkerScriptController::attachDebugger", we invoke "initScriptIfNeeded" to
     14        ensure the JSGloblalObject exist in the case of attaching Debugger before executing the worker
     15        JS code (Pause on start).
     16
     17        No new test case.
     18
     19        * bindings/js/PageScriptDebugServer.cpp:
     20        (WebCore::PageScriptDebugServer::runEventLoopWhilePaused):
     21        (WebCore):
     22        * bindings/js/PageScriptDebugServer.h:
     23        (PageScriptDebugServer):
     24        * bindings/js/ScriptDebugServer.cpp:
     25        (WebCore::ScriptDebugServer::isContentScript):
     26        (WebCore::ScriptDebugServer::pauseIfNeeded):
     27        * bindings/js/ScriptDebugServer.h:
     28        (JSC):
     29        (ScriptDebugServer):
     30        * bindings/js/WorkerScriptController.cpp:
     31        (WebCore::WorkerScriptController::attachDebugger):
     32        (WebCore):
     33        (WebCore::WorkerScriptController::detachDebugger):
     34        * bindings/js/WorkerScriptController.h:
     35        (WorkerScriptController):
     36        * bindings/js/WorkerScriptDebugServer.cpp:
     37        (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer):
     38        (WebCore):
     39        (WebCore::WorkerScriptDebugServer::addListener):
     40        (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions):
     41        (WebCore::WorkerScriptDebugServer::removeListener):
     42        (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused):
     43        * bindings/js/WorkerScriptDebugServer.h:
     44        (WorkerScriptDebugServer):
     45        (WebCore::WorkerScriptDebugServer::getListenersForGlobalObject):
     46        (WebCore::WorkerScriptDebugServer::isContentScript):
     47
    1482012-11-02  KyungTae Kim  <ktf.kim@samsung.com>
    249
  • trunk/Source/WebCore/bindings/js/PageScriptDebugServer.cpp

    r131826 r133281  
    3535#include "PageScriptDebugServer.h"
    3636
     37#include "EventLoop.h"
    3738#include "Frame.h"
    3839#include "FrameView.h"
     
    164165}
    165166
     167void PageScriptDebugServer::runEventLoopWhilePaused()
     168{
     169    EventLoop loop;
     170    while (!m_doneProcessingDebuggerEvents && !loop.ended())
     171        loop.cycle();
     172}
     173
    166174void PageScriptDebugServer::setJavaScriptPaused(const PageGroup& pageGroup, bool paused)
    167175{
  • trunk/Source/WebCore/bindings/js/PageScriptDebugServer.h

    r116917 r133281  
    6464    virtual void didContinue(JSC::JSGlobalObject*);
    6565
     66    virtual void runEventLoopWhilePaused();
     67
    6668    void didRemoveLastListener(Page*);
    6769
  • trunk/Source/WebCore/bindings/js/ScriptDebugServer.cpp

    r130615 r133281  
    3535
    3636#include "ContentSearchUtils.h"
    37 #include "EventLoop.h"
    3837#include "Frame.h"
    3938#include "JSJavaScriptCallFrame.h"
     
    335334}
    336335
    337 static bool isContentScript(ExecState* exec)
     336bool ScriptDebugServer::isContentScript(ExecState* exec)
    338337{
    339338    return currentWorld(exec) != mainThreadNormalWorld();
     
    443442    TimerBase::fireTimersInNestedEventLoop();
    444443
    445     EventLoop loop;
    446444    m_doneProcessingDebuggerEvents = false;
    447     while (!m_doneProcessingDebuggerEvents && !loop.ended())
    448         loop.cycle();
     445    runEventLoopWhilePaused();
    449446
    450447    didContinue(dynamicGlobalObject);
  • trunk/Source/WebCore/bindings/js/ScriptDebugServer.h

    r130615 r133281  
    4747class DebuggerCallFrame;
    4848class JSGlobalObject;
     49class ExecState;
    4950}
    5051namespace WebCore {
     
    114115    virtual void didContinue(JSC::JSGlobalObject*) = 0;
    115116
     117    virtual void runEventLoopWhilePaused() = 0;
     118
     119    virtual bool isContentScript(JSC::ExecState*);
     120
    116121    bool hasBreakpoint(intptr_t sourceID, const TextPosition&) const;
    117122
  • trunk/Source/WebCore/bindings/js/WorkerScriptController.cpp

    r132143 r133281  
    3939#include "WorkerContext.h"
    4040#include "WorkerObjectProxy.h"
     41#include "WorkerScriptDebugServer.h"
    4142#include "WorkerThread.h"
    4243#include <heap/StrongInlines.h>
     
    198199}
    199200
     201void WorkerScriptController::attachDebugger(JSC::Debugger* debugger)
     202{
     203    initScriptIfNeeded();
     204    debugger->attach(m_workerContextWrapper->globalObject());
     205}
     206
     207void WorkerScriptController::detachDebugger(JSC::Debugger* debugger)
     208{
     209    debugger->detach(m_workerContextWrapper->globalObject());
     210}
     211
    200212} // namespace WebCore
    201213
  • trunk/Source/WebCore/bindings/js/WorkerScriptController.h

    r128670 r133281  
    3030
    3131#if ENABLE(WORKERS)
    32 
     32#include <debugger/Debugger.h>
    3333#include <heap/Strong.h>
    3434#include <wtf/Forward.h>
     
    8080        JSC::JSGlobalData* globalData() { return m_globalData.get(); }
    8181
     82        void attachDebugger(JSC::Debugger*);
     83        void detachDebugger(JSC::Debugger*);
     84
    8285    private:
    8386        void initScriptIfNeeded()
  • trunk/Source/WebCore/bindings/js/WorkerScriptDebugServer.cpp

    r108344 r133281  
    3232
    3333#if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(WORKERS)
     34#include "WorkerScriptDebugServer.h"
    3435
    35 #include "WorkerScriptDebugServer.h"
     36#include "WorkerContext.h"
     37#include "WorkerDebuggerAgent.h"
     38#include "WorkerRunLoop.h"
     39#include "WorkerThread.h"
     40
    3641#include <wtf/PassOwnPtr.h>
    3742
     
    4045const char* WorkerScriptDebugServer::debuggerTaskMode = "debugger";
    4146
    42 WorkerScriptDebugServer::WorkerScriptDebugServer(WorkerContext*)
     47WorkerScriptDebugServer::WorkerScriptDebugServer(WorkerContext* context)
    4348    : ScriptDebugServer()
     49    , m_workerContext(context)
    4450{
    4551}
    4652
    47 void WorkerScriptDebugServer::addListener(ScriptDebugListener*)
     53void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener)
    4854{
     55    if (!listener)
     56        return;
     57
     58    if (m_listeners.isEmpty())
     59        m_workerContext->script()->attachDebugger(this);
     60    m_listeners.add(listener);
     61    recompileAllJSFunctions(0);
    4962}
    5063
    51 void WorkerScriptDebugServer::removeListener(ScriptDebugListener*)
     64void WorkerScriptDebugServer::recompileAllJSFunctions(Timer<ScriptDebugServer>*)
    5265{
     66    JSC::JSGlobalData* globalData = m_workerContext->script()->globalData();
     67
     68    JSC::JSLockHolder lock(globalData);
     69    // If JavaScript stack is not empty postpone recompilation.
     70    if (globalData->dynamicGlobalObject)
     71        recompileAllJSFunctionsSoon();
     72    else
     73        JSC::Debugger::recompileAllJSFunctions(globalData);
     74}
     75
     76void WorkerScriptDebugServer::removeListener(ScriptDebugListener* listener)
     77{
     78    if (!listener)
     79        return;
     80
     81    m_listeners.remove(listener);
     82    if (m_listeners.isEmpty())
     83        m_workerContext->script()->detachDebugger(this);
     84}
     85
     86void WorkerScriptDebugServer::runEventLoopWhilePaused()
     87{
     88    MessageQueueWaitResult result;
     89    do {
     90        result = m_workerContext->thread()->runLoop().runInMode(m_workerContext, WorkerDebuggerAgent::debuggerTaskMode);
     91    // Keep waiting until execution is resumed.
     92    } while (result != MessageQueueTerminated && !m_doneProcessingDebuggerEvents);
    5393}
    5494
  • trunk/Source/WebCore/bindings/js/WorkerScriptDebugServer.h

    r108344 r133281  
    5353    void interruptAndRunTask(PassOwnPtr<ScriptDebugServer::Task>);
    5454
     55    void recompileAllJSFunctions(Timer<ScriptDebugServer>*);
     56
    5557private:
    56     virtual void recompileAllJSFunctions(Timer<ScriptDebugServer>*) { }
    57     virtual ListenerSet* getListenersForGlobalObject(JSC::JSGlobalObject*) { return 0; }
     58    virtual ListenerSet* getListenersForGlobalObject(JSC::JSGlobalObject*) { return &m_listeners; }
    5859    virtual void didPause(JSC::JSGlobalObject*) { }
    5960    virtual void didContinue(JSC::JSGlobalObject*) { }
     61
     62    virtual bool isContentScript(JSC::ExecState*) { return false; }
     63
     64    virtual void runEventLoopWhilePaused();
     65
     66    WorkerContext* m_workerContext;
     67    ListenerSet m_listeners;
    6068};
    6169
Note: See TracChangeset for help on using the changeset viewer.