Reviewed by Adam.
authorkmccullo <kmccullo@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Oct 2007 18:15:58 +0000 (18:15 +0000)
committerkmccullo <kmccullo@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Oct 2007 18:15:58 +0000 (18:15 +0000)
        * 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
WebKitTools/Drosera/win/DebuggerDocumentPlatform.cpp
WebKitTools/Drosera/win/HelperFunctions.h
WebKitTools/Drosera/win/ServerConnection.cpp
WebKitTools/Drosera/win/ServerConnection.h

index 7e058462aeeff783ffcba3adb0a12890367b4fe1..b8aaa2e8a420130cf54ede9e0e54f75743aca000 100644 (file)
@@ -1,3 +1,23 @@
+2007-10-30  Kevin McCullough  <kmccullough@apple.com>
+
+        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  <kmccullough@apple.com>
 
         updated reviewers for my previous changelog.
index 882371908fd1501c24ccf21d54f2b12bf650c908..e9033330c8e893b858431752d4e8b50da8235132 100644 (file)
 
 #include "ServerConnection.h"
 
+#include <JavaScriptCore/JSRetainPtr.h>
 #include <JavaScriptCore/JSStringRef.h>
+#include <JavaScriptCore/JSStringRefBSTR.h>
+#include <WebKit/IWebScriptCallFrame.h>
+#include <WebKit/IWebScriptScope.h>
+
+JSValueRef JSValueRefCreateWithBSTR(JSContextRef context, BSTR string)
+{
+    JSRetainPtr<JSStringRef> 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<IWebScriptCallFrame> 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<JSValueRef>& /*currentStack*/)
+void DebuggerDocument::getPlatformCurrentFunctionStack(JSContextRef context, Vector<JSValueRef>& currentStack)
 {
+    HRESULT ret = S_OK;
+
+    COMPtr<IWebScriptCallFrame> caller;
+    for (COMPtr<IWebScriptCallFrame> 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<JSValueRef>& /*variableNames*/)
+void DebuggerDocument::getPlatformLocalScopeVariableNamesForCallFrame(JSContextRef context, int callFrame, Vector<JSValueRef>& variableNames)
 {
+    HRESULT ret = S_OK;
+
+    COMPtr<IWebScriptCallFrame> cframe = m_server->getCallerFrame(callFrame);
+    if (!cframe)
+        return;
+
+    COMPtr<IEnumVARIANT> 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<IWebScriptScope> scope;
+    scope.query(V_UNKNOWN(&var));
+    VariantClear(&var);
+
+    COMPtr<IEnumVARIANT> 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<IWebScriptCallFrame> cframe = m_server->getCallerFrame(callFrame);
+    if (!cframe)
+        return JSValueMakeUndefined(context);
+
+    COMPtr<IEnumVARIANT> 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<IWebScriptScope> 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));
index 5f9095da346cb90ca37c22c6f50b1441fa42790f..74f6c5b850c20e89a96a4b3501c4422c0c2ab3fd 100644 (file)
@@ -33,9 +33,7 @@
 
 #include <wtf/RetainPtr.h>
 
-// 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 <JavaScriptCore/JSStringRef.h>
-
 #endif //HelperFunctions_H
 
index 89388831222609db4f143bc5bc7b440ef00a57ba..7348d8026fba557626046e99ed6c535ca2da363d 100644 (file)
@@ -34,7 +34,7 @@
 
 #include <JavaScriptCore/JSContextRef.h>
 #include <JavaScriptCore/JSRetainPtr.h>
-#include <JavaScriptCore/JSStringRefCOM.h>
+#include <JavaScriptCore/JSStringRefBSTR.h>
 #include <JavaScriptCore/RetainPtr.h>
 #include <WebKit/WebKit.h>
 
@@ -99,6 +99,20 @@ IWebScriptCallFrame* ServerConnection::currentFrame() const
     return m_currentFrame;
 }
 
+IWebScriptCallFrame* ServerConnection::getCallerFrame(int callFrame) const
+{
+    COMPtr<IWebScriptCallFrame> cframe = currentFrame();
+    COMPtr<IWebScriptCallFrame> 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)
index 4b6bb3ac385d8691ab62902c52f4b82147f2f780..7007c1bb92c79a381203f651e255f10a34a13488 100644 (file)
@@ -53,6 +53,7 @@ public:
     void applicationTerminating();
     void serverConnectionDidDie();
     IWebScriptCallFrame* currentFrame() const;
+    IWebScriptCallFrame* getCallerFrame(int callFrame) const;
 
     // IUnknown
     HRESULT STDMETHODCALLTYPE QueryInterface(