Reviewed by Adam.
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 22:27:43 +0000 (22:27 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 22:27:43 +0000 (22:27 +0000)
        Use COMEnumVariant in WebScriptCallFrame and WebScriptScope.

        * WebScriptCallFrame.cpp:
        (WebScriptCallFrame::scopeChain):
        * WebScriptScope.cpp:
        (WebScriptScope::variableNames):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28080 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/win/ChangeLog
WebKit/win/WebScriptCallFrame.cpp
WebKit/win/WebScriptScope.cpp

index a73cb2fcf0d38354ef3f5a2c52dea82e0bd83bc8..355cce789f7f97522ec24203777ba2214f32de8b 100644 (file)
@@ -1,3 +1,14 @@
+2007-11-27  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        Use COMEnumVariant in WebScriptCallFrame and WebScriptScope.
+        
+        * WebScriptCallFrame.cpp:
+        (WebScriptCallFrame::scopeChain):
+        * WebScriptScope.cpp:
+        (WebScriptScope::variableNames):
+
 2007-11-27  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Adam.
index caa31eaaa36a6530c74393869a550f48776d5df1..72dfb240882eb7203328babde32c11a5e31e1f73 100644 (file)
@@ -30,6 +30,7 @@
 #include "WebKitDLL.h"
 #include "WebScriptCallFrame.h"
 
+#include "COMEnumVariant.h"
 #include "IWebScriptScope.h"
 #include "Function.h"
 #include "WebScriptScope.h"
 
 using namespace KJS;
 
-// EnumScopes -----------------------------------------------------------------
-
-class EnumScopes : public IEnumVARIANT {
-public:
-    static EnumScopes* createInstance(ScopeChain chain);
-
-private:
-    EnumScopes(ScopeChain chain)
-        : m_refCount(0)
-        , m_chain(chain)
-        , m_current(chain.begin())
-    {
-    }
-
-public:
-    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void** ppvObject);
-    virtual ULONG STDMETHODCALLTYPE AddRef();
-    virtual ULONG STDMETHODCALLTYPE Release();
-    virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT* rgVar, ULONG* pCeltFetched);
-    virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt);
-    virtual HRESULT STDMETHODCALLTYPE Reset(void);
-    virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT**);
-
-private:
-    ULONG m_refCount;
-    ScopeChain m_chain;
-    ScopeChainIterator m_current;
-};
-
-EnumScopes* EnumScopes::createInstance(ScopeChain chain)
-{
-    EnumScopes* instance = new EnumScopes(chain);
-    instance->AddRef();
-    return instance;
-}
-
-HRESULT STDMETHODCALLTYPE EnumScopes::QueryInterface(REFIID riid, void** ppvObject)
-{
-    *ppvObject = 0;
-    if (IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IEnumVARIANT))
-        *ppvObject = this;
-    else
-        return E_NOINTERFACE;
-
-    AddRef();
-    return S_OK;
-}
-
-ULONG STDMETHODCALLTYPE EnumScopes::AddRef()
-{
-    return ++m_refCount;
-}
-
-ULONG STDMETHODCALLTYPE EnumScopes::Release()
-{
-    ULONG newRef = --m_refCount;
-    if (!newRef)
-        delete(this);
-    return newRef;
-}
-
-HRESULT STDMETHODCALLTYPE EnumScopes::Next(ULONG celt, VARIANT* rgVar, ULONG* pCeltFetched)
-{
-    if (pCeltFetched)
-        *pCeltFetched = 0;
-    if (!rgVar)
-        return E_POINTER;
-    VariantInit(rgVar);
-    if (!celt || celt > 1)
-        return S_FALSE;
-    if (m_current == m_chain.end())
-        return S_FALSE;
-
-    // Create a WebScriptScope from the m_current then put it in an IUnknown.
-    COMPtr<IWebScriptScope> scope(AdoptCOM, WebScriptScope::createInstance(*m_current));
-    ++m_current;
-    if (!scope)
-        return E_FAIL;
-
-    V_VT(rgVar) = VT_UNKNOWN;
-    V_UNKNOWN(rgVar) = scope.releaseRef();
-
-    if (pCeltFetched)
-        *pCeltFetched = 1;
-    return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE EnumScopes::Skip(ULONG celt)
-{
-    for (ULONG i = 0; i < celt; ++i)
-        ++m_current;
-    return (m_current != m_chain.end()) ? S_OK : S_FALSE;
-}
-
-HRESULT STDMETHODCALLTYPE EnumScopes::Reset(void)
-{
-    m_current = m_chain.begin();
-    return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE EnumScopes::Clone(IEnumVARIANT**)
-{
-    return E_NOTIMPL;
-}
-
 // WebScriptCallFrame -----------------------------------------------------------
 
 WebScriptCallFrame::WebScriptCallFrame(ExecState* state, IWebScriptCallFrame* caller)
@@ -213,6 +109,8 @@ HRESULT STDMETHODCALLTYPE WebScriptCallFrame::caller(
     return m_caller.copyRefTo(callFrame);
 }
 
+template<> struct COMVariantSetter<JSObject*> : COMIUnknownVariantSetter<WebScriptScope, JSObject*> {};
+
 HRESULT STDMETHODCALLTYPE WebScriptCallFrame::scopeChain(
     /* [out, retval] */ IEnumVARIANT** result)
 {
@@ -220,8 +118,7 @@ HRESULT STDMETHODCALLTYPE WebScriptCallFrame::scopeChain(
         return E_POINTER;
 
     // FIXME: If there is no current body do we need to make scope chain from the global object?
-
-    *result = EnumScopes::createInstance(m_state->scopeChain());
+    *result = COMEnumVariant<ScopeChain>::createInstance(m_state->scopeChain());
 
     return S_OK;
 }
index 5c1d7a150b54880dad18a37ae184a626172f0c20..d7228db3f3ebf6eace7f8b906b794e22bb5adabf 100644 (file)
@@ -30,6 +30,7 @@
 #include "WebKitDLL.h"
 #include "WebScriptScope.h"
 
+#include "COMEnumVariant.h"
 #include "WebScriptCallFrame.h"
 
 #include <memory>
 using namespace KJS;
 using namespace std;
 
-// EnumVariables -----------------------------------------------------------------
-
-class EnumVariables : public IEnumVARIANT {
-public:
-    static EnumVariables* createInstance(auto_ptr<PropertyNameArray>);
-
-private:
-    EnumVariables(auto_ptr<PropertyNameArray> variableNames)
-        : m_refCount(0)
-        , m_names(variableNames.release())
-        , m_current(m_names->begin())
-    {
-    }
-
-public:
-    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void** ppvObject);
-    virtual ULONG STDMETHODCALLTYPE AddRef();
-    virtual ULONG STDMETHODCALLTYPE Release();
-    virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT* rgVar, ULONG* pCeltFetched);
-    virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt);
-    virtual HRESULT STDMETHODCALLTYPE Reset(void);
-    virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT**);
-
-private:
-    ULONG m_refCount;
-    OwnPtr<PropertyNameArray> m_names;
-    PropertyNameArrayIterator m_current;
-};
-
-EnumVariables* EnumVariables::createInstance(auto_ptr<PropertyNameArray> variableNames)
-{
-    EnumVariables* instance = new EnumVariables(variableNames);
-    instance->AddRef();
-    return instance;
-}
-
-HRESULT STDMETHODCALLTYPE EnumVariables::QueryInterface(REFIID riid, void** ppvObject)
-{
-    *ppvObject = 0;
-    if (IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IEnumVARIANT))
-        *ppvObject = this;
-    else
-        return E_NOINTERFACE;
-
-    AddRef();
-    return S_OK;
-}
-
-ULONG STDMETHODCALLTYPE EnumVariables::AddRef()
-{
-    return ++m_refCount;
-}
-
-ULONG STDMETHODCALLTYPE EnumVariables::Release()
-{
-    ULONG newRef = --m_refCount;
-    if (!newRef)
-        delete(this);
-    return newRef;
-}
-
-HRESULT STDMETHODCALLTYPE EnumVariables::Next(ULONG celt, VARIANT* rgVar, ULONG* pCeltFetched)
-{
-    if (pCeltFetched)
-        *pCeltFetched = 0;
-    if (!rgVar)
-        return E_POINTER;
-    VariantInit(rgVar);
-    if (!celt || celt > 1)
-        return S_FALSE;
-    if (m_current == m_names->end())
-        return S_FALSE;
-
-    V_VT(rgVar) = VT_BSTR;
-    V_BSTR(rgVar) = WebCore::BString(*m_current).release();
-    ++m_current;
-
-    if (pCeltFetched)
-        *pCeltFetched = 1;
-    return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE EnumVariables::Skip(ULONG celt)
-{
-    for (ULONG i = 0; i < celt; ++i)
-        ++m_current;
-    return (m_current != m_names->end()) ? S_OK : S_FALSE;
-}
-
-HRESULT STDMETHODCALLTYPE EnumVariables::Reset(void)
-{
-    m_current = 0;
-    return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE EnumVariables::Clone(IEnumVARIANT**)
-{
-    return E_NOTIMPL;
-}
-
 // WebScriptScope ------------------------------------------------------------
 
 WebScriptScope::WebScriptScope(JSObject* scope)
@@ -196,24 +97,35 @@ ULONG STDMETHODCALLTYPE WebScriptScope::Release(void)
     return newRef;
 }
 
+template<> struct COMVariantSetter<Identifier>
+{
+    static void setVariant(VARIANT* variant, const Identifier& value)
+    {
+        ASSERT(V_VT(variant) == VT_EMPTY);
+
+        V_VT(variant) = VT_BSTR;
+        V_BSTR(variant) = WebCore::BString(reinterpret_cast<const wchar_t*>(value.data()), value.size()).release();
+    }
+};
+
 // WebScriptScope ------------------------------------------------------------
 
 HRESULT STDMETHODCALLTYPE WebScriptScope::variableNames(
     /* [in] */ IWebScriptCallFrame* frame,
     /* [out, retval] */ IEnumVARIANT** variableNames)
 {
-    if (!frame)
-        return E_FAIL;
-
     if (!variableNames)
         return E_POINTER;
 
     *variableNames = 0;
 
-    auto_ptr<PropertyNameArray> props(new PropertyNameArray);
-    m_scope->getPropertyNames(frame->impl()->state(), *(props.get()));
+    if (!frame)
+        return E_FAIL;
+
+    PropertyNameArray propertyNames;
+    m_scope->getPropertyNames(frame->impl()->state(), propertyNames);
 
-    *variableNames = EnumVariables::createInstance(props);
+    *variableNames = COMEnumVariant<PropertyNameArray>::adopt(propertyNames);
 
     return S_OK;
 }