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, 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, This->ctx->lcid, flags, dp, retv, ei, caller);
255 return invoke_prop_func(This->prototype, jsthis, This->prototype->props+prop->u.ref, 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(This->ctx, V_DISPATCH(&prop->u.var), DISPID_VALUE, 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, 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, prop->u.p->name, NULL,
297 prop->u.p->flags, NULL, &obj);
301 prop->type = PROP_VARIANT;
302 V_VT(&prop->u.var) = VT_DISPATCH;
303 V_DISPATCH(&prop->u.var) = (IDispatch*)_IDispatchEx_(obj);
305 hres = VariantCopy(retv, &prop->u.var);
307 hres = prop->u.p->invoke(This, This->ctx->lcid, DISPATCH_PROPERTYGET, dp, retv, ei, caller);
311 hres = prop_get(This->prototype, This->prototype->props+prop->u.ref, dp, retv, ei, caller);
314 hres = VariantCopy(retv, &prop->u.var);
317 ERR("type %d\n", prop->type);
322 TRACE("fail %08x\n", hres);
326 TRACE("%s ret %s\n", debugstr_w(prop->name), debugstr_variant(retv));
330 static HRESULT prop_put(DispatchEx *This, dispex_prop_t *prop, LCID lcid, DISPPARAMS *dp,
331 jsexcept_t *ei, IServiceProvider *caller)
338 if(!(prop->flags & PROPF_METHOD))
339 return prop->u.p->invoke(This, lcid, DISPATCH_PROPERTYPUT, dp, NULL, ei, caller);
341 prop->type = PROP_VARIANT;
342 prop->flags = PROPF_ENUM;
343 V_VT(&prop->u.var) = VT_EMPTY;
346 VariantClear(&prop->u.var);
349 ERR("type %d\n", prop->type);
353 for(i=0; i < dp->cNamedArgs; i++) {
354 if(dp->rgdispidNamedArgs[i] == DISPID_PROPERTYPUT)
358 if(i == dp->cNamedArgs) {
359 TRACE("no value to set\n");
360 return DISP_E_PARAMNOTOPTIONAL;
363 hres = VariantCopy(&prop->u.var, dp->rgvarg+i);
367 if(This->builtin_info->on_put)
368 This->builtin_info->on_put(This, prop->name);
370 TRACE("%s = %s\n", debugstr_w(prop->name), debugstr_variant(dp->rgvarg+i));
374 static HRESULT fill_protrefs(DispatchEx *This)
376 dispex_prop_t *iter, *prop;
382 fill_protrefs(This->prototype);
384 for(iter = This->prototype->props; iter < This->prototype->props+This->prototype->prop_cnt; iter++) {
387 hres = find_prop_name(This, iter->name, &prop);
391 prop = alloc_protref(This, iter->name, iter - This->prototype->props);
393 return E_OUTOFMEMORY;
400 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
402 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
404 DispatchEx *This = DISPATCHEX_THIS(iface);
406 if(IsEqualGUID(&IID_IUnknown, riid)) {
407 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
408 *ppv = _IDispatchEx_(This);
409 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
410 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
411 *ppv = _IDispatchEx_(This);
412 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
413 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
414 *ppv = _IDispatchEx_(This);
415 }else if(IsEqualGUID(&IID_IDispatchJS, riid)) {
416 TRACE("(%p)->(IID_IDispatchJS %p)\n", This, ppv);
417 IUnknown_AddRef(_IDispatchEx_(This));
421 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
423 return E_NOINTERFACE;
426 IUnknown_AddRef((IUnknown*)*ppv);
430 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
432 DispatchEx *This = DISPATCHEX_THIS(iface);
433 LONG ref = InterlockedIncrement(&This->ref);
435 TRACE("(%p) ref=%d\n", This, ref);
440 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
442 DispatchEx *This = DISPATCHEX_THIS(iface);
443 LONG ref = InterlockedDecrement(&This->ref);
445 TRACE("(%p) ref=%d\n", This, ref);
450 for(prop = This->props; prop < This->props+This->prop_cnt; prop++) {
451 if(prop->type == PROP_VARIANT)
452 VariantClear(&prop->u.var);
453 heap_free(prop->name);
455 heap_free(This->props);
456 script_release(This->ctx);
458 if(This->builtin_info->destructor)
459 This->builtin_info->destructor(This);
467 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
469 DispatchEx *This = DISPATCHEX_THIS(iface);
471 TRACE("(%p)->(%p)\n", This, pctinfo);
477 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
478 LCID lcid, ITypeInfo **ppTInfo)
480 DispatchEx *This = DISPATCHEX_THIS(iface);
481 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
485 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
486 LPOLESTR *rgszNames, UINT cNames,
487 LCID lcid, DISPID *rgDispId)
489 DispatchEx *This = DISPATCHEX_THIS(iface);
493 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
496 for(i=0; i < cNames; i++) {
497 hres = IDispatchEx_GetDispID(_IDispatchEx_(This), rgszNames[i], 0, rgDispId+i);
505 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
506 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
507 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
509 DispatchEx *This = DISPATCHEX_THIS(iface);
511 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
512 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
514 return IDispatchEx_InvokeEx(_IDispatchEx_(This), dispIdMember, lcid, wFlags,
515 pDispParams, pVarResult, pExcepInfo, NULL);
518 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
520 DispatchEx *This = DISPATCHEX_THIS(iface);
522 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
524 if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit)) {
525 FIXME("Unsupported grfdex %x\n", grfdex);
529 return jsdisp_get_id(This, bstrName, grfdex, pid);
532 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
533 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
535 DispatchEx *This = DISPATCHEX_THIS(iface);
540 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
543 V_VT(pvarRes) = VT_EMPTY;
545 prop = get_prop(This, id);
546 if(!prop || prop->type == PROP_DELETED) {
547 TRACE("invalid id\n");
548 return DISP_E_MEMBERNOTFOUND;
551 memset(&jsexcept, 0, sizeof(jsexcept));
554 case DISPATCH_METHOD:
555 case DISPATCH_CONSTRUCT:
556 hres = invoke_prop_func(This, This, prop, wFlags, pdp, pvarRes, &jsexcept, pspCaller);
558 case DISPATCH_PROPERTYGET:
559 hres = prop_get(This, prop, pdp, pvarRes, &jsexcept, pspCaller);
561 case DISPATCH_PROPERTYPUT:
562 hres = prop_put(This, prop, lcid, pdp, &jsexcept, pspCaller);
565 FIXME("Unimplemented flags %x\n", wFlags);
575 static HRESULT delete_prop(dispex_prop_t *prop)
577 heap_free(prop->name);
579 prop->type = PROP_DELETED;
584 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
586 DispatchEx *This = DISPATCHEX_THIS(iface);
590 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
592 if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit))
593 FIXME("Unsupported grfdex %x\n", grfdex);
595 hres = find_prop_name(This, bstrName, &prop);
599 TRACE("not found\n");
603 return delete_prop(prop);
606 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
608 DispatchEx *This = DISPATCHEX_THIS(iface);
611 TRACE("(%p)->(%x)\n", This, id);
613 prop = get_prop(This, id);
615 WARN("invalid id\n");
616 return DISP_E_MEMBERNOTFOUND;
619 return delete_prop(prop);
622 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
624 DispatchEx *This = DISPATCHEX_THIS(iface);
625 FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
629 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
631 DispatchEx *This = DISPATCHEX_THIS(iface);
634 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
636 prop = get_prop(This, id);
637 if(!prop || !prop->name || prop->type == PROP_DELETED)
638 return DISP_E_MEMBERNOTFOUND;
640 *pbstrName = SysAllocString(prop->name);
642 return E_OUTOFMEMORY;
647 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
649 DispatchEx *This = DISPATCHEX_THIS(iface);
653 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
655 if(id == DISPID_STARTENUM) {
656 hres = fill_protrefs(This);
661 iter = get_prop(This, id+1);
663 *pid = DISPID_STARTENUM;
667 while(iter < This->props + This->prop_cnt) {
668 if(iter->name && (get_flags(This, iter) & PROPF_ENUM)) {
669 *pid = prop_to_id(This, iter);
675 *pid = DISPID_STARTENUM;
679 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
681 DispatchEx *This = DISPATCHEX_THIS(iface);
682 FIXME("(%p)->(%p)\n", This, ppunk);
686 #undef DISPATCHEX_THIS
688 static IDispatchExVtbl DispatchExVtbl = {
689 DispatchEx_QueryInterface,
692 DispatchEx_GetTypeInfoCount,
693 DispatchEx_GetTypeInfo,
694 DispatchEx_GetIDsOfNames,
696 DispatchEx_GetDispID,
698 DispatchEx_DeleteMemberByName,
699 DispatchEx_DeleteMemberByDispID,
700 DispatchEx_GetMemberProperties,
701 DispatchEx_GetMemberName,
702 DispatchEx_GetNextDispID,
703 DispatchEx_GetNameSpaceParent
706 HRESULT init_dispex(DispatchEx *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *prototype)
708 TRACE("%p (%p)\n", dispex, prototype);
710 dispex->lpIDispatchExVtbl = &DispatchExVtbl;
712 dispex->builtin_info = builtin_info;
714 dispex->props = heap_alloc((dispex->buf_size=4) * sizeof(dispex_prop_t));
716 return E_OUTOFMEMORY;
718 dispex->prototype = prototype;
720 IDispatchEx_AddRef(_IDispatchEx_(prototype));
722 dispex->prop_cnt = 1;
723 dispex->props[0].name = NULL;
724 dispex->props[0].flags = 0;
725 if(builtin_info->value_prop.invoke) {
726 dispex->props[0].type = PROP_BUILTIN;
727 dispex->props[0].u.p = &builtin_info->value_prop;
729 dispex->props[0].type = PROP_DELETED;
738 static const builtin_info_t dispex_info = {
746 HRESULT create_dispex(script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *prototype, DispatchEx **dispex)
751 ret = heap_alloc_zero(sizeof(DispatchEx));
753 return E_OUTOFMEMORY;
755 hres = init_dispex(ret, ctx, builtin_info ? builtin_info : &dispex_info, prototype);
763 HRESULT init_dispex_from_constr(DispatchEx *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, DispatchEx *constr)
765 DispatchEx *prot = NULL;
769 static const WCHAR prototypeW[] = {'p','r','o','t','o','t','y','p','e',0};
771 hres = find_prop_name_prot(constr, prototypeW, FALSE, &prop);
772 if(SUCCEEDED(hres) && prop) {
776 V_VT(&var) = VT_EMPTY;
777 memset(&jsexcept, 0, sizeof(jsexcept));
778 hres = prop_get(constr, prop, NULL, &var, &jsexcept, NULL/*FIXME*/);
780 ERR("Could not get prototype\n");
784 if(V_VT(&var) == VT_DISPATCH)
785 prot = iface_to_jsdisp((IUnknown*)V_DISPATCH(&var));
789 hres = init_dispex(dispex, ctx, builtin_info, prot);
792 jsdisp_release(prot);
796 DispatchEx *iface_to_jsdisp(IUnknown *iface)
801 hres = IUnknown_QueryInterface(iface, &IID_IDispatchJS, (void**)&ret);
808 HRESULT jsdisp_get_id(DispatchEx *jsdisp, const WCHAR *name, DWORD flags, DISPID *id)
813 hres = find_prop_name_prot(jsdisp, name, (flags&fdexNameEnsure) != 0, &prop);
818 *id = prop_to_id(jsdisp, prop);
822 TRACE("not found %s\n", debugstr_w(name));
823 return DISP_E_UNKNOWNNAME;
826 HRESULT jsdisp_call_value(DispatchEx *disp, WORD flags, DISPPARAMS *dp, VARIANT *retv,
827 jsexcept_t *ei, IServiceProvider *caller)
829 return disp->builtin_info->value_prop.invoke(disp, disp->ctx->lcid, flags, dp, retv, ei, caller);
832 HRESULT jsdisp_call(DispatchEx *disp, DISPID id, WORD flags, DISPPARAMS *dp, VARIANT *retv,
833 jsexcept_t *ei, IServiceProvider *caller)
837 memset(ei, 0, sizeof(*ei));
839 V_VT(retv) = VT_EMPTY;
841 prop = get_prop(disp, id);
843 return DISP_E_MEMBERNOTFOUND;
845 return invoke_prop_func(disp, disp, prop, flags, dp, retv, ei, caller);
848 HRESULT jsdisp_call_name(DispatchEx *disp, const WCHAR *name, WORD flags, DISPPARAMS *dp, VARIANT *retv,
849 jsexcept_t *ei, IServiceProvider *caller)
854 hres = find_prop_name_prot(disp, name, TRUE, &prop);
858 memset(ei, 0, sizeof(*ei));
860 V_VT(retv) = VT_EMPTY;
862 return invoke_prop_func(disp, disp, prop, flags, dp, retv, ei, caller);
865 HRESULT disp_call(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD flags, DISPPARAMS *dp, VARIANT *retv,
866 jsexcept_t *ei, IServiceProvider *caller)
872 jsdisp = iface_to_jsdisp((IUnknown*)disp);
874 hres = jsdisp_call(jsdisp, id, flags, dp, retv, ei, caller);
875 jsdisp_release(jsdisp);
879 memset(ei, 0, sizeof(*ei));
882 V_VT(retv) = VT_EMPTY;
883 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
887 if(flags == DISPATCH_CONSTRUCT) {
888 WARN("IDispatch cannot be constructor\n");
889 return DISP_E_MEMBERNOTFOUND;
892 TRACE("using IDispatch\n");
893 return IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, flags, dp, retv, &ei->ei, &err);
896 hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, flags, dp, retv, &ei->ei, caller);
897 IDispatchEx_Release(dispex);
902 HRESULT jsdisp_propput_name(DispatchEx *obj, const WCHAR *name, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
904 DISPID named_arg = DISPID_PROPERTYPUT;
905 DISPPARAMS dp = {val, &named_arg, 1, 1};
909 hres = find_prop_name_prot(obj, name, TRUE, &prop);
913 return prop_put(obj, prop, lcid, &dp, ei, caller);
916 HRESULT jsdisp_propput_idx(DispatchEx *obj, DWORD idx, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
920 static const WCHAR formatW[] = {'%','d',0};
922 sprintfW(buf, formatW, idx);
923 return jsdisp_propput_name(obj, buf, lcid, val, ei, caller);
926 HRESULT disp_propput(IDispatch *disp, DISPID id, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
928 DISPID dispid = DISPID_PROPERTYPUT;
929 DISPPARAMS dp = {val, &dispid, 1, 1};
934 jsdisp = iface_to_jsdisp((IUnknown*)disp);
938 prop = get_prop(jsdisp, id);
940 hres = prop_put(jsdisp, prop, lcid, &dp, ei, caller);
942 hres = DISP_E_MEMBERNOTFOUND;
944 jsdisp_release(jsdisp);
948 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
952 TRACE("using IDispatch\n");
953 return IDispatch_Invoke(disp, id, &IID_NULL, DISPATCH_PROPERTYPUT, lcid, &dp, NULL, &ei->ei, &err);
956 hres = IDispatchEx_InvokeEx(dispex, id, lcid, DISPATCH_PROPERTYPUT, &dp, NULL, &ei->ei, caller);
958 IDispatchEx_Release(dispex);
962 HRESULT jsdisp_propget_name(DispatchEx *obj, const WCHAR *name, VARIANT *var, 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, &dp, var, ei, caller);
979 HRESULT jsdisp_propget_idx(DispatchEx *obj, DWORD idx, 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, var, ei, caller);
989 HRESULT jsdisp_propget(DispatchEx *jsdisp, DISPID id, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
991 DISPPARAMS dp = {NULL,NULL,0,0};
994 prop = get_prop(jsdisp, id);
996 return DISP_E_MEMBERNOTFOUND;
998 V_VT(val) = VT_EMPTY;
999 return prop_get(jsdisp, prop, &dp, val, ei, caller);
1002 HRESULT disp_propget(script_ctx_t *ctx, IDispatch *disp, DISPID id, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
1004 DISPPARAMS dp = {NULL,NULL,0,0};
1005 IDispatchEx *dispex;
1009 jsdisp = iface_to_jsdisp((IUnknown*)disp);
1011 hres = jsdisp_propget(jsdisp, id, val, ei, caller);
1012 jsdisp_release(jsdisp);
1016 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1020 TRACE("using IDispatch\n");
1021 return IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, INVOKE_PROPERTYGET, &dp, val, &ei->ei, &err);
1024 hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, INVOKE_PROPERTYGET, &dp, val, &ei->ei, caller);
1025 IDispatchEx_Release(dispex);
1030 HRESULT jsdisp_delete_idx(DispatchEx *obj, DWORD idx)
1032 static const WCHAR formatW[] = {'%','d',0};
1034 dispex_prop_t *prop;
1037 sprintfW(buf, formatW, idx);
1039 hres = find_prop_name(obj, buf, &prop);
1040 if(FAILED(hres) || !prop)
1043 return delete_prop(prop);