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
, DWORD create_flags
, dispex_prop_t
**ret
)
198 hres
= find_prop_name_prot(This
, name
, &prop
);
199 if(SUCCEEDED(hres
) && !prop
) {
200 TRACE("creating prop %s\n", debugstr_w(name
));
202 prop
= alloc_prop(This
, name
, PROP_VARIANT
, create_flags
);
204 return E_OUTOFMEMORY
;
205 VariantInit(&prop
->u
.var
);
212 static HRESULT
set_this(DISPPARAMS
*dp
, DISPPARAMS
*olddp
, IDispatch
*jsthis
)
217 static DISPID this_id
= DISPID_THIS
;
221 for(i
= 0; i
< dp
->cNamedArgs
; i
++) {
222 if(dp
->rgdispidNamedArgs
[i
] == DISPID_THIS
)
226 oldargs
= dp
->rgvarg
;
227 dp
->rgvarg
= heap_alloc((dp
->cArgs
+1) * sizeof(VARIANTARG
));
229 return E_OUTOFMEMORY
;
230 memcpy(dp
->rgvarg
+1, oldargs
, dp
->cArgs
*sizeof(VARIANTARG
));
231 V_VT(dp
->rgvarg
) = VT_DISPATCH
;
232 V_DISPATCH(dp
->rgvarg
) = jsthis
;
236 DISPID
*old
= dp
->rgdispidNamedArgs
;
237 dp
->rgdispidNamedArgs
= heap_alloc((dp
->cNamedArgs
+1)*sizeof(DISPID
));
238 if(!dp
->rgdispidNamedArgs
) {
239 heap_free(dp
->rgvarg
);
240 return E_OUTOFMEMORY
;
243 memcpy(dp
->rgdispidNamedArgs
+1, old
, dp
->cNamedArgs
*sizeof(DISPID
));
244 dp
->rgdispidNamedArgs
[0] = DISPID_THIS
;
247 dp
->rgdispidNamedArgs
= &this_id
;
254 static HRESULT
invoke_prop_func(DispatchEx
*This
, DispatchEx
*jsthis
, dispex_prop_t
*prop
, WORD flags
,
255 DISPPARAMS
*dp
, VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*caller
)
263 if(flags
== DISPATCH_CONSTRUCT
&& (prop
->flags
& DISPATCH_METHOD
)) {
264 WARN("%s is not a constructor\n", debugstr_w(prop
->name
));
268 set_jsdisp(&vthis
, jsthis
);
269 hres
= prop
->u
.p
->invoke(This
->ctx
, &vthis
, flags
, dp
, retv
, ei
, caller
);
270 vdisp_release(&vthis
);
274 return invoke_prop_func(This
->prototype
, jsthis
, This
->prototype
->props
+prop
->u
.ref
, flags
, dp
, retv
, ei
, caller
);
278 if(V_VT(&prop
->u
.var
) != VT_DISPATCH
) {
279 FIXME("invoke vt %d\n", V_VT(&prop
->u
.var
));
283 TRACE("call %s %p\n", debugstr_w(prop
->name
), V_DISPATCH(&prop
->u
.var
));
285 hres
= set_this(&new_dp
, dp
, (IDispatch
*)_IDispatchEx_(jsthis
));
289 hres
= disp_call(This
->ctx
, V_DISPATCH(&prop
->u
.var
), DISPID_VALUE
, flags
, &new_dp
, retv
, ei
, caller
);
291 if(new_dp
.rgvarg
!= dp
->rgvarg
) {
292 heap_free(new_dp
.rgvarg
);
293 if(new_dp
.cNamedArgs
> 1)
294 heap_free(new_dp
.rgdispidNamedArgs
);
300 ERR("type %d\n", prop
->type
);
306 static HRESULT
prop_get(DispatchEx
*This
, dispex_prop_t
*prop
, DISPPARAMS
*dp
,
307 VARIANT
*retv
, jsexcept_t
*ei
, IServiceProvider
*caller
)
313 if(prop
->u
.p
->flags
& PROPF_METHOD
) {
315 hres
= create_builtin_function(This
->ctx
, prop
->u
.p
->invoke
, prop
->u
.p
->name
, NULL
,
316 prop
->u
.p
->flags
, NULL
, &obj
);
320 prop
->type
= PROP_VARIANT
;
321 V_VT(&prop
->u
.var
) = VT_DISPATCH
;
322 V_DISPATCH(&prop
->u
.var
) = (IDispatch
*)_IDispatchEx_(obj
);
324 hres
= VariantCopy(retv
, &prop
->u
.var
);
328 set_jsdisp(&vthis
, This
);
329 hres
= prop
->u
.p
->invoke(This
->ctx
, &vthis
, DISPATCH_PROPERTYGET
, dp
, retv
, ei
, caller
);
330 vdisp_release(&vthis
);
334 hres
= prop_get(This
->prototype
, This
->prototype
->props
+prop
->u
.ref
, dp
, retv
, ei
, caller
);
337 hres
= VariantCopy(retv
, &prop
->u
.var
);
340 ERR("type %d\n", prop
->type
);
345 TRACE("fail %08x\n", hres
);
349 TRACE("%s ret %s\n", debugstr_w(prop
->name
), debugstr_variant(retv
));
353 static HRESULT
prop_put(DispatchEx
*This
, dispex_prop_t
*prop
, DISPPARAMS
*dp
,
354 jsexcept_t
*ei
, IServiceProvider
*caller
)
361 if(!(prop
->flags
& PROPF_METHOD
)) {
364 set_jsdisp(&vthis
, This
);
365 hres
= prop
->u
.p
->invoke(This
->ctx
, &vthis
, DISPATCH_PROPERTYPUT
, dp
, NULL
, ei
, caller
);
366 vdisp_release(&vthis
);
370 prop
->type
= PROP_VARIANT
;
371 prop
->flags
= PROPF_ENUM
;
372 V_VT(&prop
->u
.var
) = VT_EMPTY
;
375 VariantClear(&prop
->u
.var
);
378 ERR("type %d\n", prop
->type
);
382 for(i
=0; i
< dp
->cNamedArgs
; i
++) {
383 if(dp
->rgdispidNamedArgs
[i
] == DISPID_PROPERTYPUT
)
387 if(i
== dp
->cNamedArgs
) {
388 TRACE("no value to set\n");
389 return DISP_E_PARAMNOTOPTIONAL
;
392 hres
= VariantCopy(&prop
->u
.var
, dp
->rgvarg
+i
);
396 if(This
->builtin_info
->on_put
)
397 This
->builtin_info
->on_put(This
, prop
->name
);
399 TRACE("%s = %s\n", debugstr_w(prop
->name
), debugstr_variant(dp
->rgvarg
+i
));
403 static HRESULT
fill_protrefs(DispatchEx
*This
)
405 dispex_prop_t
*iter
, *prop
;
411 fill_protrefs(This
->prototype
);
413 for(iter
= This
->prototype
->props
; iter
< This
->prototype
->props
+This
->prototype
->prop_cnt
; iter
++) {
416 hres
= find_prop_name(This
, iter
->name
, &prop
);
420 prop
= alloc_protref(This
, iter
->name
, iter
- This
->prototype
->props
);
422 return E_OUTOFMEMORY
;
429 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
431 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
433 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
435 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
436 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
437 *ppv
= _IDispatchEx_(This
);
438 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
439 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
440 *ppv
= _IDispatchEx_(This
);
441 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
442 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
443 *ppv
= _IDispatchEx_(This
);
444 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
445 TRACE("(%p)->(IID_IDispatchJS %p)\n", This
, ppv
);
446 IUnknown_AddRef(_IDispatchEx_(This
));
450 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
452 return E_NOINTERFACE
;
455 IUnknown_AddRef((IUnknown
*)*ppv
);
459 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
461 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
462 LONG ref
= InterlockedIncrement(&This
->ref
);
464 TRACE("(%p) ref=%d\n", This
, ref
);
469 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
471 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
472 LONG ref
= InterlockedDecrement(&This
->ref
);
474 TRACE("(%p) ref=%d\n", This
, ref
);
479 for(prop
= This
->props
; prop
< This
->props
+This
->prop_cnt
; prop
++) {
480 if(prop
->type
== PROP_VARIANT
)
481 VariantClear(&prop
->u
.var
);
482 heap_free(prop
->name
);
484 heap_free(This
->props
);
485 script_release(This
->ctx
);
487 jsdisp_release(This
->prototype
);
489 if(This
->builtin_info
->destructor
)
490 This
->builtin_info
->destructor(This
);
498 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
500 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
502 TRACE("(%p)->(%p)\n", This
, pctinfo
);
508 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
, LCID lcid
,
511 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
512 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
516 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
517 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
,
520 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
524 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
527 for(i
=0; i
< cNames
; i
++) {
528 hres
= IDispatchEx_GetDispID(_IDispatchEx_(This
), rgszNames
[i
], 0, rgDispId
+i
);
536 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
537 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
538 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
540 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
542 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
543 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
545 return IDispatchEx_InvokeEx(_IDispatchEx_(This
), dispIdMember
, lcid
, wFlags
,
546 pDispParams
, pVarResult
, pExcepInfo
, NULL
);
549 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
551 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
553 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
555 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
)) {
556 FIXME("Unsupported grfdex %x\n", grfdex
);
560 return jsdisp_get_id(This
, bstrName
, grfdex
, pid
);
563 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
564 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
566 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
571 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
574 V_VT(pvarRes
) = VT_EMPTY
;
576 prop
= get_prop(This
, id
);
577 if(!prop
|| prop
->type
== PROP_DELETED
) {
578 TRACE("invalid id\n");
579 return DISP_E_MEMBERNOTFOUND
;
582 memset(&jsexcept
, 0, sizeof(jsexcept
));
585 case DISPATCH_METHOD
:
586 case DISPATCH_CONSTRUCT
:
587 hres
= invoke_prop_func(This
, This
, prop
, wFlags
, pdp
, pvarRes
, &jsexcept
, pspCaller
);
589 case DISPATCH_PROPERTYGET
:
590 hres
= prop_get(This
, prop
, pdp
, pvarRes
, &jsexcept
, pspCaller
);
592 case DISPATCH_PROPERTYPUT
:
593 hres
= prop_put(This
, prop
, pdp
, &jsexcept
, pspCaller
);
596 FIXME("Unimplemented flags %x\n", wFlags
);
606 static HRESULT
delete_prop(dispex_prop_t
*prop
)
608 heap_free(prop
->name
);
610 prop
->type
= PROP_DELETED
;
615 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
617 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
621 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
623 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
624 FIXME("Unsupported grfdex %x\n", grfdex
);
626 hres
= find_prop_name(This
, bstrName
, &prop
);
630 TRACE("not found\n");
634 return delete_prop(prop
);
637 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
639 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
642 TRACE("(%p)->(%x)\n", This
, id
);
644 prop
= get_prop(This
, id
);
646 WARN("invalid id\n");
647 return DISP_E_MEMBERNOTFOUND
;
650 return delete_prop(prop
);
653 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
655 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
656 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
660 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
662 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
665 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
667 prop
= get_prop(This
, id
);
668 if(!prop
|| !prop
->name
|| prop
->type
== PROP_DELETED
)
669 return DISP_E_MEMBERNOTFOUND
;
671 *pbstrName
= SysAllocString(prop
->name
);
673 return E_OUTOFMEMORY
;
678 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
680 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
684 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
686 if(id
== DISPID_STARTENUM
) {
687 hres
= fill_protrefs(This
);
692 iter
= get_prop(This
, id
+1);
694 *pid
= DISPID_STARTENUM
;
698 while(iter
< This
->props
+ This
->prop_cnt
) {
699 if(iter
->name
&& (get_flags(This
, iter
) & PROPF_ENUM
)) {
700 *pid
= prop_to_id(This
, iter
);
706 *pid
= DISPID_STARTENUM
;
710 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
712 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
713 FIXME("(%p)->(%p)\n", This
, ppunk
);
717 #undef DISPATCHEX_THIS
719 static IDispatchExVtbl DispatchExVtbl
= {
720 DispatchEx_QueryInterface
,
723 DispatchEx_GetTypeInfoCount
,
724 DispatchEx_GetTypeInfo
,
725 DispatchEx_GetIDsOfNames
,
727 DispatchEx_GetDispID
,
729 DispatchEx_DeleteMemberByName
,
730 DispatchEx_DeleteMemberByDispID
,
731 DispatchEx_GetMemberProperties
,
732 DispatchEx_GetMemberName
,
733 DispatchEx_GetNextDispID
,
734 DispatchEx_GetNameSpaceParent
737 HRESULT
init_dispex(DispatchEx
*dispex
, script_ctx_t
*ctx
, const builtin_info_t
*builtin_info
, DispatchEx
*prototype
)
739 TRACE("%p (%p)\n", dispex
, prototype
);
741 dispex
->lpIDispatchExVtbl
= &DispatchExVtbl
;
743 dispex
->builtin_info
= builtin_info
;
745 dispex
->props
= heap_alloc((dispex
->buf_size
=4) * sizeof(dispex_prop_t
));
747 return E_OUTOFMEMORY
;
749 dispex
->prototype
= prototype
;
751 IDispatchEx_AddRef(_IDispatchEx_(prototype
));
753 dispex
->prop_cnt
= 1;
754 dispex
->props
[0].name
= NULL
;
755 dispex
->props
[0].flags
= 0;
756 if(builtin_info
->value_prop
.invoke
) {
757 dispex
->props
[0].type
= PROP_BUILTIN
;
758 dispex
->props
[0].u
.p
= &builtin_info
->value_prop
;
760 dispex
->props
[0].type
= PROP_DELETED
;
769 static const builtin_info_t dispex_info
= {
777 HRESULT
create_dispex(script_ctx_t
*ctx
, const builtin_info_t
*builtin_info
, DispatchEx
*prototype
, DispatchEx
**dispex
)
782 ret
= heap_alloc_zero(sizeof(DispatchEx
));
784 return E_OUTOFMEMORY
;
786 hres
= init_dispex(ret
, ctx
, builtin_info
? builtin_info
: &dispex_info
, prototype
);
794 HRESULT
init_dispex_from_constr(DispatchEx
*dispex
, script_ctx_t
*ctx
, const builtin_info_t
*builtin_info
, DispatchEx
*constr
)
796 DispatchEx
*prot
= NULL
;
800 static const WCHAR prototypeW
[] = {'p','r','o','t','o','t','y','p','e',0};
802 hres
= find_prop_name_prot(constr
, prototypeW
, &prop
);
803 if(SUCCEEDED(hres
) && prop
) {
807 V_VT(&var
) = VT_EMPTY
;
808 memset(&jsexcept
, 0, sizeof(jsexcept
));
809 hres
= prop_get(constr
, prop
, NULL
, &var
, &jsexcept
, NULL
/*FIXME*/);
811 ERR("Could not get prototype\n");
815 if(V_VT(&var
) == VT_DISPATCH
)
816 prot
= iface_to_jsdisp((IUnknown
*)V_DISPATCH(&var
));
820 hres
= init_dispex(dispex
, ctx
, builtin_info
, prot
);
823 jsdisp_release(prot
);
827 DispatchEx
*iface_to_jsdisp(IUnknown
*iface
)
832 hres
= IUnknown_QueryInterface(iface
, &IID_IDispatchJS
, (void**)&ret
);
839 HRESULT
jsdisp_get_id(DispatchEx
*jsdisp
, const WCHAR
*name
, DWORD flags
, DISPID
*id
)
844 if(flags
& fdexNameEnsure
)
845 hres
= ensure_prop_name(jsdisp
, name
, PROPF_ENUM
, &prop
);
847 hres
= find_prop_name_prot(jsdisp
, name
, &prop
);
852 *id
= prop_to_id(jsdisp
, prop
);
856 TRACE("not found %s\n", debugstr_w(name
));
857 return DISP_E_UNKNOWNNAME
;
860 HRESULT
jsdisp_call_value(DispatchEx
*jsthis
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*retv
,
861 jsexcept_t
*ei
, IServiceProvider
*caller
)
866 set_jsdisp(&vdisp
, jsthis
);
867 hres
= jsthis
->builtin_info
->value_prop
.invoke(jsthis
->ctx
, &vdisp
, flags
, dp
, retv
, ei
, caller
);
868 vdisp_release(&vdisp
);
872 HRESULT
jsdisp_call(DispatchEx
*disp
, DISPID id
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*retv
,
873 jsexcept_t
*ei
, IServiceProvider
*caller
)
877 memset(ei
, 0, sizeof(*ei
));
879 V_VT(retv
) = VT_EMPTY
;
881 prop
= get_prop(disp
, id
);
883 return DISP_E_MEMBERNOTFOUND
;
885 return invoke_prop_func(disp
, disp
, prop
, flags
, dp
, retv
, ei
, caller
);
888 HRESULT
jsdisp_call_name(DispatchEx
*disp
, const WCHAR
*name
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*retv
,
889 jsexcept_t
*ei
, IServiceProvider
*caller
)
894 hres
= find_prop_name_prot(disp
, name
, &prop
);
898 memset(ei
, 0, sizeof(*ei
));
900 V_VT(retv
) = VT_EMPTY
;
902 return invoke_prop_func(disp
, disp
, prop
, flags
, dp
, retv
, ei
, caller
);
905 HRESULT
disp_call(script_ctx_t
*ctx
, IDispatch
*disp
, DISPID id
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*retv
,
906 jsexcept_t
*ei
, IServiceProvider
*caller
)
912 jsdisp
= iface_to_jsdisp((IUnknown
*)disp
);
914 hres
= jsdisp_call(jsdisp
, id
, flags
, dp
, retv
, ei
, caller
);
915 jsdisp_release(jsdisp
);
919 memset(ei
, 0, sizeof(*ei
));
922 V_VT(retv
) = VT_EMPTY
;
923 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
927 if(flags
== DISPATCH_CONSTRUCT
) {
928 WARN("IDispatch cannot be constructor\n");
929 return DISP_E_MEMBERNOTFOUND
;
932 TRACE("using IDispatch\n");
933 return IDispatch_Invoke(disp
, id
, &IID_NULL
, ctx
->lcid
, flags
, dp
, retv
, &ei
->ei
, &err
);
936 hres
= IDispatchEx_InvokeEx(dispex
, id
, ctx
->lcid
, flags
, dp
, retv
, &ei
->ei
, caller
);
937 IDispatchEx_Release(dispex
);
942 HRESULT
jsdisp_propput_name(DispatchEx
*obj
, const WCHAR
*name
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
944 DISPID named_arg
= DISPID_PROPERTYPUT
;
945 DISPPARAMS dp
= {val
, &named_arg
, 1, 1};
949 hres
= ensure_prop_name(obj
, name
, PROPF_ENUM
, &prop
);
953 return prop_put(obj
, prop
, &dp
, ei
, caller
);
956 HRESULT
jsdisp_propput_idx(DispatchEx
*obj
, DWORD idx
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
960 static const WCHAR formatW
[] = {'%','d',0};
962 sprintfW(buf
, formatW
, idx
);
963 return jsdisp_propput_name(obj
, buf
, val
, ei
, caller
);
966 HRESULT
disp_propput(script_ctx_t
*ctx
, IDispatch
*disp
, DISPID id
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
968 DISPID dispid
= DISPID_PROPERTYPUT
;
969 DISPPARAMS dp
= {val
, &dispid
, 1, 1};
974 jsdisp
= iface_to_jsdisp((IUnknown
*)disp
);
978 prop
= get_prop(jsdisp
, id
);
980 hres
= prop_put(jsdisp
, prop
, &dp
, ei
, caller
);
982 hres
= DISP_E_MEMBERNOTFOUND
;
984 jsdisp_release(jsdisp
);
988 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
992 TRACE("using IDispatch\n");
993 return IDispatch_Invoke(disp
, id
, &IID_NULL
, ctx
->lcid
, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
->ei
, &err
);
996 hres
= IDispatchEx_InvokeEx(dispex
, id
, ctx
->lcid
, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
->ei
, caller
);
998 IDispatchEx_Release(dispex
);
1002 HRESULT
jsdisp_propget_name(DispatchEx
*obj
, const WCHAR
*name
, VARIANT
*var
, jsexcept_t
*ei
, IServiceProvider
*caller
)
1004 DISPPARAMS dp
= {NULL
, NULL
, 0, 0};
1005 dispex_prop_t
*prop
;
1008 hres
= find_prop_name_prot(obj
, name
, &prop
);
1012 V_VT(var
) = VT_EMPTY
;
1016 return prop_get(obj
, prop
, &dp
, var
, ei
, caller
);
1019 HRESULT
jsdisp_get_idx(DispatchEx
*obj
, DWORD idx
, VARIANT
*var
, jsexcept_t
*ei
, IServiceProvider
*caller
)
1022 DISPPARAMS dp
= {NULL
, NULL
, 0, 0};
1023 dispex_prop_t
*prop
;
1026 static const WCHAR formatW
[] = {'%','d',0};
1028 sprintfW(name
, formatW
, idx
);
1030 hres
= find_prop_name_prot(obj
, name
, &prop
);
1034 V_VT(var
) = VT_EMPTY
;
1036 return DISP_E_UNKNOWNNAME
;
1038 return prop_get(obj
, prop
, &dp
, var
, ei
, caller
);
1041 HRESULT
jsdisp_propget(DispatchEx
*jsdisp
, DISPID id
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
1043 DISPPARAMS dp
= {NULL
,NULL
,0,0};
1044 dispex_prop_t
*prop
;
1046 prop
= get_prop(jsdisp
, id
);
1048 return DISP_E_MEMBERNOTFOUND
;
1050 V_VT(val
) = VT_EMPTY
;
1051 return prop_get(jsdisp
, prop
, &dp
, val
, ei
, caller
);
1054 HRESULT
disp_propget(script_ctx_t
*ctx
, IDispatch
*disp
, DISPID id
, VARIANT
*val
, jsexcept_t
*ei
, IServiceProvider
*caller
)
1056 DISPPARAMS dp
= {NULL
,NULL
,0,0};
1057 IDispatchEx
*dispex
;
1061 jsdisp
= iface_to_jsdisp((IUnknown
*)disp
);
1063 hres
= jsdisp_propget(jsdisp
, id
, val
, ei
, caller
);
1064 jsdisp_release(jsdisp
);
1068 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
1072 TRACE("using IDispatch\n");
1073 return IDispatch_Invoke(disp
, id
, &IID_NULL
, ctx
->lcid
, INVOKE_PROPERTYGET
, &dp
, val
, &ei
->ei
, &err
);
1076 hres
= IDispatchEx_InvokeEx(dispex
, id
, ctx
->lcid
, INVOKE_PROPERTYGET
, &dp
, val
, &ei
->ei
, caller
);
1077 IDispatchEx_Release(dispex
);
1082 HRESULT
jsdisp_delete_idx(DispatchEx
*obj
, DWORD idx
)
1084 static const WCHAR formatW
[] = {'%','d',0};
1086 dispex_prop_t
*prop
;
1089 sprintfW(buf
, formatW
, idx
);
1091 hres
= find_prop_name(obj
, buf
, &prop
);
1092 if(FAILED(hres
) || !prop
)
1095 return delete_prop(prop
);