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
)
251 if(flags
== DISPATCH_CONSTRUCT
&& (prop
->flags
& DISPATCH_METHOD
)) {
252 WARN("%s is not a constructor\n", debugstr_w(prop
->name
));
256 set_jsdisp(&vthis
, jsthis
);
257 hres
= prop
->u
.p
->invoke(This
->ctx
, &vthis
, flags
, dp
, retv
, ei
, caller
);
258 vdisp_release(&vthis
);
262 return invoke_prop_func(This
->prototype
, jsthis
, This
->prototype
->props
+prop
->u
.ref
, flags
, dp
, retv
, ei
, caller
);
266 if(V_VT(&prop
->u
.var
) != VT_DISPATCH
) {
267 FIXME("invoke vt %d\n", V_VT(&prop
->u
.var
));
271 TRACE("call %s %p\n", debugstr_w(prop
->name
), V_DISPATCH(&prop
->u
.var
));
273 hres
= set_this(&new_dp
, dp
, (IDispatch
*)_IDispatchEx_(jsthis
));
277 hres
= disp_call(This
->ctx
, V_DISPATCH(&prop
->u
.var
), DISPID_VALUE
, flags
, &new_dp
, retv
, ei
, caller
);
279 if(new_dp
.rgvarg
!= dp
->rgvarg
) {
280 heap_free(new_dp
.rgvarg
);
281 if(new_dp
.cNamedArgs
> 1)
282 heap_free(new_dp
.rgdispidNamedArgs
);
288 ERR("type %d\n", prop
->type
);
294 static HRESULT
prop_get(DispatchEx
*This
, dispex_prop_t
*prop
, DISPPARAMS
*dp
,
295 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*caller
)
301 if(prop
->u
.p
->flags
& PROPF_METHOD
) {
303 hres
= create_builtin_function(This
->ctx
, prop
->u
.p
->invoke
, prop
->u
.p
->name
, NULL
,
304 prop
->u
.p
->flags
, NULL
, &obj
);
308 prop
->type
= PROP_VARIANT
;
309 V_VT(&prop
->u
.var
) = VT_DISPATCH
;
310 V_DISPATCH(&prop
->u
.var
) = (IDispatch
*)_IDispatchEx_(obj
);
312 hres
= VariantCopy(retv
, &prop
->u
.var
);
316 set_jsdisp(&vthis
, This
);
317 hres
= prop
->u
.p
->invoke(This
->ctx
, &vthis
, DISPATCH_PROPERTYGET
, dp
, retv
, ei
, caller
);
318 vdisp_release(&vthis
);
322 hres
= prop_get(This
->prototype
, This
->prototype
->props
+prop
->u
.ref
, dp
, retv
, ei
, caller
);
325 hres
= VariantCopy(retv
, &prop
->u
.var
);
328 ERR("type %d\n", prop
->type
);
333 TRACE("fail %08x\n", hres
);
337 TRACE("%s ret %s\n", debugstr_w(prop
->name
), debugstr_variant(retv
));
341 static HRESULT
prop_put(DispatchEx
*This
, dispex_prop_t
*prop
, DISPPARAMS
*dp
,
342 jsexcept_t
*ei
, IServiceProvider
*caller
)
349 if(!(prop
->flags
& PROPF_METHOD
)) {
352 set_jsdisp(&vthis
, This
);
353 hres
= prop
->u
.p
->invoke(This
->ctx
, &vthis
, DISPATCH_PROPERTYPUT
, dp
, NULL
, ei
, caller
);
354 vdisp_release(&vthis
);
358 prop
->type
= PROP_VARIANT
;
359 prop
->flags
= PROPF_ENUM
;
360 V_VT(&prop
->u
.var
) = VT_EMPTY
;
363 VariantClear(&prop
->u
.var
);
366 ERR("type %d\n", prop
->type
);
370 for(i
=0; i
< dp
->cNamedArgs
; i
++) {
371 if(dp
->rgdispidNamedArgs
[i
] == DISPID_PROPERTYPUT
)
375 if(i
== dp
->cNamedArgs
) {
376 TRACE("no value to set\n");
377 return DISP_E_PARAMNOTOPTIONAL
;
380 hres
= VariantCopy(&prop
->u
.var
, dp
->rgvarg
+i
);
384 if(This
->builtin_info
->on_put
)
385 This
->builtin_info
->on_put(This
, prop
->name
);
387 TRACE("%s = %s\n", debugstr_w(prop
->name
), debugstr_variant(dp
->rgvarg
+i
));
391 static HRESULT
fill_protrefs(DispatchEx
*This
)
393 dispex_prop_t
*iter
, *prop
;
399 fill_protrefs(This
->prototype
);
401 for(iter
= This
->prototype
->props
; iter
< This
->prototype
->props
+This
->prototype
->prop_cnt
; iter
++) {
404 hres
= find_prop_name(This
, iter
->name
, &prop
);
408 prop
= alloc_protref(This
, iter
->name
, iter
- This
->prototype
->props
);
410 return E_OUTOFMEMORY
;
417 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
419 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
421 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
423 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
424 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
425 *ppv
= _IDispatchEx_(This
);
426 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
427 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
428 *ppv
= _IDispatchEx_(This
);
429 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
430 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
431 *ppv
= _IDispatchEx_(This
);
432 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
433 TRACE("(%p)->(IID_IDispatchJS %p)\n", This
, ppv
);
434 IUnknown_AddRef(_IDispatchEx_(This
));
438 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
440 return E_NOINTERFACE
;
443 IUnknown_AddRef((IUnknown
*)*ppv
);
447 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
449 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
450 LONG ref
= InterlockedIncrement(&This
->ref
);
452 TRACE("(%p) ref=%d\n", This
, ref
);
457 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
459 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
460 LONG ref
= InterlockedDecrement(&This
->ref
);
462 TRACE("(%p) ref=%d\n", This
, ref
);
467 for(prop
= This
->props
; prop
< This
->props
+This
->prop_cnt
; prop
++) {
468 if(prop
->type
== PROP_VARIANT
)
469 VariantClear(&prop
->u
.var
);
470 heap_free(prop
->name
);
472 heap_free(This
->props
);
473 script_release(This
->ctx
);
475 if(This
->builtin_info
->destructor
)
476 This
->builtin_info
->destructor(This
);
484 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
486 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
488 TRACE("(%p)->(%p)\n", This
, pctinfo
);
494 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
, LCID lcid
,
497 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
498 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
502 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
503 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
,
506 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
510 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
513 for(i
=0; i
< cNames
; i
++) {
514 hres
= IDispatchEx_GetDispID(_IDispatchEx_(This
), rgszNames
[i
], 0, rgDispId
+i
);
522 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
523 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
524 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
526 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
528 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
529 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
531 return IDispatchEx_InvokeEx(_IDispatchEx_(This
), dispIdMember
, lcid
, wFlags
,
532 pDispParams
, pVarResult
, pExcepInfo
, NULL
);
535 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
537 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
539 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
541 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameEnsure
|fdexNameImplicit
)) {
542 FIXME("Unsupported grfdex %x\n", grfdex
);
546 return jsdisp_get_id(This
, bstrName
, grfdex
, pid
);
549 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
550 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
552 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
557 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
560 V_VT(pvarRes
) = VT_EMPTY
;
562 prop
= get_prop(This
, id
);
563 if(!prop
|| prop
->type
== PROP_DELETED
) {
564 TRACE("invalid id\n");
565 return DISP_E_MEMBERNOTFOUND
;
568 memset(&jsexcept
, 0, sizeof(jsexcept
));
571 case DISPATCH_METHOD
:
572 case DISPATCH_CONSTRUCT
:
573 hres
= invoke_prop_func(This
, This
, prop
, wFlags
, pdp
, pvarRes
, &jsexcept
, pspCaller
);
575 case DISPATCH_PROPERTYGET
:
576 hres
= prop_get(This
, prop
, pdp
, pvarRes
, &jsexcept
, pspCaller
);
578 case DISPATCH_PROPERTYPUT
:
579 hres
= prop_put(This
, prop
, pdp
, &jsexcept
, pspCaller
);
582 FIXME("Unimplemented flags %x\n", wFlags
);
592 static HRESULT
delete_prop(dispex_prop_t
*prop
)
594 heap_free(prop
->name
);
596 prop
->type
= PROP_DELETED
;
601 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
603 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
607 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
609 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameEnsure
|fdexNameImplicit
))
610 FIXME("Unsupported grfdex %x\n", grfdex
);
612 hres
= find_prop_name(This
, bstrName
, &prop
);
616 TRACE("not found\n");
620 return delete_prop(prop
);
623 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
625 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
628 TRACE("(%p)->(%x)\n", This
, id
);
630 prop
= get_prop(This
, id
);
632 WARN("invalid id\n");
633 return DISP_E_MEMBERNOTFOUND
;
636 return delete_prop(prop
);
639 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
641 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
642 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
646 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
648 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
651 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
653 prop
= get_prop(This
, id
);
654 if(!prop
|| !prop
->name
|| prop
->type
== PROP_DELETED
)
655 return DISP_E_MEMBERNOTFOUND
;
657 *pbstrName
= SysAllocString(prop
->name
);
659 return E_OUTOFMEMORY
;
664 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
666 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
670 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
672 if(id
== DISPID_STARTENUM
) {
673 hres
= fill_protrefs(This
);
678 iter
= get_prop(This
, id
+1);
680 *pid
= DISPID_STARTENUM
;
684 while(iter
< This
->props
+ This
->prop_cnt
) {
685 if(iter
->name
&& (get_flags(This
, iter
) & PROPF_ENUM
)) {
686 *pid
= prop_to_id(This
, iter
);
692 *pid
= DISPID_STARTENUM
;
696 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
698 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
699 FIXME("(%p)->(%p)\n", This
, ppunk
);
703 #undef DISPATCHEX_THIS
705 static IDispatchExVtbl DispatchExVtbl
= {
706 DispatchEx_QueryInterface
,
709 DispatchEx_GetTypeInfoCount
,
710 DispatchEx_GetTypeInfo
,
711 DispatchEx_GetIDsOfNames
,
713 DispatchEx_GetDispID
,
715 DispatchEx_DeleteMemberByName
,
716 DispatchEx_DeleteMemberByDispID
,
717 DispatchEx_GetMemberProperties
,
718 DispatchEx_GetMemberName
,
719 DispatchEx_GetNextDispID
,
720 DispatchEx_GetNameSpaceParent
723 HRESULT
init_dispex(DispatchEx
*dispex
, script_ctx_t
*ctx
, const builtin_info_t
*builtin_info
, DispatchEx
*prototype
)
725 TRACE("%p (%p)\n", dispex
, prototype
);
727 dispex
->lpIDispatchExVtbl
= &DispatchExVtbl
;
729 dispex
->builtin_info
= builtin_info
;
731 dispex
->props
= heap_alloc((dispex
->buf_size
=4) * sizeof(dispex_prop_t
));
733 return E_OUTOFMEMORY
;
735 dispex
->prototype
= prototype
;
737 IDispatchEx_AddRef(_IDispatchEx_(prototype
));
739 dispex
->prop_cnt
= 1;
740 dispex
->props
[0].name
= NULL
;
741 dispex
->props
[0].flags
= 0;
742 if(builtin_info
->value_prop
.invoke
) {
743 dispex
->props
[0].type
= PROP_BUILTIN
;
744 dispex
->props
[0].u
.p
= &builtin_info
->value_prop
;
746 dispex
->props
[0].type
= PROP_DELETED
;
755 static const builtin_info_t dispex_info
= {
763 HRESULT
create_dispex(script_ctx_t
*ctx
, const builtin_info_t
*builtin_info
, DispatchEx
*prototype
, DispatchEx
**dispex
)
768 ret
= heap_alloc_zero(sizeof(DispatchEx
));
770 return E_OUTOFMEMORY
;
772 hres
= init_dispex(ret
, ctx
, builtin_info
? builtin_info
: &dispex_info
, prototype
);
780 HRESULT
init_dispex_from_constr(DispatchEx
*dispex
, script_ctx_t
*ctx
, const builtin_info_t
*builtin_info
, DispatchEx
*constr
)
782 DispatchEx
*prot
= NULL
;
786 static const WCHAR prototypeW
[] = {'p','r','o','t','o','t','y','p','e',0};
788 hres
= find_prop_name_prot(constr
, prototypeW
, FALSE
, &prop
);
789 if(SUCCEEDED(hres
) && prop
) {
793 V_VT(&var
) = VT_EMPTY
;
794 memset(&jsexcept
, 0, sizeof(jsexcept
));
795 hres
= prop_get(constr
, prop
, NULL
, &var
, &jsexcept
, NULL
/*FIXME*/);
797 ERR("Could not get prototype\n");
801 if(V_VT(&var
) == VT_DISPATCH
)
802 prot
= iface_to_jsdisp((IUnknown
*)V_DISPATCH(&var
));
806 hres
= init_dispex(dispex
, ctx
, builtin_info
, prot
);
809 jsdisp_release(prot
);
813 DispatchEx
*iface_to_jsdisp(IUnknown
*iface
)
818 hres
= IUnknown_QueryInterface(iface
, &IID_IDispatchJS
, (void**)&ret
);
825 HRESULT
jsdisp_get_id(DispatchEx
*jsdisp
, const WCHAR
*name
, DWORD flags
, DISPID
*id
)
830 hres
= find_prop_name_prot(jsdisp
, name
, (flags
&fdexNameEnsure
) != 0, &prop
);
835 *id
= prop_to_id(jsdisp
, prop
);
839 TRACE("not found %s\n", debugstr_w(name
));
840 return DISP_E_UNKNOWNNAME
;
843 HRESULT
jsdisp_call_value(DispatchEx
*jsthis
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*retv
,
844 jsexcept_t
*ei
, IServiceProvider
*caller
)
849 set_jsdisp(&vdisp
, jsthis
);
850 hres
= jsthis
->builtin_info
->value_prop
.invoke(jsthis
->ctx
, &vdisp
, flags
, dp
, retv
, ei
, caller
);
851 vdisp_release(&vdisp
);
855 HRESULT
jsdisp_call(DispatchEx
*disp
, DISPID id
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*retv
,
856 jsexcept_t
*ei
, IServiceProvider
*caller
)
860 memset(ei
, 0, sizeof(*ei
));
862 V_VT(retv
) = VT_EMPTY
;
864 prop
= get_prop(disp
, id
);
866 return DISP_E_MEMBERNOTFOUND
;
868 return invoke_prop_func(disp
, disp
, prop
, flags
, dp
, retv
, ei
, caller
);
871 HRESULT
jsdisp_call_name(DispatchEx
*disp
, const WCHAR
*name
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*retv
,
872 jsexcept_t
*ei
, IServiceProvider
*caller
)
877 hres
= find_prop_name_prot(disp
, name
, TRUE
, &prop
);
881 memset(ei
, 0, sizeof(*ei
));
883 V_VT(retv
) = VT_EMPTY
;
885 return invoke_prop_func(disp
, disp
, prop
, flags
, dp
, retv
, ei
, caller
);
888 HRESULT
disp_call(script_ctx_t
*ctx
, IDispatch
*disp
, DISPID id
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*retv
,
889 jsexcept_t
*ei
, IServiceProvider
*caller
)
895 jsdisp
= iface_to_jsdisp((IUnknown
*)disp
);
897 hres
= jsdisp_call(jsdisp
, id
, flags
, dp
, retv
, ei
, caller
);
898 jsdisp_release(jsdisp
);
902 memset(ei
, 0, sizeof(*ei
));
905 V_VT(retv
) = VT_EMPTY
;
906 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
910 if(flags
== DISPATCH_CONSTRUCT
) {
911 WARN("IDispatch cannot be constructor\n");
912 return DISP_E_MEMBERNOTFOUND
;
915 TRACE("using IDispatch\n");
916 return IDispatch_Invoke(disp
, id
, &IID_NULL
, ctx
->lcid
, flags
, dp
, retv
, &ei
->ei
, &err
);
919 hres
= IDispatchEx_InvokeEx(dispex
, id
, ctx
->lcid
, flags
, dp
, retv
, &ei
->ei
, caller
);
920 IDispatchEx_Release(dispex
);
925 HRESULT
jsdisp_propput_name(DispatchEx
*obj
, const WCHAR
*name
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
927 DISPID named_arg
= DISPID_PROPERTYPUT
;
928 DISPPARAMS dp
= {val
, &named_arg
, 1, 1};
932 hres
= find_prop_name_prot(obj
, name
, TRUE
, &prop
);
936 return prop_put(obj
, prop
, &dp
, ei
, caller
);
939 HRESULT
jsdisp_propput_idx(DispatchEx
*obj
, DWORD idx
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
943 static const WCHAR formatW
[] = {'%','d',0};
945 sprintfW(buf
, formatW
, idx
);
946 return jsdisp_propput_name(obj
, buf
, val
, ei
, caller
);
949 HRESULT
disp_propput(script_ctx_t
*ctx
, IDispatch
*disp
, DISPID id
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
951 DISPID dispid
= DISPID_PROPERTYPUT
;
952 DISPPARAMS dp
= {val
, &dispid
, 1, 1};
957 jsdisp
= iface_to_jsdisp((IUnknown
*)disp
);
961 prop
= get_prop(jsdisp
, id
);
963 hres
= prop_put(jsdisp
, prop
, &dp
, ei
, caller
);
965 hres
= DISP_E_MEMBERNOTFOUND
;
967 jsdisp_release(jsdisp
);
971 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
975 TRACE("using IDispatch\n");
976 return IDispatch_Invoke(disp
, id
, &IID_NULL
, ctx
->lcid
, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
->ei
, &err
);
979 hres
= IDispatchEx_InvokeEx(dispex
, id
, ctx
->lcid
, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
->ei
, caller
);
981 IDispatchEx_Release(dispex
);
985 HRESULT
jsdisp_propget_name(DispatchEx
*obj
, const WCHAR
*name
, VARIANT
*var
, jsexcept_t
*ei
, IServiceProvider
*caller
)
987 DISPPARAMS dp
= {NULL
, NULL
, 0, 0};
991 hres
= find_prop_name_prot(obj
, name
, FALSE
, &prop
);
995 V_VT(var
) = VT_EMPTY
;
999 return prop_get(obj
, prop
, &dp
, var
, ei
, caller
);
1002 HRESULT
jsdisp_propget_idx(DispatchEx
*obj
, DWORD idx
, VARIANT
*var
, jsexcept_t
*ei
, IServiceProvider
*caller
)
1006 static const WCHAR formatW
[] = {'%','d',0};
1008 sprintfW(buf
, formatW
, idx
);
1009 return jsdisp_propget_name(obj
, buf
, var
, ei
, caller
);
1012 HRESULT
jsdisp_propget(DispatchEx
*jsdisp
, DISPID id
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
1014 DISPPARAMS dp
= {NULL
,NULL
,0,0};
1015 dispex_prop_t
*prop
;
1017 prop
= get_prop(jsdisp
, id
);
1019 return DISP_E_MEMBERNOTFOUND
;
1021 V_VT(val
) = VT_EMPTY
;
1022 return prop_get(jsdisp
, prop
, &dp
, val
, ei
, caller
);
1025 HRESULT
disp_propget(script_ctx_t
*ctx
, IDispatch
*disp
, DISPID id
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
1027 DISPPARAMS dp
= {NULL
,NULL
,0,0};
1028 IDispatchEx
*dispex
;
1032 jsdisp
= iface_to_jsdisp((IUnknown
*)disp
);
1034 hres
= jsdisp_propget(jsdisp
, id
, val
, ei
, caller
);
1035 jsdisp_release(jsdisp
);
1039 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
1043 TRACE("using IDispatch\n");
1044 return IDispatch_Invoke(disp
, id
, &IID_NULL
, ctx
->lcid
, INVOKE_PROPERTYGET
, &dp
, val
, &ei
->ei
, &err
);
1047 hres
= IDispatchEx_InvokeEx(dispex
, id
, ctx
->lcid
, INVOKE_PROPERTYGET
, &dp
, val
, &ei
->ei
, caller
);
1048 IDispatchEx_Release(dispex
);
1053 HRESULT
jsdisp_delete_idx(DispatchEx
*obj
, DWORD idx
)
1055 static const WCHAR formatW
[] = {'%','d',0};
1057 dispex_prop_t
*prop
;
1060 sprintfW(buf
, formatW
, idx
);
1062 hres
= find_prop_name(obj
, buf
, &prop
);
1063 if(FAILED(hres
) || !prop
)
1066 return delete_prop(prop
);