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);
27 * This IID is used to get DispatchEx objecto from interface.
28 * We might consider using private insteface instead.
30 static const IID IID_IDispatchJS =
31 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
33 #define FDEX_VERSION_MASK 0xf0000000
42 struct _dispex_prop_t {
49 const builtin_prop_t *p;
54 static inline DISPID prop_to_id(DispatchEx *This, dispex_prop_t *prop)
56 return prop - This->props;
59 static inline dispex_prop_t *get_prop(DispatchEx *This, DISPID id)
61 if(id < 0 || id >= This->prop_cnt || This->props[id].type == PROP_DELETED)
64 return This->props+id;
67 static DWORD get_flags(DispatchEx *This, dispex_prop_t *prop)
69 if(prop->type == PROP_PROTREF) {
70 dispex_prop_t *parent = get_prop(This->prototype, prop->u.ref);
72 prop->type = PROP_DELETED;
76 return get_flags(This->prototype, parent);
82 static const builtin_prop_t *find_builtin_prop(DispatchEx *This, const WCHAR *name)
84 int min = 0, max, i, r;
86 max = This->builtin_info->props_cnt-1;
90 r = strcmpW(name, This->builtin_info->props[i].name);
92 return This->builtin_info->props + i;
103 static dispex_prop_t *alloc_prop(DispatchEx *This, const WCHAR *name, prop_type_t type, DWORD flags)
107 if(This->buf_size == This->prop_cnt) {
108 dispex_prop_t *tmp = heap_realloc(This->props, (This->buf_size<<=1)*sizeof(*This->props));
114 ret = This->props + This->prop_cnt++;
117 ret->name = heap_strdupW(name);
124 static dispex_prop_t *alloc_protref(DispatchEx *This, const WCHAR *name, DWORD ref)
128 ret = alloc_prop(This, name, PROP_PROTREF, 0);
136 static HRESULT find_prop_name(DispatchEx *This, const WCHAR *name, dispex_prop_t **ret)
138 const builtin_prop_t *builtin;
141 for(prop = This->props; prop < This->props+This->prop_cnt; prop++) {
142 if(prop->name && !strcmpW(prop->name, name)) {
148 builtin = find_builtin_prop(This, name);
150 prop = alloc_prop(This, name, PROP_BUILTIN, builtin->flags);
152 return E_OUTOFMEMORY;
163 static HRESULT find_prop_name_prot(DispatchEx *This, const WCHAR *name, dispex_prop_t **ret)
168 hres = find_prop_name(This, name, &prop);
176 if(This->prototype) {
177 hres = find_prop_name_prot(This->prototype, name, &prop);
181 prop = alloc_protref(This, prop->name, prop - This->prototype->props);
183 return E_OUTOFMEMORY;
193 static HRESULT ensure_prop_name(DispatchEx *This, const WCHAR *name, BOOL search_prot, DWORD create_flags, dispex_prop_t **ret)
199 hres = find_prop_name_prot(This, name, &prop);
201 hres = find_prop_name(This, name, &prop);
202 if(SUCCEEDED(hres) && !prop) {
203 TRACE("creating prop %s\n", debugstr_w(name));
205 prop = alloc_prop(This, name, PROP_VARIANT, create_flags);
207 return E_OUTOFMEMORY;
208 VariantInit(&prop->u.var);
215 static HRESULT set_this(DISPPARAMS *dp, DISPPARAMS *olddp, IDispatch *jsthis)
220 static DISPID this_id = DISPID_THIS;
224 for(i = 0; i < dp->cNamedArgs; i++) {
225 if(dp->rgdispidNamedArgs[i] == DISPID_THIS)
229 oldargs = dp->rgvarg;
230 dp->rgvarg = heap_alloc((dp->cArgs+1) * sizeof(VARIANTARG));
232 return E_OUTOFMEMORY;
233 memcpy(dp->rgvarg+1, oldargs, dp->cArgs*sizeof(VARIANTARG));
234 V_VT(dp->rgvarg) = VT_DISPATCH;
235 V_DISPATCH(dp->rgvarg) = jsthis;
239 DISPID *old = dp->rgdispidNamedArgs;
240 dp->rgdispidNamedArgs = heap_alloc((dp->cNamedArgs+1)*sizeof(DISPID));
241 if(!dp->rgdispidNamedArgs) {
242 heap_free(dp->rgvarg);
243 return E_OUTOFMEMORY;
246 memcpy(dp->rgdispidNamedArgs+1, old, dp->cNamedArgs*sizeof(DISPID));
247 dp->rgdispidNamedArgs[0] = DISPID_THIS;
250 dp->rgdispidNamedArgs = &this_id;
257 static HRESULT invoke_prop_func(DispatchEx *This, DispatchEx *jsthis, dispex_prop_t *prop, WORD flags,
258 DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
266 if(flags == DISPATCH_CONSTRUCT && (prop->flags & DISPATCH_METHOD)) {
267 WARN("%s is not a constructor\n", debugstr_w(prop->name));
271 set_jsdisp(&vthis, jsthis);
272 hres = prop->u.p->invoke(This->ctx, &vthis, flags, dp, retv, ei, caller);
273 vdisp_release(&vthis);
277 return invoke_prop_func(This->prototype, jsthis, This->prototype->props+prop->u.ref, flags, dp, retv, ei, caller);
281 if(V_VT(&prop->u.var) != VT_DISPATCH) {
282 FIXME("invoke vt %d\n", V_VT(&prop->u.var));
286 TRACE("call %s %p\n", debugstr_w(prop->name), V_DISPATCH(&prop->u.var));
288 hres = set_this(&new_dp, dp, (IDispatch*)_IDispatchEx_(jsthis));
292 hres = disp_call(This->ctx, V_DISPATCH(&prop->u.var), DISPID_VALUE, flags, &new_dp, retv, ei, caller);
294 if(new_dp.rgvarg != dp->rgvarg) {
295 heap_free(new_dp.rgvarg);
296 if(new_dp.cNamedArgs > 1)
297 heap_free(new_dp.rgdispidNamedArgs);
303 ERR("type %d\n", prop->type);
309 static HRESULT prop_get(DispatchEx *This, dispex_prop_t *prop, DISPPARAMS *dp,
310 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
316 if(prop->u.p->flags & PROPF_METHOD) {
318 hres = create_builtin_function(This->ctx, prop->u.p->invoke, prop->u.p->name, NULL,
319 prop->u.p->flags, NULL, &obj);
323 prop->type = PROP_VARIANT;
324 V_VT(&prop->u.var) = VT_DISPATCH;
325 V_DISPATCH(&prop->u.var) = (IDispatch*)_IDispatchEx_(obj);
327 hres = VariantCopy(retv, &prop->u.var);
331 set_jsdisp(&vthis, This);
332 hres = prop->u.p->invoke(This->ctx, &vthis, DISPATCH_PROPERTYGET, dp, retv, ei, caller);
333 vdisp_release(&vthis);
337 hres = prop_get(This->prototype, This->prototype->props+prop->u.ref, dp, retv, ei, caller);
340 hres = VariantCopy(retv, &prop->u.var);
343 ERR("type %d\n", prop->type);
348 TRACE("fail %08x\n", hres);
352 TRACE("%s ret %s\n", debugstr_w(prop->name), debugstr_variant(retv));
356 static HRESULT prop_put(DispatchEx *This, dispex_prop_t *prop, VARIANT *val,
357 jsexcept_t *ei, IServiceProvider *caller)
363 if(!(prop->flags & PROPF_METHOD)) {
364 DISPPARAMS dp = {val, NULL, 1, 0};
367 set_jsdisp(&vthis, This);
368 hres = prop->u.p->invoke(This->ctx, &vthis, DISPATCH_PROPERTYPUT, &dp, NULL, ei, caller);
369 vdisp_release(&vthis);
373 prop->type = PROP_VARIANT;
374 prop->flags = PROPF_ENUM;
375 V_VT(&prop->u.var) = VT_EMPTY;
378 VariantClear(&prop->u.var);
381 ERR("type %d\n", prop->type);
385 hres = VariantCopy(&prop->u.var, val);
389 if(This->builtin_info->on_put)
390 This->builtin_info->on_put(This, prop->name);
392 TRACE("%s = %s\n", debugstr_w(prop->name), debugstr_variant(val));
396 static HRESULT fill_protrefs(DispatchEx *This)
398 dispex_prop_t *iter, *prop;
404 fill_protrefs(This->prototype);
406 for(iter = This->prototype->props; iter < This->prototype->props+This->prototype->prop_cnt; iter++) {
409 hres = find_prop_name(This, iter->name, &prop);
413 prop = alloc_protref(This, iter->name, iter - This->prototype->props);
415 return E_OUTOFMEMORY;
422 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
424 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
426 DispatchEx *This = DISPATCHEX_THIS(iface);
428 if(IsEqualGUID(&IID_IUnknown, riid)) {
429 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
430 *ppv = _IDispatchEx_(This);
431 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
432 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
433 *ppv = _IDispatchEx_(This);
434 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
435 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
436 *ppv = _IDispatchEx_(This);
437 }else if(IsEqualGUID(&IID_IDispatchJS, riid)) {
438 TRACE("(%p)->(IID_IDispatchJS %p)\n", This, ppv);
439 IUnknown_AddRef(_IDispatchEx_(This));
443 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
445 return E_NOINTERFACE;
448 IUnknown_AddRef((IUnknown*)*ppv);
452 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
454 DispatchEx *This = DISPATCHEX_THIS(iface);
455 LONG ref = InterlockedIncrement(&This->ref);
457 TRACE("(%p) ref=%d\n", This, ref);
462 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
464 DispatchEx *This = DISPATCHEX_THIS(iface);
465 LONG ref = InterlockedDecrement(&This->ref);
467 TRACE("(%p) ref=%d\n", This, ref);
472 for(prop = This->props; prop < This->props+This->prop_cnt; prop++) {
473 if(prop->type == PROP_VARIANT)
474 VariantClear(&prop->u.var);
475 heap_free(prop->name);
477 heap_free(This->props);
478 script_release(This->ctx);
480 jsdisp_release(This->prototype);
482 if(This->builtin_info->destructor)
483 This->builtin_info->destructor(This);
491 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
493 DispatchEx *This = DISPATCHEX_THIS(iface);
495 TRACE("(%p)->(%p)\n", This, pctinfo);
501 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid,
504 DispatchEx *This = DISPATCHEX_THIS(iface);
505 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
509 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
510 LPOLESTR *rgszNames, UINT cNames, LCID lcid,
513 DispatchEx *This = DISPATCHEX_THIS(iface);
517 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
520 for(i=0; i < cNames; i++) {
521 hres = IDispatchEx_GetDispID(_IDispatchEx_(This), rgszNames[i], 0, rgDispId+i);
529 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
530 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
531 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
533 DispatchEx *This = DISPATCHEX_THIS(iface);
535 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
536 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
538 return IDispatchEx_InvokeEx(_IDispatchEx_(This), dispIdMember, lcid, wFlags,
539 pDispParams, pVarResult, pExcepInfo, NULL);
542 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
544 DispatchEx *This = DISPATCHEX_THIS(iface);
546 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
548 if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit|FDEX_VERSION_MASK)) {
549 FIXME("Unsupported grfdex %x\n", grfdex);
553 return jsdisp_get_id(This, bstrName, grfdex, pid);
556 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
557 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
559 DispatchEx *This = DISPATCHEX_THIS(iface);
564 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
567 V_VT(pvarRes) = VT_EMPTY;
569 prop = get_prop(This, id);
570 if(!prop || prop->type == PROP_DELETED) {
571 TRACE("invalid id\n");
572 return DISP_E_MEMBERNOTFOUND;
575 memset(&jsexcept, 0, sizeof(jsexcept));
578 case DISPATCH_METHOD:
579 case DISPATCH_CONSTRUCT:
580 hres = invoke_prop_func(This, This, prop, wFlags, pdp, pvarRes, &jsexcept, pspCaller);
582 case DISPATCH_PROPERTYGET:
583 hres = prop_get(This, prop, pdp, pvarRes, &jsexcept, pspCaller);
585 case DISPATCH_PROPERTYPUT: {
588 for(i=0; i < pdp->cNamedArgs; i++) {
589 if(pdp->rgdispidNamedArgs[i] == DISPID_PROPERTYPUT)
593 if(i == pdp->cNamedArgs) {
594 TRACE("no value to set\n");
595 return DISP_E_PARAMNOTOPTIONAL;
598 hres = prop_put(This, prop, pdp->rgvarg+i, &jsexcept, pspCaller);
602 FIXME("Unimplemented flags %x\n", wFlags);
612 static HRESULT delete_prop(dispex_prop_t *prop)
614 heap_free(prop->name);
616 prop->type = PROP_DELETED;
621 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
623 DispatchEx *This = DISPATCHEX_THIS(iface);
627 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
629 if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit|FDEX_VERSION_MASK))
630 FIXME("Unsupported grfdex %x\n", grfdex);
632 hres = find_prop_name(This, bstrName, &prop);
636 TRACE("not found\n");
640 return delete_prop(prop);
643 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
645 DispatchEx *This = DISPATCHEX_THIS(iface);
648 TRACE("(%p)->(%x)\n", This, id);
650 prop = get_prop(This, id);
652 WARN("invalid id\n");
653 return DISP_E_MEMBERNOTFOUND;
656 return delete_prop(prop);
659 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
661 DispatchEx *This = DISPATCHEX_THIS(iface);
662 FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
666 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
668 DispatchEx *This = DISPATCHEX_THIS(iface);
671 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
673 prop = get_prop(This, id);
674 if(!prop || !prop->name || prop->type == PROP_DELETED)
675 return DISP_E_MEMBERNOTFOUND;
677 *pbstrName = SysAllocString(prop->name);
679 return E_OUTOFMEMORY;
684 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
686 DispatchEx *This = DISPATCHEX_THIS(iface);
690 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
692 if(id == DISPID_STARTENUM) {
693 hres = fill_protrefs(This);
698 iter = get_prop(This, id+1);
700 *pid = DISPID_STARTENUM;
704 while(iter < This->props + This->prop_cnt) {
705 if(iter->name && (get_flags(This, iter) & PROPF_ENUM)) {
706 *pid = prop_to_id(This, iter);
712 *pid = DISPID_STARTENUM;
716 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
718 DispatchEx *This = DISPATCHEX_THIS(iface);
719 FIXME("(%p)->(%p)\n", This, ppunk);
723 #undef DISPATCHEX_THIS
725 static IDispatchExVtbl DispatchExVtbl = {
726 DispatchEx_QueryInterface,
729 DispatchEx_GetTypeInfoCount,
730 DispatchEx_GetTypeInfo,
731 DispatchEx_GetIDsOfNames,
733 DispatchEx_GetDispID,
735 DispatchEx_DeleteMemberByName,
736 DispatchEx_DeleteMemberByDispID,
737 DispatchEx_GetMemberProperties,
738 DispatchEx_GetMemberName,
739 DispatchEx_GetNextDispID,
740 DispatchEx_GetNameSpaceParent
743 HRESULT init_dispex(DispatchEx *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *prototype)
745 TRACE("%p (%p)\n", dispex, prototype);
747 dispex->lpIDispatchExVtbl = &DispatchExVtbl;
749 dispex->builtin_info = builtin_info;
751 dispex->props = heap_alloc((dispex->buf_size=4) * sizeof(dispex_prop_t));
753 return E_OUTOFMEMORY;
755 dispex->prototype = prototype;
757 IDispatchEx_AddRef(_IDispatchEx_(prototype));
759 dispex->prop_cnt = 1;
760 dispex->props[0].name = NULL;
761 dispex->props[0].flags = 0;
762 if(builtin_info->value_prop.invoke) {
763 dispex->props[0].type = PROP_BUILTIN;
764 dispex->props[0].u.p = &builtin_info->value_prop;
766 dispex->props[0].type = PROP_DELETED;
775 static const builtin_info_t dispex_info = {
783 HRESULT create_dispex(script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *prototype, DispatchEx **dispex)
788 ret = heap_alloc_zero(sizeof(DispatchEx));
790 return E_OUTOFMEMORY;
792 hres = init_dispex(ret, ctx, builtin_info ? builtin_info : &dispex_info, prototype);
800 HRESULT init_dispex_from_constr(DispatchEx *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *constr)
802 DispatchEx *prot = NULL;
806 static const WCHAR constructorW[] = {'c','o','n','s','t','r','u','c','t','o','r'};
807 static const WCHAR prototypeW[] = {'p','r','o','t','o','t','y','p','e',0};
809 hres = find_prop_name_prot(constr, prototypeW, &prop);
810 if(SUCCEEDED(hres) && prop) {
814 V_VT(&var) = VT_EMPTY;
815 memset(&jsexcept, 0, sizeof(jsexcept));
816 hres = prop_get(constr, prop, NULL, &var, &jsexcept, NULL/*FIXME*/);
818 ERR("Could not get prototype\n");
822 if(V_VT(&var) == VT_DISPATCH)
823 prot = iface_to_jsdisp((IUnknown*)V_DISPATCH(&var));
827 hres = init_dispex(dispex, ctx, builtin_info, prot);
830 jsdisp_release(prot);
834 hres = ensure_prop_name(dispex, constructorW, FALSE, 0, &prop);
835 if(SUCCEEDED(hres)) {
839 V_VT(&var) = VT_DISPATCH;
840 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(constr);
841 memset(&jsexcept, 0, sizeof(jsexcept));
842 hres = prop_put(dispex, prop, &var, &jsexcept, NULL/*FIXME*/);
845 jsdisp_release(dispex);
850 DispatchEx *iface_to_jsdisp(IUnknown *iface)
855 hres = IUnknown_QueryInterface(iface, &IID_IDispatchJS, (void**)&ret);
862 HRESULT jsdisp_get_id(DispatchEx *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
867 if(flags & fdexNameEnsure)
868 hres = ensure_prop_name(jsdisp, name, TRUE, PROPF_ENUM, &prop);
870 hres = find_prop_name_prot(jsdisp, name, &prop);
875 *id = prop_to_id(jsdisp, prop);
879 TRACE("not found %s\n", debugstr_w(name));
880 return DISP_E_UNKNOWNNAME;
883 HRESULT jsdisp_call_value(DispatchEx *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv,
884 jsexcept_t *ei, IServiceProvider *caller)
889 set_jsdisp(&vdisp, jsthis);
890 hres = jsthis->builtin_info->value_prop.invoke(jsthis->ctx, &vdisp, flags, dp, retv, ei, caller);
891 vdisp_release(&vdisp);
895 HRESULT jsdisp_call(DispatchEx *disp, DISPID id, WORD flags, DISPPARAMS *dp, VARIANT *retv,
896 jsexcept_t *ei, IServiceProvider *caller)
900 memset(ei, 0, sizeof(*ei));
902 V_VT(retv) = VT_EMPTY;
904 prop = get_prop(disp, id);
906 return DISP_E_MEMBERNOTFOUND;
908 return invoke_prop_func(disp, disp, prop, flags, dp, retv, ei, caller);
911 HRESULT jsdisp_call_name(DispatchEx *disp, const WCHAR *name, WORD flags, DISPPARAMS *dp, VARIANT *retv,
912 jsexcept_t *ei, IServiceProvider *caller)
917 hres = find_prop_name_prot(disp, name, &prop);
921 memset(ei, 0, sizeof(*ei));
923 V_VT(retv) = VT_EMPTY;
925 return invoke_prop_func(disp, disp, prop, flags, dp, retv, ei, caller);
928 HRESULT disp_call(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD flags, DISPPARAMS *dp, VARIANT *retv,
929 jsexcept_t *ei, IServiceProvider *caller)
935 jsdisp = iface_to_jsdisp((IUnknown*)disp);
937 hres = jsdisp_call(jsdisp, id, flags, dp, retv, ei, caller);
938 jsdisp_release(jsdisp);
942 memset(ei, 0, sizeof(*ei));
945 V_VT(retv) = VT_EMPTY;
946 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
950 if(flags == DISPATCH_CONSTRUCT) {
951 WARN("IDispatch cannot be constructor\n");
952 return DISP_E_MEMBERNOTFOUND;
955 TRACE("using IDispatch\n");
956 return IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, flags, dp, retv, &ei->ei, &err);
959 hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, flags, dp, retv, &ei->ei, caller);
960 IDispatchEx_Release(dispex);
965 HRESULT jsdisp_propput_name(DispatchEx *obj, const WCHAR *name, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
970 hres = ensure_prop_name(obj, name, FALSE, PROPF_ENUM, &prop);
974 return prop_put(obj, prop, val, ei, caller);
977 HRESULT jsdisp_propput_idx(DispatchEx *obj, DWORD idx, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
981 static const WCHAR formatW[] = {'%','d',0};
983 sprintfW(buf, formatW, idx);
984 return jsdisp_propput_name(obj, buf, val, ei, caller);
987 HRESULT disp_propput(script_ctx_t *ctx, IDispatch *disp, DISPID id, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
992 jsdisp = iface_to_jsdisp((IUnknown*)disp);
996 prop = get_prop(jsdisp, id);
998 hres = prop_put(jsdisp, prop, val, ei, caller);
1000 hres = DISP_E_MEMBERNOTFOUND;
1002 jsdisp_release(jsdisp);
1004 DISPID dispid = DISPID_PROPERTYPUT;
1005 DISPPARAMS dp = {val, &dispid, 1, 1};
1006 IDispatchEx *dispex;
1008 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1009 if(SUCCEEDED(hres)) {
1010 hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, DISPATCH_PROPERTYPUT, &dp, NULL, &ei->ei, caller);
1011 IDispatchEx_Release(dispex);
1015 TRACE("using IDispatch\n");
1016 hres = IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, DISPATCH_PROPERTYPUT, &dp, NULL, &ei->ei, &err);
1023 HRESULT jsdisp_propget_name(DispatchEx *obj, const WCHAR *name, VARIANT *var, jsexcept_t *ei, IServiceProvider *caller)
1025 DISPPARAMS dp = {NULL, NULL, 0, 0};
1026 dispex_prop_t *prop;
1029 hres = find_prop_name_prot(obj, name, &prop);
1033 V_VT(var) = VT_EMPTY;
1037 return prop_get(obj, prop, &dp, var, ei, caller);
1040 HRESULT jsdisp_get_idx(DispatchEx *obj, DWORD idx, VARIANT *var, jsexcept_t *ei, IServiceProvider *caller)
1043 DISPPARAMS dp = {NULL, NULL, 0, 0};
1044 dispex_prop_t *prop;
1047 static const WCHAR formatW[] = {'%','d',0};
1049 sprintfW(name, formatW, idx);
1051 hres = find_prop_name_prot(obj, name, &prop);
1055 V_VT(var) = VT_EMPTY;
1057 return DISP_E_UNKNOWNNAME;
1059 return prop_get(obj, prop, &dp, var, ei, caller);
1062 HRESULT jsdisp_propget(DispatchEx *jsdisp, DISPID id, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
1064 DISPPARAMS dp = {NULL,NULL,0,0};
1065 dispex_prop_t *prop;
1067 prop = get_prop(jsdisp, id);
1069 return DISP_E_MEMBERNOTFOUND;
1071 V_VT(val) = VT_EMPTY;
1072 return prop_get(jsdisp, prop, &dp, val, ei, caller);
1075 HRESULT disp_propget(script_ctx_t *ctx, IDispatch *disp, DISPID id, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
1077 DISPPARAMS dp = {NULL,NULL,0,0};
1078 IDispatchEx *dispex;
1082 jsdisp = iface_to_jsdisp((IUnknown*)disp);
1084 hres = jsdisp_propget(jsdisp, id, val, ei, caller);
1085 jsdisp_release(jsdisp);
1089 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1093 TRACE("using IDispatch\n");
1094 return IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, INVOKE_PROPERTYGET, &dp, val, &ei->ei, &err);
1097 hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, INVOKE_PROPERTYGET, &dp, val, &ei->ei, caller);
1098 IDispatchEx_Release(dispex);
1103 HRESULT jsdisp_delete_idx(DispatchEx *obj, DWORD idx)
1105 static const WCHAR formatW[] = {'%','d',0};
1107 dispex_prop_t *prop;
1110 sprintfW(buf, formatW, idx);
1112 hres = find_prop_name(obj, buf, &prop);
1113 if(FAILED(hres) || !prop)
1116 return delete_prop(prop);