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}};
40 struct _dispex_prop_t {
47 const builtin_prop_t *p;
52 static inline DISPID prop_to_id(DispatchEx *This, dispex_prop_t *prop)
54 return prop - This->props;
57 static inline dispex_prop_t *get_prop(DispatchEx *This, DISPID id)
59 if(id < 0 || id >= This->prop_cnt || This->props[id].type == PROP_DELETED)
62 return This->props+id;
65 static DWORD get_flags(DispatchEx *This, dispex_prop_t *prop)
67 if(prop->type == PROP_PROTREF) {
68 dispex_prop_t *parent = get_prop(This->prototype, prop->u.ref);
70 prop->type = PROP_DELETED;
74 return get_flags(This->prototype, parent);
80 static const builtin_prop_t *find_builtin_prop(DispatchEx *This, const WCHAR *name)
82 int min = 0, max, i, r;
84 max = This->builtin_info->props_cnt-1;
88 r = strcmpW(name, This->builtin_info->props[i].name);
90 return This->builtin_info->props + i;
101 static dispex_prop_t *alloc_prop(DispatchEx *This, const WCHAR *name, prop_type_t type, DWORD flags)
105 if(This->buf_size == This->prop_cnt) {
106 dispex_prop_t *tmp = heap_realloc(This->props, (This->buf_size<<=1)*sizeof(*This->props));
112 ret = This->props + This->prop_cnt++;
115 ret->name = heap_strdupW(name);
122 static dispex_prop_t *alloc_protref(DispatchEx *This, const WCHAR *name, DWORD ref)
126 ret = alloc_prop(This, name, PROP_PROTREF, 0);
134 static HRESULT find_prop_name(DispatchEx *This, const WCHAR *name, dispex_prop_t **ret)
136 const builtin_prop_t *builtin;
139 for(prop = This->props; prop < This->props+This->prop_cnt; prop++) {
140 if(prop->name && !strcmpW(prop->name, name)) {
146 builtin = find_builtin_prop(This, name);
148 prop = alloc_prop(This, name, PROP_BUILTIN, builtin->flags);
150 return E_OUTOFMEMORY;
161 static HRESULT find_prop_name_prot(DispatchEx *This, const WCHAR *name, BOOL alloc, dispex_prop_t **ret)
166 hres = find_prop_name(This, name, &prop);
174 if(This->prototype) {
175 hres = find_prop_name_prot(This->prototype, name, FALSE, &prop);
179 prop = alloc_protref(This, prop->name, prop - This->prototype->props);
181 return E_OUTOFMEMORY;
188 TRACE("creating prop %s\n", debugstr_w(name));
190 prop = alloc_prop(This, name, PROP_VARIANT, PROPF_ENUM);
192 return E_OUTOFMEMORY;
193 VariantInit(&prop->u.var);
200 static HRESULT set_this(DISPPARAMS *dp, DISPPARAMS *olddp, IDispatch *jsthis)
205 static DISPID this_id = DISPID_THIS;
209 for(i = 0; i < dp->cNamedArgs; i++) {
210 if(dp->rgdispidNamedArgs[i] == DISPID_THIS)
214 oldargs = dp->rgvarg;
215 dp->rgvarg = heap_alloc((dp->cArgs+1) * sizeof(VARIANTARG));
217 return E_OUTOFMEMORY;
218 memcpy(dp->rgvarg+1, oldargs, dp->cArgs*sizeof(VARIANTARG));
219 V_VT(dp->rgvarg) = VT_DISPATCH;
220 V_DISPATCH(dp->rgvarg) = jsthis;
224 DISPID *old = dp->rgdispidNamedArgs;
225 dp->rgdispidNamedArgs = heap_alloc((dp->cNamedArgs+1)*sizeof(DISPID));
226 if(!dp->rgdispidNamedArgs) {
227 heap_free(dp->rgvarg);
228 return E_OUTOFMEMORY;
231 memcpy(dp->rgdispidNamedArgs+1, old, dp->cNamedArgs*sizeof(DISPID));
232 dp->rgdispidNamedArgs[0] = DISPID_THIS;
235 dp->rgdispidNamedArgs = &this_id;
242 static HRESULT invoke_prop_func(DispatchEx *This, DispatchEx *jsthis, dispex_prop_t *prop, LCID lcid, WORD flags,
243 DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
249 if(flags == DISPATCH_CONSTRUCT && (prop->flags & DISPATCH_METHOD)) {
250 WARN("%s is not a constructor\n", debugstr_w(prop->name));
253 return prop->u.p->invoke(jsthis, lcid, flags, dp, retv, ei, caller);
255 return invoke_prop_func(This->prototype, jsthis, This->prototype->props+prop->u.ref, lcid, flags, dp, retv, ei, caller);
259 if(V_VT(&prop->u.var) != VT_DISPATCH) {
260 FIXME("invoke vt %d\n", V_VT(&prop->u.var));
264 TRACE("call %s %p\n", debugstr_w(prop->name), V_DISPATCH(&prop->u.var));
266 hres = set_this(&new_dp, dp, (IDispatch*)_IDispatchEx_(jsthis));
270 hres = disp_call(V_DISPATCH(&prop->u.var), DISPID_VALUE, lcid, flags, &new_dp, retv, ei, caller);
272 if(new_dp.rgvarg != dp->rgvarg) {
273 heap_free(new_dp.rgvarg);
274 if(new_dp.cNamedArgs > 1)
275 heap_free(new_dp.rgdispidNamedArgs);
281 ERR("type %d\n", prop->type);
287 static HRESULT prop_get(DispatchEx *This, dispex_prop_t *prop, LCID lcid, DISPPARAMS *dp,
288 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
294 if(prop->u.p->flags & PROPF_METHOD) {
296 hres = create_builtin_function(This->ctx, prop->u.p->invoke, NULL, prop->u.p->flags, NULL, &obj);
300 prop->type = PROP_VARIANT;
301 V_VT(&prop->u.var) = VT_DISPATCH;
302 V_DISPATCH(&prop->u.var) = (IDispatch*)_IDispatchEx_(obj);
304 hres = VariantCopy(retv, &prop->u.var);
306 hres = prop->u.p->invoke(This, lcid, DISPATCH_PROPERTYGET, dp, retv, ei, caller);
310 hres = prop_get(This->prototype, This->prototype->props+prop->u.ref, lcid, dp, retv, ei, caller);
313 hres = VariantCopy(retv, &prop->u.var);
316 ERR("type %d\n", prop->type);
321 TRACE("fail %08x\n", hres);
325 TRACE("%s ret %s\n", debugstr_w(prop->name), debugstr_variant(retv));
329 static HRESULT prop_put(DispatchEx *This, dispex_prop_t *prop, LCID lcid, DISPPARAMS *dp,
330 jsexcept_t *ei, IServiceProvider *caller)
337 if(!(prop->flags & PROPF_METHOD))
338 return prop->u.p->invoke(This, lcid, DISPATCH_PROPERTYPUT, dp, NULL, ei, caller);
340 prop->type = PROP_VARIANT;
341 prop->flags = PROPF_ENUM;
342 V_VT(&prop->u.var) = VT_EMPTY;
345 VariantClear(&prop->u.var);
348 ERR("type %d\n", prop->type);
352 for(i=0; i < dp->cNamedArgs; i++) {
353 if(dp->rgdispidNamedArgs[i] == DISPID_PROPERTYPUT)
357 if(i == dp->cNamedArgs) {
358 TRACE("no value to set\n");
359 return DISP_E_PARAMNOTOPTIONAL;
362 hres = VariantCopy(&prop->u.var, dp->rgvarg+i);
366 if(This->builtin_info->on_put)
367 This->builtin_info->on_put(This, prop->name);
369 TRACE("%s = %s\n", debugstr_w(prop->name), debugstr_variant(dp->rgvarg+i));
373 static HRESULT fill_protrefs(DispatchEx *This)
375 dispex_prop_t *iter, *prop;
381 fill_protrefs(This->prototype);
383 for(iter = This->prototype->props; iter < This->prototype->props+This->prototype->prop_cnt; iter++) {
386 hres = find_prop_name(This, iter->name, &prop);
390 prop = alloc_protref(This, iter->name, iter - This->prototype->props);
392 return E_OUTOFMEMORY;
399 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
401 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
403 DispatchEx *This = DISPATCHEX_THIS(iface);
405 if(IsEqualGUID(&IID_IUnknown, riid)) {
406 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
407 *ppv = _IDispatchEx_(This);
408 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
409 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
410 *ppv = _IDispatchEx_(This);
411 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
412 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
413 *ppv = _IDispatchEx_(This);
414 }else if(IsEqualGUID(&IID_IDispatchJS, riid)) {
415 TRACE("(%p)->(IID_IDispatchJS %p)\n", This, ppv);
416 IUnknown_AddRef(_IDispatchEx_(This));
420 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
422 return E_NOINTERFACE;
425 IUnknown_AddRef((IUnknown*)*ppv);
429 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
431 DispatchEx *This = DISPATCHEX_THIS(iface);
432 LONG ref = InterlockedIncrement(&This->ref);
434 TRACE("(%p) ref=%d\n", This, ref);
439 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
441 DispatchEx *This = DISPATCHEX_THIS(iface);
442 LONG ref = InterlockedDecrement(&This->ref);
444 TRACE("(%p) ref=%d\n", This, ref);
449 for(prop = This->props; prop < This->props+This->prop_cnt; prop++) {
450 if(prop->type == PROP_VARIANT)
451 VariantClear(&prop->u.var);
452 heap_free(prop->name);
454 heap_free(This->props);
455 script_release(This->ctx);
457 if(This->builtin_info->destructor)
458 This->builtin_info->destructor(This);
466 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
468 DispatchEx *This = DISPATCHEX_THIS(iface);
470 TRACE("(%p)->(%p)\n", This, pctinfo);
476 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
477 LCID lcid, ITypeInfo **ppTInfo)
479 DispatchEx *This = DISPATCHEX_THIS(iface);
480 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
484 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
485 LPOLESTR *rgszNames, UINT cNames,
486 LCID lcid, DISPID *rgDispId)
488 DispatchEx *This = DISPATCHEX_THIS(iface);
492 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
495 for(i=0; i < cNames; i++) {
496 hres = IDispatchEx_GetDispID(_IDispatchEx_(This), rgszNames[i], 0, rgDispId+i);
504 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
505 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
506 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
508 DispatchEx *This = DISPATCHEX_THIS(iface);
510 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
511 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
513 return IDispatchEx_InvokeEx(_IDispatchEx_(This), dispIdMember, lcid, wFlags,
514 pDispParams, pVarResult, pExcepInfo, NULL);
517 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
519 DispatchEx *This = DISPATCHEX_THIS(iface);
521 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
523 if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit)) {
524 FIXME("Unsupported grfdex %x\n", grfdex);
528 return jsdisp_get_id(This, bstrName, grfdex, pid);
531 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
532 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
534 DispatchEx *This = DISPATCHEX_THIS(iface);
539 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
542 V_VT(pvarRes) = VT_EMPTY;
544 prop = get_prop(This, id);
545 if(!prop || prop->type == PROP_DELETED) {
546 TRACE("invalid id\n");
547 return DISP_E_MEMBERNOTFOUND;
550 memset(&jsexcept, 0, sizeof(jsexcept));
553 case DISPATCH_METHOD:
554 case DISPATCH_CONSTRUCT:
555 hres = invoke_prop_func(This, This, prop, lcid, wFlags, pdp, pvarRes, &jsexcept, pspCaller);
557 case DISPATCH_PROPERTYGET:
558 hres = prop_get(This, prop, lcid, pdp, pvarRes, &jsexcept, pspCaller);
560 case DISPATCH_PROPERTYPUT:
561 hres = prop_put(This, prop, lcid, pdp, &jsexcept, pspCaller);
564 FIXME("Unimplemented flags %x\n", wFlags);
574 static HRESULT delete_prop(dispex_prop_t *prop)
576 heap_free(prop->name);
578 prop->type = PROP_DELETED;
583 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
585 DispatchEx *This = DISPATCHEX_THIS(iface);
589 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
591 if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit))
592 FIXME("Unsupported grfdex %x\n", grfdex);
594 hres = find_prop_name(This, bstrName, &prop);
598 TRACE("not found\n");
602 return delete_prop(prop);
605 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
607 DispatchEx *This = DISPATCHEX_THIS(iface);
610 TRACE("(%p)->(%x)\n", This, id);
612 prop = get_prop(This, id);
614 WARN("invalid id\n");
615 return DISP_E_MEMBERNOTFOUND;
618 return delete_prop(prop);
621 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
623 DispatchEx *This = DISPATCHEX_THIS(iface);
624 FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
628 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
630 DispatchEx *This = DISPATCHEX_THIS(iface);
633 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
635 prop = get_prop(This, id);
636 if(!prop || !prop->name || prop->type == PROP_DELETED)
637 return DISP_E_MEMBERNOTFOUND;
639 *pbstrName = SysAllocString(prop->name);
641 return E_OUTOFMEMORY;
646 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
648 DispatchEx *This = DISPATCHEX_THIS(iface);
652 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
654 if(id == DISPID_STARTENUM) {
655 hres = fill_protrefs(This);
660 iter = get_prop(This, id+1);
662 *pid = DISPID_STARTENUM;
666 while(iter < This->props + This->prop_cnt) {
667 if(iter->name && (get_flags(This, iter) & PROPF_ENUM)) {
668 *pid = prop_to_id(This, iter);
674 *pid = DISPID_STARTENUM;
678 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
680 DispatchEx *This = DISPATCHEX_THIS(iface);
681 FIXME("(%p)->(%p)\n", This, ppunk);
685 #undef DISPATCHEX_THIS
687 static IDispatchExVtbl DispatchExVtbl = {
688 DispatchEx_QueryInterface,
691 DispatchEx_GetTypeInfoCount,
692 DispatchEx_GetTypeInfo,
693 DispatchEx_GetIDsOfNames,
695 DispatchEx_GetDispID,
697 DispatchEx_DeleteMemberByName,
698 DispatchEx_DeleteMemberByDispID,
699 DispatchEx_GetMemberProperties,
700 DispatchEx_GetMemberName,
701 DispatchEx_GetNextDispID,
702 DispatchEx_GetNameSpaceParent
705 HRESULT init_dispex(DispatchEx *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *prototype)
707 TRACE("%p (%p)\n", dispex, prototype);
709 dispex->lpIDispatchExVtbl = &DispatchExVtbl;
711 dispex->builtin_info = builtin_info;
713 dispex->props = heap_alloc((dispex->buf_size=4) * sizeof(dispex_prop_t));
715 return E_OUTOFMEMORY;
717 dispex->prototype = prototype;
719 IDispatchEx_AddRef(_IDispatchEx_(prototype));
721 dispex->prop_cnt = 1;
722 dispex->props[0].name = NULL;
723 dispex->props[0].flags = 0;
724 if(builtin_info->value_prop.invoke) {
725 dispex->props[0].type = PROP_BUILTIN;
726 dispex->props[0].u.p = &builtin_info->value_prop;
728 dispex->props[0].type = PROP_DELETED;
737 static const builtin_info_t dispex_info = {
745 HRESULT create_dispex(script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *prototype, DispatchEx **dispex)
750 ret = heap_alloc_zero(sizeof(DispatchEx));
752 return E_OUTOFMEMORY;
754 hres = init_dispex(ret, ctx, builtin_info ? builtin_info : &dispex_info, prototype);
762 HRESULT init_dispex_from_constr(DispatchEx *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *constr)
764 DispatchEx *prot = NULL;
768 static const WCHAR prototypeW[] = {'p','r','o','t','o','t','y','p','e',0};
770 hres = find_prop_name_prot(constr, prototypeW, FALSE, &prop);
771 if(SUCCEEDED(hres) && prop) {
775 V_VT(&var) = VT_EMPTY;
776 memset(&jsexcept, 0, sizeof(jsexcept));
777 hres = prop_get(constr, prop, ctx->lcid, NULL, &var, &jsexcept, NULL/*FIXME*/);
779 ERR("Could not get prototype\n");
783 if(V_VT(&var) == VT_DISPATCH)
784 prot = iface_to_jsdisp((IUnknown*)V_DISPATCH(&var));
788 hres = init_dispex(dispex, ctx, builtin_info, prot);
791 jsdisp_release(prot);
795 DispatchEx *iface_to_jsdisp(IUnknown *iface)
800 hres = IUnknown_QueryInterface(iface, &IID_IDispatchJS, (void**)&ret);
807 HRESULT jsdisp_get_id(DispatchEx *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
812 hres = find_prop_name_prot(jsdisp, name, (flags&fdexNameEnsure) != 0, &prop);
817 *id = prop_to_id(jsdisp, prop);
821 TRACE("not found %s\n", debugstr_w(name));
822 return DISP_E_UNKNOWNNAME;
825 HRESULT jsdisp_call_value(DispatchEx *disp, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv,
826 jsexcept_t *ei, IServiceProvider *caller)
828 return disp->builtin_info->value_prop.invoke(disp, lcid, flags, dp, retv, ei, caller);
831 HRESULT jsdisp_call(DispatchEx *disp, DISPID id, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv,
832 jsexcept_t *ei, IServiceProvider *caller)
836 memset(ei, 0, sizeof(*ei));
838 V_VT(retv) = VT_EMPTY;
840 prop = get_prop(disp, id);
842 return DISP_E_MEMBERNOTFOUND;
844 return invoke_prop_func(disp, disp, prop, lcid, flags, dp, retv, ei, caller);
847 HRESULT jsdisp_call_name(DispatchEx *disp, const WCHAR *name, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv,
848 jsexcept_t *ei, IServiceProvider *caller)
853 hres = find_prop_name_prot(disp, name, TRUE, &prop);
857 memset(ei, 0, sizeof(*ei));
859 V_VT(retv) = VT_EMPTY;
861 return invoke_prop_func(disp, disp, prop, lcid, flags, dp, retv, ei, caller);
864 HRESULT disp_call(IDispatch *disp, DISPID id, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv,
865 jsexcept_t *ei, IServiceProvider *caller)
871 jsdisp = iface_to_jsdisp((IUnknown*)disp);
873 hres = jsdisp_call(jsdisp, id, lcid, flags, dp, retv, ei, caller);
874 jsdisp_release(jsdisp);
878 memset(ei, 0, sizeof(*ei));
881 V_VT(retv) = VT_EMPTY;
882 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
886 if(flags == DISPATCH_CONSTRUCT) {
887 WARN("IDispatch cannot be constructor\n");
888 return DISP_E_MEMBERNOTFOUND;
891 TRACE("using IDispatch\n");
892 return IDispatch_Invoke(disp, id, &IID_NULL, lcid, flags, dp, retv, &ei->ei, &err);
895 hres = IDispatchEx_InvokeEx(dispex, id, lcid, flags, dp, retv, &ei->ei, caller);
896 IDispatchEx_Release(dispex);
901 HRESULT jsdisp_propput_name(DispatchEx *obj, const WCHAR *name, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
903 DISPID named_arg = DISPID_PROPERTYPUT;
904 DISPPARAMS dp = {val, &named_arg, 1, 1};
908 hres = find_prop_name_prot(obj, name, TRUE, &prop);
912 return prop_put(obj, prop, lcid, &dp, ei, caller);
915 HRESULT jsdisp_propput_idx(DispatchEx *obj, DWORD idx, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
919 static const WCHAR formatW[] = {'%','d',0};
921 sprintfW(buf, formatW, idx);
922 return jsdisp_propput_name(obj, buf, lcid, val, ei, caller);
925 HRESULT disp_propput(IDispatch *disp, DISPID id, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
927 DISPID dispid = DISPID_PROPERTYPUT;
928 DISPPARAMS dp = {val, &dispid, 1, 1};
933 jsdisp = iface_to_jsdisp((IUnknown*)disp);
937 prop = get_prop(jsdisp, id);
939 hres = prop_put(jsdisp, prop, lcid, &dp, ei, caller);
941 hres = DISP_E_MEMBERNOTFOUND;
943 jsdisp_release(jsdisp);
947 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
951 TRACE("using IDispatch\n");
952 return IDispatch_Invoke(disp, id, &IID_NULL, DISPATCH_PROPERTYPUT, lcid, &dp, NULL, &ei->ei, &err);
955 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_PROPERTYPUT, &dp, NULL, &ei->ei, caller);
957 IDispatchEx_Release(dispex);
961 HRESULT jsdisp_propget_name(DispatchEx *obj, const WCHAR *name, LCID lcid, VARIANT *var,
962 jsexcept_t *ei, IServiceProvider *caller)
964 DISPPARAMS dp = {NULL, NULL, 0, 0};
968 hres = find_prop_name_prot(obj, name, FALSE, &prop);
972 V_VT(var) = VT_EMPTY;
976 return prop_get(obj, prop, lcid, &dp, var, ei, caller);
979 HRESULT jsdisp_propget_idx(DispatchEx *obj, DWORD idx, LCID lcid, VARIANT *var, jsexcept_t *ei, IServiceProvider *caller)
983 static const WCHAR formatW[] = {'%','d',0};
985 sprintfW(buf, formatW, idx);
986 return jsdisp_propget_name(obj, buf, lcid, var, ei, caller);
989 HRESULT jsdisp_propget(DispatchEx *jsdisp, DISPID id, LCID lcid, VARIANT *val, jsexcept_t *ei,
990 IServiceProvider *caller)
992 DISPPARAMS dp = {NULL,NULL,0,0};
995 prop = get_prop(jsdisp, id);
997 return DISP_E_MEMBERNOTFOUND;
999 V_VT(val) = VT_EMPTY;
1000 return prop_get(jsdisp, prop, lcid, &dp, val, ei, caller);
1003 HRESULT disp_propget(IDispatch *disp, DISPID id, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
1005 DISPPARAMS dp = {NULL,NULL,0,0};
1006 IDispatchEx *dispex;
1010 jsdisp = iface_to_jsdisp((IUnknown*)disp);
1012 hres = jsdisp_propget(jsdisp, id, lcid, val, ei, caller);
1013 jsdisp_release(jsdisp);
1017 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1021 TRACE("using IDispatch\n");
1022 return IDispatch_Invoke(disp, id, &IID_NULL, lcid, INVOKE_PROPERTYGET, &dp, val, &ei->ei, &err);
1025 hres = IDispatchEx_InvokeEx(dispex, id, lcid, INVOKE_PROPERTYGET, &dp, val, &ei->ei, caller);
1026 IDispatchEx_Release(dispex);
1031 HRESULT jsdisp_delete_idx(DispatchEx *obj, DWORD idx)
1033 static const WCHAR formatW[] = {'%','d',0};
1035 dispex_prop_t *prop;
1038 sprintfW(buf, formatW, idx);
1040 hres = find_prop_name(obj, buf, &prop);
1041 if(FAILED(hres) || !prop)
1044 return delete_prop(prop);