Commit c8a33e45 authored by timothy@apple.com's avatar timothy@apple.com

Add debugger related functions to the InspectorController and

expose them to the JavaScript side of InspectorController.

Reviewed by Geoff Garen.

* page/InspectorController.cpp:
(WebCore::jsStringRef): Added helper to convert a UString to a JSStringRef.
(WebCore::currentCallFrame): Call InspectorController::currentCallFrame.
(WebCore::pauseInDebugger): Call InspectorController::pauseInDebugger.
(WebCore::resumeDebugger): Call InspectorController::resumeDebugger.
(WebCore::stepOverStatementInDebugger): Call InspectorController::stepOverStatementInDebugger.
(WebCore::stepIntoStatementInDebugger): Call InspectorController::stepIntoStatementInDebugger.
(WebCore::stepOutOfFunctionInDebugger): Call InspectorController::stepOutOfFunctionInDebugger.
(WebCore::addBreakpoint): Call InspectorController::addBreakpoint.
(WebCore::removeBreakpoint): Call InspectorController::removeBreakpoint.
(WebCore::InspectorController::windowScriptObjectAvailable): Add the new functions to the
InspectorController JavaScript class.
(WebCore::InspectorController::startDebuggingAndReloadInspectedPage): Clear breakpoints.
(WebCore::InspectorController::currentCallFrame): Return the currentCallFrame from the
JavaScriptDebugServer.
(WebCore::InspectorController::pauseInDebugger): Call JavaScriptDebugServer's pauseOnNextStatement.
(WebCore::InspectorController::resumeDebugger): Call JavaScriptDebugServer's resume.
(WebCore::InspectorController::stepOverStatementInDebugger):  Call JavaScriptDebugServer's stepOverStatement.
(WebCore::InspectorController::stepIntoStatementInDebugger): Call JavaScriptDebugServer's stepIntoStatement.
(WebCore::InspectorController::stepOutOfFunctionInDebugger): Call JavaScriptDebugServer's stepOutOfFunction.
(WebCore::InspectorController::addBreakpoint): Call JavaScriptDebugServer's addBreakpoint.
(WebCore::InspectorController::removeBreakpoint): Call JavaScriptDebugServer's removeBreakpoint.
(WebCore::InspectorController::didParseSource): Call into the Inspector's JavaScript.
(WebCore::InspectorController::failedToParseSource): Ditto.
(WebCore::InspectorController::didPause): Ditto.
* page/InspectorController.h: Add new functions.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33405 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 12d60aab
2008-05-13 Timothy Hatcher <timothy@apple.com>
Add debugger related functions to the InspectorController and
expose them to the JavaScript side of InspectorController.
Reviewed by Geoff Garen.
* page/InspectorController.cpp:
(WebCore::jsStringRef): Added helper to convert a UString to a JSStringRef.
(WebCore::currentCallFrame): Call InspectorController::currentCallFrame.
(WebCore::pauseInDebugger): Call InspectorController::pauseInDebugger.
(WebCore::resumeDebugger): Call InspectorController::resumeDebugger.
(WebCore::stepOverStatementInDebugger): Call InspectorController::stepOverStatementInDebugger.
(WebCore::stepIntoStatementInDebugger): Call InspectorController::stepIntoStatementInDebugger.
(WebCore::stepOutOfFunctionInDebugger): Call InspectorController::stepOutOfFunctionInDebugger.
(WebCore::addBreakpoint): Call InspectorController::addBreakpoint.
(WebCore::removeBreakpoint): Call InspectorController::removeBreakpoint.
(WebCore::InspectorController::windowScriptObjectAvailable): Add the new functions to the
InspectorController JavaScript class.
(WebCore::InspectorController::startDebuggingAndReloadInspectedPage): Clear breakpoints.
(WebCore::InspectorController::currentCallFrame): Return the currentCallFrame from the
JavaScriptDebugServer.
(WebCore::InspectorController::pauseInDebugger): Call JavaScriptDebugServer's pauseOnNextStatement.
(WebCore::InspectorController::resumeDebugger): Call JavaScriptDebugServer's resume.
(WebCore::InspectorController::stepOverStatementInDebugger): Call JavaScriptDebugServer's stepOverStatement.
(WebCore::InspectorController::stepIntoStatementInDebugger): Call JavaScriptDebugServer's stepIntoStatement.
(WebCore::InspectorController::stepOutOfFunctionInDebugger): Call JavaScriptDebugServer's stepOutOfFunction.
(WebCore::InspectorController::addBreakpoint): Call JavaScriptDebugServer's addBreakpoint.
(WebCore::InspectorController::removeBreakpoint): Call JavaScriptDebugServer's removeBreakpoint.
(WebCore::InspectorController::didParseSource): Call into the Inspector's JavaScript.
(WebCore::InspectorController::failedToParseSource): Ditto.
(WebCore::InspectorController::didPause): Ditto.
* page/InspectorController.h: Add new functions.
2008-05-13 Timothy Hatcher <timothy@apple.com>
Implements more debugger APIs on JavaScriptDebugServer and reduces
......@@ -46,9 +46,11 @@
#include "GraphicsContext.h"
#include "HTMLFrameOwnerElement.h"
#include "InspectorClient.h"
#include "JavaScriptCallFrame.h"
#include "JSDOMWindow.h"
#include "JSInspectedObjectWrapper.h"
#include "JSInspectorCallbackWrapper.h"
#include "JSJavaScriptCallFrame.h"
#include "JSNode.h"
#include "JSRange.h"
#include "JavaScriptDebugServer.h"
......@@ -89,6 +91,12 @@ static JSRetainPtr<JSStringRef> jsStringRef(const String& str)
return JSRetainPtr<JSStringRef>(Adopt, JSStringCreateWithCharacters(str.characters(), str.length()));
}
static JSRetainPtr<JSStringRef> jsStringRef(const UString& str)
{
JSLock lock;
return JSRetainPtr<JSStringRef>(toRef(str.rep()));
}
static String toString(JSContextRef context, JSValueRef value, JSValueRef* exception)
{
ASSERT_ARG(value, value);
......@@ -777,6 +785,121 @@ static JSValueRef debuggerAttached(JSContextRef ctx, JSObjectRef /*function*/, J
return JSValueMakeBoolean(ctx, controller->debuggerAttached());
}
static JSValueRef currentCallFrame(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
JavaScriptCallFrame* callFrame = controller->currentCallFrame();
if (!callFrame->isValid())
return JSValueMakeUndefined(ctx);
ExecState* globalExec = callFrame->execState()->lexicalGlobalObject()->globalExec();
JSLock lock;
return toRef(JSInspectedObjectWrapper::wrap(globalExec, toJS(toJS(ctx), callFrame)));
}
static JSValueRef pauseInDebugger(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
controller->pauseInDebugger();
return JSValueMakeUndefined(ctx);
}
static JSValueRef resumeDebugger(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
controller->resumeDebugger();
return JSValueMakeUndefined(ctx);
}
static JSValueRef stepOverStatementInDebugger(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
controller->stepOverStatementInDebugger();
return JSValueMakeUndefined(ctx);
}
static JSValueRef stepIntoStatementInDebugger(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
controller->stepIntoStatementInDebugger();
return JSValueMakeUndefined(ctx);
}
static JSValueRef stepOutOfFunctionInDebugger(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
controller->stepOutOfFunctionInDebugger();
return JSValueMakeUndefined(ctx);
}
static JSValueRef addBreakpoint(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
if (argumentCount < 2)
return JSValueMakeUndefined(ctx);
double sourceID = JSValueToNumber(ctx, arguments[0], exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
double lineNumber = JSValueToNumber(ctx, arguments[1], exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
controller->addBreakpoint(static_cast<int>(sourceID), static_cast<unsigned>(lineNumber));
return JSValueMakeUndefined(ctx);
}
static JSValueRef removeBreakpoint(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
if (!controller)
return JSValueMakeUndefined(ctx);
if (argumentCount < 2)
return JSValueMakeUndefined(ctx);
double sourceID = JSValueToNumber(ctx, arguments[0], exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
double lineNumber = JSValueToNumber(ctx, arguments[1], exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
controller->removeBreakpoint(static_cast<int>(sourceID), static_cast<unsigned>(lineNumber));
return JSValueMakeUndefined(ctx);
}
#pragma mark -
#pragma mark InspectorController Class
......@@ -1010,6 +1133,14 @@ void InspectorController::windowScriptObjectAvailable()
{ "startDebuggingAndReloadInspectedPage", WebCore::startDebuggingAndReloadInspectedPage, kJSPropertyAttributeNone },
{ "stopDebugging", WebCore::stopDebugging, kJSPropertyAttributeNone },
{ "debuggerAttached", WebCore::debuggerAttached, kJSPropertyAttributeNone },
{ "currentCallFrame", WebCore::currentCallFrame, kJSPropertyAttributeNone },
{ "pauseInDebugger", WebCore::pauseInDebugger, kJSPropertyAttributeNone },
{ "resumeDebugger", WebCore::resumeDebugger, kJSPropertyAttributeNone },
{ "stepOverStatementInDebugger", WebCore::stepOverStatementInDebugger, kJSPropertyAttributeNone },
{ "stepIntoStatementInDebugger", WebCore::stepIntoStatementInDebugger, kJSPropertyAttributeNone },
{ "stepOutOfFunctionInDebugger", WebCore::stepOutOfFunctionInDebugger, kJSPropertyAttributeNone },
{ "addBreakpoint", WebCore::addBreakpoint, kJSPropertyAttributeNone },
{ "removeBreakpoint", WebCore::removeBreakpoint, kJSPropertyAttributeNone },
{ 0, 0, 0 }
};
......@@ -1877,6 +2008,7 @@ void InspectorController::startDebuggingAndReloadInspectedPage()
{
JavaScriptDebugServer::shared().addListener(this, m_inspectedPage);
m_debuggerAttached = true;
JavaScriptDebugServer::shared().clearBreakpoints();
m_inspectedPage->mainFrame()->loader()->reload();
}
......@@ -1886,6 +2018,56 @@ void InspectorController::stopDebugging()
m_debuggerAttached = false;
}
JavaScriptCallFrame* InspectorController::currentCallFrame() const
{
return JavaScriptDebugServer::shared().currentCallFrame();
}
void InspectorController::pauseInDebugger()
{
if (!m_debuggerAttached)
return;
JavaScriptDebugServer::shared().pauseOnNextStatement();
}
void InspectorController::resumeDebugger()
{
if (!m_debuggerAttached)
return;
JavaScriptDebugServer::shared().resume();
}
void InspectorController::stepOverStatementInDebugger()
{
if (!m_debuggerAttached)
return;
JavaScriptDebugServer::shared().stepOverStatement();
}
void InspectorController::stepIntoStatementInDebugger()
{
if (!m_debuggerAttached)
return;
JavaScriptDebugServer::shared().stepIntoStatement();
}
void InspectorController::stepOutOfFunctionInDebugger()
{
if (!m_debuggerAttached)
return;
JavaScriptDebugServer::shared().stepOutOfFunction();
}
void InspectorController::addBreakpoint(int sourceID, unsigned lineNumber)
{
JavaScriptDebugServer::shared().addBreakpoint(sourceID, lineNumber);
}
void InspectorController::removeBreakpoint(int sourceID, unsigned lineNumber)
{
JavaScriptDebugServer::shared().removeBreakpoint(sourceID, lineNumber);
}
static void drawOutlinedRect(GraphicsContext& context, const IntRect& rect, const Color& fillColor)
{
static const int outlineThickness = 1;
......@@ -2002,16 +2184,35 @@ bool InspectorController::handleException(JSContextRef context, JSValueRef excep
#pragma mark -
#pragma mark JavaScriptDebugListener functions
void InspectorController::didParseSource(const UString& /*source*/, int /*startingLineNumber*/, const UString& /*sourceURL*/, int /*sourceID*/)
void InspectorController::didParseSource(const UString& source, int startingLineNumber, const UString& sourceURL, int sourceID)
{
JSValueRef sourceIDValue = JSValueMakeNumber(m_scriptContext, sourceID);
JSValueRef sourceURLValue = JSValueMakeString(m_scriptContext, jsStringRef(sourceURL).get());
JSValueRef sourceValue = JSValueMakeString(m_scriptContext, jsStringRef(source).get());
JSValueRef startingLineNumberValue = JSValueMakeNumber(m_scriptContext, startingLineNumber);
JSValueRef exception = 0;
JSValueRef arguments[] = { sourceIDValue, sourceURLValue, sourceValue, startingLineNumberValue };
callFunction(m_scriptContext, m_scriptObject, "parsedScriptSource", 4, arguments, exception);
}
void InspectorController::failedToParseSource(const UString& /*source*/, int /*startingLineNumber*/, const UString& /*sourceURL*/, int /*errorLine*/, const UString& /*errorMessage*/)
void InspectorController::failedToParseSource(const UString& source, int startingLineNumber, const UString& sourceURL, int errorLine, const UString& errorMessage)
{
JSValueRef sourceURLValue = JSValueMakeString(m_scriptContext, jsStringRef(sourceURL).get());
JSValueRef sourceValue = JSValueMakeString(m_scriptContext, jsStringRef(source).get());
JSValueRef startingLineNumberValue = JSValueMakeNumber(m_scriptContext, startingLineNumber);
JSValueRef errorLineValue = JSValueMakeNumber(m_scriptContext, errorLine);
JSValueRef errorMessageValue = JSValueMakeString(m_scriptContext, jsStringRef(errorMessage).get());
JSValueRef exception = 0;
JSValueRef arguments[] = { sourceURLValue, sourceValue, startingLineNumberValue, errorLineValue, errorMessageValue };
callFunction(m_scriptContext, m_scriptObject, "failedToParseScriptSource", 5, arguments, exception);
}
void InspectorController::didPause()
{
JSValueRef exception = 0;
callFunction(m_scriptContext, m_scriptObject, "pausedScript", 0, 0, exception);
}
} // namespace WebCore
......@@ -47,6 +47,7 @@ class Database;
class DocumentLoader;
class GraphicsContext;
class InspectorClient;
class JavaScriptCallFrame;
class Node;
class Page;
class ResourceResponse;
......@@ -134,6 +135,18 @@ public:
void stopDebugging();
bool debuggerAttached() const { return m_debuggerAttached; }
JavaScriptCallFrame* currentCallFrame() const;
void addBreakpoint(int sourceID, unsigned lineNumber);
void removeBreakpoint(int sourceID, unsigned lineNumber);
void pauseInDebugger();
void resumeDebugger();
void stepOverStatementInDebugger();
void stepIntoStatementInDebugger();
void stepOutOfFunctionInDebugger();
void drawNodeHighlight(GraphicsContext&) const;
private:
......
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