2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/unicode.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
33 struct _dispex_prop_t {
40 const builtin_prop_t *p;
45 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
47 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
49 DispatchEx *This = DISPATCHEX_THIS(iface);
51 if(IsEqualGUID(&IID_IUnknown, riid)) {
52 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
53 *ppv = _IDispatchEx_(This);
54 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
55 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
56 *ppv = _IDispatchEx_(This);
57 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
58 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
59 *ppv = _IDispatchEx_(This);
61 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
66 IUnknown_AddRef((IUnknown*)*ppv);
70 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
72 DispatchEx *This = DISPATCHEX_THIS(iface);
73 LONG ref = InterlockedIncrement(&This->ref);
75 TRACE("(%p) ref=%d\n", This, ref);
80 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
82 DispatchEx *This = DISPATCHEX_THIS(iface);
83 LONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p) ref=%d\n", This, ref);
90 for(prop = This->props; prop < This->props+This->prop_cnt; prop++) {
91 if(prop->type == PROP_VARIANT)
92 VariantClear(&prop->u.var);
93 heap_free(prop->name);
95 heap_free(This->props);
96 script_release(This->ctx);
98 if(This->builtin_info->destructor)
99 This->builtin_info->destructor(This);
107 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
109 DispatchEx *This = DISPATCHEX_THIS(iface);
111 TRACE("(%p)->(%p)\n", This, pctinfo);
117 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
118 LCID lcid, ITypeInfo **ppTInfo)
120 DispatchEx *This = DISPATCHEX_THIS(iface);
121 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
125 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
126 LPOLESTR *rgszNames, UINT cNames,
127 LCID lcid, DISPID *rgDispId)
129 DispatchEx *This = DISPATCHEX_THIS(iface);
133 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
136 for(i=0; i < cNames; i++) {
137 hres = IDispatchEx_GetDispID(_IDispatchEx_(This), rgszNames[i], 0, rgDispId+i);
145 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
146 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
147 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
149 DispatchEx *This = DISPATCHEX_THIS(iface);
151 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
152 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
154 return IDispatchEx_InvokeEx(_IDispatchEx_(This), dispIdMember, lcid, wFlags,
155 pDispParams, pVarResult, pExcepInfo, NULL);
158 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
160 DispatchEx *This = DISPATCHEX_THIS(iface);
161 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
165 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
166 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
168 DispatchEx *This = DISPATCHEX_THIS(iface);
169 FIXME("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
173 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
175 DispatchEx *This = DISPATCHEX_THIS(iface);
176 FIXME("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
180 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
182 DispatchEx *This = DISPATCHEX_THIS(iface);
183 FIXME("(%p)->(%x)\n", This, id);
187 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
189 DispatchEx *This = DISPATCHEX_THIS(iface);
190 FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
194 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
196 DispatchEx *This = DISPATCHEX_THIS(iface);
197 FIXME("(%p)->(%x %p)\n", This, id, pbstrName);
201 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
203 DispatchEx *This = DISPATCHEX_THIS(iface);
204 FIXME("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
208 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
210 DispatchEx *This = DISPATCHEX_THIS(iface);
211 FIXME("(%p)->(%p)\n", This, ppunk);
215 #undef DISPATCHEX_THIS
217 static IDispatchExVtbl DispatchExVtbl = {
218 DispatchEx_QueryInterface,
221 DispatchEx_GetTypeInfoCount,
222 DispatchEx_GetTypeInfo,
223 DispatchEx_GetIDsOfNames,
225 DispatchEx_GetDispID,
227 DispatchEx_DeleteMemberByName,
228 DispatchEx_DeleteMemberByDispID,
229 DispatchEx_GetMemberProperties,
230 DispatchEx_GetMemberName,
231 DispatchEx_GetNextDispID,
232 DispatchEx_GetNameSpaceParent
235 static HRESULT jsdisp_set_prot_prop(DispatchEx *dispex, DispatchEx *prototype)
239 if(!dispex->props[1].name)
240 return E_OUTOFMEMORY;
242 dispex->props[1].type = PROP_VARIANT;
243 dispex->props[1].flags = 0;
245 var = &dispex->props[1].u.var;
246 V_VT(var) = VT_DISPATCH;
247 V_DISPATCH(var) = (IDispatch*)_IDispatchEx_(prototype);
252 static HRESULT init_dispex(DispatchEx *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *prototype)
254 static const WCHAR prototypeW[] = {'p','r','o','t','o','t','y','p','e',0};
256 TRACE("%p (%p)\n", dispex, prototype);
258 dispex->lpIDispatchExVtbl = &DispatchExVtbl;
260 dispex->builtin_info = builtin_info;
262 dispex->props = heap_alloc((dispex->buf_size=4) * sizeof(dispex_prop_t));
264 return E_OUTOFMEMORY;
266 dispex->prototype = prototype;
268 IDispatchEx_AddRef(_IDispatchEx_(prototype));
270 dispex->prop_cnt = 2;
271 dispex->props[0].name = NULL;
272 dispex->props[0].flags = 0;
273 if(builtin_info->value_prop.invoke) {
274 dispex->props[0].type = PROP_BUILTIN;
275 dispex->props[0].u.p = &builtin_info->value_prop;
277 dispex->props[0].type = PROP_DELETED;
280 dispex->props[1].type = PROP_DELETED;
281 dispex->props[1].name = SysAllocString(prototypeW);
282 dispex->props[1].flags = 0;
287 hres = jsdisp_set_prot_prop(dispex, prototype);
289 IDispatchEx_Release(_IDispatchEx_(dispex));
300 static const builtin_info_t dispex_info = {
308 HRESULT create_dispex(script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *prototype, DispatchEx **dispex)
313 ret = heap_alloc_zero(sizeof(DispatchEx));
315 return E_OUTOFMEMORY;
317 hres = init_dispex(ret, ctx, builtin_info ? builtin_info : &dispex_info, prototype);