Commit 4bfc7338 authored by timothy@apple.com's avatar timothy@apple.com

Fixes a regression where starting a debugging session in

        another Web Inspector window would not show any scripts.
        Also only attach the debugger to only the required Pages.

        https://bugs.webkit.org/show_bug.cgi?id=21708

        Reviewed by Darin Adler.

        * inspector/JavaScriptDebugServer.cpp:
        (WebCore::JavaScriptDebugServer::addListener): Add an assert and
        remove the call to willAddFirstListener(). Add a call to
        didAddListener().
        (WebCore::JavaScriptDebugServer::removeListener): Add an assert
        and call to didRemoveListener().
        (WebCore::JavaScriptDebugServer::pageCreated): Attach the debugger
        if there is a listener interested in the new Page.
        (WebCore::JavaScriptDebugServer::hasListenersInterestedInPage):
        Use hasGlobalListeners() instead of isEmpty().
        (WebCore::JavaScriptDebugServer::sourceParsed): Ditto.
        (WebCore::JavaScriptDebugServer::didAddListener): Added. Attach the
        debugger to the page if non-null, or all pages if page is null.
        (WebCore::JavaScriptDebugServer::didRemoveListener): Added. Detach
        the debugger only if there are no interested listeners.
        (WebCore::JavaScriptDebugServer::didRemoveLastListener): Remove the
        call to Page::setDebuggerForAllPages().
        * inspector/JavaScriptDebugServer.h:
        (WebCore::JavaScriptDebugServer::hasGlobalListeners): Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@37656 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent af9954f2
2008-10-17 Timothy Hatcher <timothy@apple.com>
Fixes a regression where starting a debugging session in
another Web Inspector window would not show any scripts.
Also only attach the debugger to only the required Pages.
https://bugs.webkit.org/show_bug.cgi?id=21708
Reviewed by Darin Adler.
* inspector/JavaScriptDebugServer.cpp:
(WebCore::JavaScriptDebugServer::addListener): Add an assert and
remove the call to willAddFirstListener(). Add a call to
didAddListener().
(WebCore::JavaScriptDebugServer::removeListener): Add an assert
and call to didRemoveListener().
(WebCore::JavaScriptDebugServer::pageCreated): Attach the debugger
if there is a listener interested in the new Page.
(WebCore::JavaScriptDebugServer::hasListenersInterestedInPage):
Use hasGlobalListeners() instead of isEmpty().
(WebCore::JavaScriptDebugServer::sourceParsed): Ditto.
(WebCore::JavaScriptDebugServer::didAddListener): Added. Attach the
debugger to the page if non-null, or all pages if page is null.
(WebCore::JavaScriptDebugServer::didRemoveListener): Added. Detach
the debugger only if there are no interested listeners.
(WebCore::JavaScriptDebugServer::didRemoveLastListener): Remove the
call to Page::setDebuggerForAllPages().
* inspector/JavaScriptDebugServer.h:
(WebCore::JavaScriptDebugServer::hasGlobalListeners): Added.
2008-10-15 Brett Wilson <brettw@chromium.org>
Reviewed by Timothy Hatcher.
......
......@@ -83,36 +83,42 @@ JavaScriptDebugServer::~JavaScriptDebugServer()
void JavaScriptDebugServer::addListener(JavaScriptDebugListener* listener)
{
if (!hasListeners())
willAddFirstListener();
ASSERT_ARG(listener, listener);
m_listeners.add(listener);
didAddListener(0);
}
void JavaScriptDebugServer::removeListener(JavaScriptDebugListener* listener)
{
ASSERT_ARG(listener, listener);
m_listeners.remove(listener);
didRemoveListener(0);
if (!hasListeners())
didRemoveLastListener();
}
void JavaScriptDebugServer::addListener(JavaScriptDebugListener* listener, Page* page)
{
ASSERT_ARG(listener, listener);
ASSERT_ARG(page, page);
if (!hasListeners())
willAddFirstListener();
pair<PageListenersMap::iterator, bool> result = m_pageListenersMap.add(page, 0);
if (result.second)
result.first->second = new ListenerSet;
ListenerSet* listeners = result.first->second;
ListenerSet* listeners = result.first->second;
listeners->add(listener);
didAddListener(page);
}
void JavaScriptDebugServer::removeListener(JavaScriptDebugListener* listener, Page* page)
{
ASSERT_ARG(listener, listener);
ASSERT_ARG(page, page);
PageListenersMap::iterator it = m_pageListenersMap.find(page);
......@@ -126,15 +132,17 @@ void JavaScriptDebugServer::removeListener(JavaScriptDebugListener* listener, Pa
delete listeners;
}
didRemoveListener(page);
if (!hasListeners())
didRemoveLastListener();
}
void JavaScriptDebugServer::pageCreated(Page* page)
{
if (!hasListeners())
return;
ASSERT_ARG(page, page);
if (!hasListenersInterestedInPage(page))
return;
page->setDebugger(this);
}
......@@ -142,7 +150,7 @@ bool JavaScriptDebugServer::hasListenersInterestedInPage(Page* page)
{
ASSERT_ARG(page, page);
if (!m_listeners.isEmpty())
if (hasGlobalListeners())
return true;
return m_pageListenersMap.contains(page);
......@@ -281,7 +289,7 @@ void JavaScriptDebugServer::sourceParsed(ExecState* exec, const SourceCode& sour
bool isError = errorLine != -1;
if (!m_listeners.isEmpty()) {
if (hasGlobalListeners()) {
if (isError)
dispatchFailedToParseSource(m_listeners, exec, source, errorLine, errorMessage);
else
......@@ -317,6 +325,7 @@ void JavaScriptDebugServer::dispatchFunctionToListeners(JavaScriptExecutionCallb
ASSERT(hasListeners());
WebCore::dispatchFunctionToListeners(m_listeners, callback);
if (ListenerSet* pageListeners = m_pageListenersMap.get(page)) {
ASSERT(!pageListeners->isEmpty());
WebCore::dispatchFunctionToListeners(*pageListeners, callback);
......@@ -509,7 +518,7 @@ void JavaScriptDebugServer::didReachBreakpoint(const DebuggerCallFrame& debugger
{
if (m_paused)
return;
ASSERT(m_currentCallFrame);
if (!m_currentCallFrame)
return;
......@@ -523,7 +532,7 @@ void JavaScriptDebugServer::recompileAllJSFunctions(Timer<JavaScriptDebugServer>
{
JSLock lock(false);
JSGlobalData* globalData = JSDOMWindow::commonJSGlobalData();
// If JavaScript is running, it's not safe to recompile, since we'll end
// up throwing away code that is live on the stack.
ASSERT(!globalData->dynamicGlobalObject);
......@@ -542,11 +551,11 @@ void JavaScriptDebugServer::recompileAllJSFunctions(Timer<JavaScriptDebugServer>
FunctionBodyMap functionBodies;
SourceProviderSet sourceProviders;
size_t size = functions.size();
for (size_t i = 0; i < size; ++i) {
JSFunction* function = functions[i];
FunctionBodyNode* oldBody = function->m_body.get();
pair<FunctionBodyMap::iterator, bool> result = functionBodies.add(oldBody, 0);
if (!result.second) {
......@@ -560,7 +569,7 @@ void JavaScriptDebugServer::recompileAllJSFunctions(Timer<JavaScriptDebugServer>
RefPtr<FunctionBodyNode> newBody = globalData->parser->parse<FunctionBodyNode>(exec, 0, sourceCode);
ASSERT(newBody);
newBody->finishParsing(oldBody->copyParameters(), oldBody->parameterCount());
result.first->second = newBody;
function->m_body = newBody.release();
......@@ -572,15 +581,29 @@ void JavaScriptDebugServer::recompileAllJSFunctions(Timer<JavaScriptDebugServer>
}
}
void JavaScriptDebugServer::willAddFirstListener()
void JavaScriptDebugServer::didAddListener(Page* page)
{
Page::setDebuggerForAllPages(this);
m_recompileTimer.startOneShot(0);
if (page)
page->setDebugger(this);
else
Page::setDebuggerForAllPages(this);
}
void JavaScriptDebugServer::didRemoveListener(Page* page)
{
if (hasGlobalListeners() || (page && hasListenersInterestedInPage(page)))
return;
if (page)
page->setDebugger(0);
else
Page::setDebuggerForAllPages(0);
}
void JavaScriptDebugServer::didRemoveLastListener()
{
Page::setDebuggerForAllPages(0);
m_doneProcessingDebuggerEvents = true;
m_recompileTimer.startOneShot(0);
}
......
......@@ -87,6 +87,7 @@ namespace WebCore {
~JavaScriptDebugServer();
bool hasListeners() const { return !m_listeners.isEmpty() || !m_pageListenersMap.isEmpty(); }
bool hasGlobalListeners() const { return !m_listeners.isEmpty(); }
bool hasListenersInterestedInPage(Page*);
void setJavaScriptPaused(const PageGroup&, bool paused);
......@@ -106,7 +107,8 @@ namespace WebCore {
virtual void didExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno);
virtual void didReachBreakpoint(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno);
void willAddFirstListener();
void didAddListener(Page*);
void didRemoveListener(Page*);
void didRemoveLastListener();
typedef HashMap<Page*, ListenerSet*> PageListenersMap;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment