From 81b059576087d992a1b04f7e88eaca3f1ba0da40 Mon Sep 17 00:00:00 2001 From: kmccullo Date: Tue, 30 Oct 2007 18:15:58 +0000 Subject: [PATCH] Reviewed by Adam. * Drosera/win/DebuggerDocumentPlatform.cpp:Implemented much of the functionality that could not have existed previously without the new interfaces. (JSValueRefCreateWithBSTR): Added a helper function to easily convert from a BSTR to a JSValueRef. (DebuggerDocument::platformEvaluateScript): Implemented. (DebuggerDocument::getPlatformCurrentFunctionStack): Implemented. (DebuggerDocument::getPlatformLocalScopeVariableNamesForCallFrame): Implemented. (DebuggerDocument::platformValueForScopeVariableNamed): Implemented. * Drosera/win/HelperFunctions.h: Cleaned up some comments. * Drosera/win/ServerConnection.cpp: Added a helper function. (ServerConnection::getCallerFrame): * Drosera/win/ServerConnection.h: Added a helper function. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27261 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebKitTools/ChangeLog | 20 +++ .../Drosera/win/DebuggerDocumentPlatform.cpp | 146 +++++++++++++++++- WebKitTools/Drosera/win/HelperFunctions.h | 8 +- WebKitTools/Drosera/win/ServerConnection.cpp | 16 +- WebKitTools/Drosera/win/ServerConnection.h | 1 + 5 files changed, 175 insertions(+), 16 deletions(-) diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog index 7e058462aeef..b8aaa2e8a420 100644 --- a/WebKitTools/ChangeLog +++ b/WebKitTools/ChangeLog @@ -1,3 +1,23 @@ +2007-10-30 Kevin McCullough + + Reviewed by Adam. + + * Drosera/win/DebuggerDocumentPlatform.cpp:Implemented much of the + functionality that could not have existed previously without the new + interfaces. + (JSValueRefCreateWithBSTR): Added a helper function to easily convert + from a BSTR to a JSValueRef. + (DebuggerDocument::platformEvaluateScript): Implemented. + (DebuggerDocument::getPlatformCurrentFunctionStack): Implemented. + (DebuggerDocument::getPlatformLocalScopeVariableNamesForCallFrame): + Implemented. + (DebuggerDocument::platformValueForScopeVariableNamed): Implemented. + * Drosera/win/HelperFunctions.h: Cleaned up some comments. + * Drosera/win/ServerConnection.cpp: Added a helper function. + (ServerConnection::getCallerFrame): + * Drosera/win/ServerConnection.h: Added a helper function. + + 2007-10-29 Kevin McCullough updated reviewers for my previous changelog. diff --git a/WebKitTools/Drosera/win/DebuggerDocumentPlatform.cpp b/WebKitTools/Drosera/win/DebuggerDocumentPlatform.cpp index 882371908fd1..e9033330c8e8 100644 --- a/WebKitTools/Drosera/win/DebuggerDocumentPlatform.cpp +++ b/WebKitTools/Drosera/win/DebuggerDocumentPlatform.cpp @@ -30,7 +30,17 @@ #include "ServerConnection.h" +#include #include +#include +#include +#include + +JSValueRef JSValueRefCreateWithBSTR(JSContextRef context, BSTR string) +{ + JSRetainPtr jsString(Adopt, JSStringCreateWithBSTR(string)); + return JSValueMakeString(context, jsString.get()); +} // DebuggerDocument platform specific implementations @@ -49,26 +59,146 @@ void DebuggerDocument::platformStepInto() m_server->stepInto(); } -// FIXME: Some of the below functionality cannot be implemented until the WebScriptCallFrame Server works on windows. - -JSValueRef DebuggerDocument::platformEvaluateScript(JSContextRef context, JSStringRef /*script*/, int /*callFrame*/) +JSValueRef DebuggerDocument::platformEvaluateScript(JSContextRef context, JSStringRef script, int callFrame) { - return JSValueMakeUndefined(context); + HRESULT ret = S_OK; + + COMPtr cframe = m_server->getCallerFrame(callFrame); + if (!cframe) + return JSValueMakeUndefined(context); + + // Convert script to BSTR + BSTR scriptBSTR = JSStringCopyBSTR(script); + BSTR value = 0; + ret = cframe->stringByEvaluatingJavaScriptFromString(scriptBSTR, &value); + SysFreeString(scriptBSTR); + if (FAILED(ret)) { + SysFreeString(value); + return JSValueMakeUndefined(context); + } + + JSValueRef returnValue = JSValueRefCreateWithBSTR(context, value); + SysFreeString(value); + return returnValue; + } -void DebuggerDocument::getPlatformCurrentFunctionStack(JSContextRef /*context*/, Vector& /*currentStack*/) +void DebuggerDocument::getPlatformCurrentFunctionStack(JSContextRef context, Vector& currentStack) { + HRESULT ret = S_OK; + + COMPtr caller; + for (COMPtr frame = m_server->currentFrame(); frame; frame = caller) { + BSTR function = 0; + ret = frame->functionName(&function); + if (FAILED(ret)) { + SysFreeString(function); + return; + } + + ret = frame->caller(&caller); + if (FAILED(ret)) + return; + + bool needToFree = true; + if (!function) { + needToFree = false; + if (caller) + function = L"(anonymous function)"; + else + function = L"(global scope)"; + } + + currentStack.append(JSValueRefCreateWithBSTR(context, function)); + if (needToFree) + SysFreeString(function); + } } -void DebuggerDocument::getPlatformLocalScopeVariableNamesForCallFrame(JSContextRef /*context*/, int /*callFrame*/, Vector& /*variableNames*/) +void DebuggerDocument::getPlatformLocalScopeVariableNamesForCallFrame(JSContextRef context, int callFrame, Vector& variableNames) { + HRESULT ret = S_OK; + + COMPtr cframe = m_server->getCallerFrame(callFrame); + if (!cframe) + return; + + COMPtr scopeChain; + ret = cframe->scopeChain(&scopeChain); + if (FAILED(ret)) + return; + + VARIANT var; + VariantInit(&var); + ret = scopeChain->Next(1, &var, 0); // local is always first + if (FAILED(ret)) { + VariantClear(&var); + return; + } + + ASSERT(V_VT(&var) == VT_UNKNOWN); + COMPtr scope; + scope.query(V_UNKNOWN(&var)); + VariantClear(&var); + + COMPtr localScopeVariableNames; + ret = scope->variableNames(&localScopeVariableNames); + if (FAILED(ret)) + return; + + while (localScopeVariableNames->Next(1, &var, 0) == S_OK) { + ASSERT(V_VT(&var) == VT_BSTR); + BSTR variableName; + + variableName = V_BSTR(&var); + variableNames.append(JSValueRefCreateWithBSTR(context, variableName)); + + SysFreeString(variableName); + VariantClear(&var); + } } -JSValueRef DebuggerDocument::platformValueForScopeVariableNamed(JSContextRef context, JSStringRef /*key*/, int /*callFrame*/) +JSValueRef DebuggerDocument::platformValueForScopeVariableNamed(JSContextRef context, JSStringRef key, int callFrame) { - return JSValueMakeUndefined(context); + HRESULT ret = S_OK; + + COMPtr cframe = m_server->getCallerFrame(callFrame); + if (!cframe) + return JSValueMakeUndefined(context); + + COMPtr scopeChain; + ret = cframe->scopeChain(&scopeChain); + if (FAILED(ret)) + return JSValueMakeUndefined(context); + + VARIANT var; + VariantInit(&var); + + BSTR resultString = 0; + BSTR bstrKey = JSStringCopyBSTR(key); + while (scopeChain->Next(1, &var, 0) == S_OK && resultString == 0) { + ASSERT(V_VT(&var) == VT_UNKNOWN); + + COMPtr scope; + scope.query(V_UNKNOWN(&var)); + ret = scope->valueForVariable(bstrKey, &resultString); + VariantClear(&var); + + if (FAILED(ret)) { + SysFreeString(bstrKey); + SysFreeString(resultString); + return JSValueMakeUndefined(context); + } + } + SysFreeString(bstrKey); + + JSValueRef returnValue = JSValueRefCreateWithBSTR(context, resultString); + SysFreeString(resultString); + + return returnValue; } + void DebuggerDocument::platformLog(JSStringRef msg) { printf("%S\n", JSStringGetCharactersPtr(msg)); diff --git a/WebKitTools/Drosera/win/HelperFunctions.h b/WebKitTools/Drosera/win/HelperFunctions.h index 5f9095da346c..74f6c5b850c2 100644 --- a/WebKitTools/Drosera/win/HelperFunctions.h +++ b/WebKitTools/Drosera/win/HelperFunctions.h @@ -33,9 +33,7 @@ #include -// These functions are actually defined somewhere else but could not be linked for one reason or another. - -// This function was copied from WebCore BString.cpp I would lik to it if I could +// This function was copied from WebCore BString.cpp I would link to it if I could. BSTR cfStringToBSTR(CFStringRef cfstr) { BSTR bstr; @@ -57,9 +55,5 @@ BSTR cfStringToBSTR(CFStringRef cfstr) return bstr; } -//FIXME This is a class I believe I will need in the future but if not should be removed. -// It will include a Smart JSStringRef ptr -//#include - #endif //HelperFunctions_H diff --git a/WebKitTools/Drosera/win/ServerConnection.cpp b/WebKitTools/Drosera/win/ServerConnection.cpp index 893888312226..7348d8026fba 100644 --- a/WebKitTools/Drosera/win/ServerConnection.cpp +++ b/WebKitTools/Drosera/win/ServerConnection.cpp @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include @@ -99,6 +99,20 @@ IWebScriptCallFrame* ServerConnection::currentFrame() const return m_currentFrame; } +IWebScriptCallFrame* ServerConnection::getCallerFrame(int callFrame) const +{ + COMPtr cframe = currentFrame(); + COMPtr callerFrame; + for (int count = 0; count < callFrame; count++) { + if (FAILED(cframe->caller(&callerFrame))) + return 0; + + cframe = callerFrame; + } + + return cframe.get(); +} + // IUnknown -------------------------------------------------- HRESULT STDMETHODCALLTYPE ServerConnection::QueryInterface(REFIID riid, void** ppvObject) diff --git a/WebKitTools/Drosera/win/ServerConnection.h b/WebKitTools/Drosera/win/ServerConnection.h index 4b6bb3ac385d..7007c1bb92c7 100644 --- a/WebKitTools/Drosera/win/ServerConnection.h +++ b/WebKitTools/Drosera/win/ServerConnection.h @@ -53,6 +53,7 @@ public: void applicationTerminating(); void serverConnectionDidDie(); IWebScriptCallFrame* currentFrame() const; + IWebScriptCallFrame* getCallerFrame(int callFrame) const; // IUnknown HRESULT STDMETHODCALLTYPE QueryInterface( -- 2.36.0