2 * Copyright 2008-2009 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
23 #define NONAMELESSUNION
30 #include "wine/debug.h"
32 #include "mshtml_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 static CRITICAL_SECTION cs_dispex_static_data
;
39 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg
=
41 0, 0, &cs_dispex_static_data
,
42 { &cs_dispex_static_data_dbg
.ProcessLocksList
, &cs_dispex_static_data_dbg
.ProcessLocksList
},
43 0, 0, { (DWORD_PTR
)(__FILE__
": dispex_static_data") }
45 static CRITICAL_SECTION cs_dispex_static_data
= { &cs_dispex_static_data_dbg
, -1, 0, 0, 0, 0 };
48 static const WCHAR objectW
[] = {'[','o','b','j','e','c','t',']',0};
63 struct dispex_data_t
{
64 const dispex_static_data_t
*desc
;
69 func_info_t
**name_table
;
81 #define DYNPROP_DELETED 0x01
85 IUnknown IUnknown_iface
;
92 func_disp_t
*func_obj
;
96 struct dispex_dynamic_data_t
{
99 dynamic_prop_t
*props
;
100 func_obj_entry_t
*func_disps
;
103 #define DISPID_DYNPROP_0 0x50000000
104 #define DISPID_DYNPROP_MAX 0x5fffffff
106 #define FDEX_VERSION_MASK 0xf0000000
108 static ITypeLib
*typelib
;
109 static ITypeInfo
*typeinfos
[LAST_tid
];
110 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
112 static REFIID tid_ids
[] = {
113 #define XIID(iface) &IID_ ## iface,
114 #define XDIID(iface) &DIID_ ## iface,
120 static HRESULT
load_typelib(void)
125 hres
= LoadRegTypeLib(&LIBID_MSHTML
, 4, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
127 ERR("LoadRegTypeLib failed: %08x\n", hres
);
131 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
132 ITypeLib_Release(tl
);
136 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
141 hres
= load_typelib();
145 if(!typeinfos
[tid
]) {
148 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
150 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_mshtml_guid(tid_ids
[tid
]), hres
);
154 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
155 ITypeInfo_Release(ti
);
158 *typeinfo
= typeinfos
[tid
];
162 void release_typelib(void)
167 while(!list_empty(&dispex_data_list
)) {
168 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
169 list_remove(&iter
->entry
);
171 for(i
=0; i
< iter
->func_cnt
; i
++)
172 SysFreeString(iter
->funcs
[i
].name
);
174 heap_free(iter
->funcs
);
175 heap_free(iter
->name_table
);
182 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
184 ITypeInfo_Release(typeinfos
[i
]);
186 ITypeLib_Release(typelib
);
187 DeleteCriticalSection(&cs_dispex_static_data
);
190 HRESULT
get_htmldoc_classinfo(ITypeInfo
**typeinfo
)
195 hres
= load_typelib();
199 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, &CLSID_HTMLDocument
, typeinfo
);
201 ERR("GetTypeInfoOfGuid failed: %08x\n", hres
);
205 /* Not all argument types are supported yet */
206 #define BUILTIN_ARG_TYPES_SWITCH \
207 CASE_VT(VT_I2, INT16, V_I2); \
208 CASE_VT(VT_I4, INT32, V_I4); \
209 CASE_VT(VT_R4, float, V_R4); \
210 CASE_VT(VT_BSTR, BSTR, V_BSTR); \
211 CASE_VT(VT_BOOL, VARIANT_BOOL, V_BOOL)
213 /* List all types used by IDispatchEx-based properties */
214 #define BUILTIN_TYPES_SWITCH \
215 BUILTIN_ARG_TYPES_SWITCH; \
216 CASE_VT(VT_VARIANT, VARIANT, *); \
217 CASE_VT(VT_PTR, void*, V_BYREF); \
218 CASE_VT(VT_UNKNOWN, IUnknown*, V_UNKNOWN); \
219 CASE_VT(VT_DISPATCH, IDispatch*, V_DISPATCH)
221 static BOOL
is_arg_type_supported(VARTYPE vt
)
224 #define CASE_VT(x,a,b) case x: return TRUE
225 BUILTIN_ARG_TYPES_SWITCH
;
231 static void add_func_info(dispex_data_t
*data
, tid_t tid
, const FUNCDESC
*desc
, ITypeInfo
*dti
)
237 hres
= ITypeInfo_GetDocumentation(dti
, desc
->memid
, &name
, NULL
, NULL
, NULL
);
241 for(info
= data
->funcs
; info
< data
->funcs
+data
->func_cnt
; info
++) {
242 if(info
->id
== desc
->memid
|| !strcmpW(info
->name
, name
)) {
243 if(info
->tid
!= tid
) {
245 return; /* Duplicated in other interface */
251 if(info
== data
->funcs
+data
->func_cnt
) {
252 if(data
->func_cnt
== data
->func_size
)
253 data
->funcs
= heap_realloc_zero(data
->funcs
, (data
->func_size
<<= 1)*sizeof(func_info_t
));
254 info
= data
->funcs
+data
->func_cnt
;
258 info
->id
= desc
->memid
;
261 info
->func_disp_idx
= -1;
262 info
->prop_vt
= VT_EMPTY
;
267 if(desc
->invkind
& DISPATCH_METHOD
) {
270 info
->func_disp_idx
= data
->func_disp_cnt
++;
271 info
->argc
= desc
->cParams
;
273 assert(info
->argc
< MAX_ARGS
);
274 assert(desc
->funckind
== FUNC_DISPATCH
);
276 info
->arg_types
= heap_alloc(sizeof(*info
->arg_types
) * info
->argc
);
278 return; /* FIXME: real error instead of fallback */
280 for(i
=0; i
< info
->argc
; i
++)
281 info
->arg_types
[i
] = desc
->lprgelemdescParam
[i
].tdesc
.vt
;
283 info
->prop_vt
= desc
->elemdescFunc
.tdesc
.vt
;
284 if(info
->prop_vt
!= VT_VOID
&& !is_arg_type_supported(info
->prop_vt
)) {
285 TRACE("%s: return type %d\n", debugstr_w(info
->name
), info
->prop_vt
);
286 return; /* Fallback to ITypeInfo::Invoke */
289 if(desc
->cParamsOpt
) {
290 TRACE("%s: optional params\n", debugstr_w(info
->name
));
291 return; /* Fallback to ITypeInfo::Invoke */
294 for(i
=0; i
< info
->argc
; i
++) {
295 if(!is_arg_type_supported(info
->arg_types
[i
])) {
296 return; /* Fallback to ITypeInfo for unsupported arg types */
299 if(desc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
300 TRACE("%s param %d: default value\n", debugstr_w(info
->name
), i
);
301 return; /* Fallback to ITypeInfo::Invoke */
305 assert(info
->argc
<= MAX_ARGS
);
306 assert(desc
->callconv
== CC_STDCALL
);
308 info
->call_vtbl_off
= desc
->oVft
/sizeof(void*);
309 }else if(desc
->invkind
& (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYGET
)) {
310 VARTYPE vt
= VT_EMPTY
;
312 if(desc
->invkind
& DISPATCH_PROPERTYGET
) {
313 vt
= desc
->elemdescFunc
.tdesc
.vt
;
314 info
->get_vtbl_off
= desc
->oVft
/sizeof(void*);
316 if(desc
->invkind
& DISPATCH_PROPERTYPUT
) {
317 assert(desc
->cParams
== 1);
318 vt
= desc
->lprgelemdescParam
->tdesc
.vt
;
319 info
->put_vtbl_off
= desc
->oVft
/sizeof(void*);
322 assert(info
->prop_vt
== VT_EMPTY
|| vt
== info
->prop_vt
);
327 static HRESULT
process_interface(dispex_data_t
*data
, tid_t tid
, ITypeInfo
*disp_typeinfo
)
329 unsigned i
= 7; /* skip IDispatch functions */
334 hres
= get_typeinfo(tid
, &typeinfo
);
339 hres
= ITypeInfo_GetFuncDesc(typeinfo
, i
++, &funcdesc
);
343 TRACE("adding...\n");
345 add_func_info(data
, tid
, funcdesc
, disp_typeinfo
? disp_typeinfo
: typeinfo
);
346 ITypeInfo_ReleaseFuncDesc(typeinfo
, funcdesc
);
352 void dispex_info_add_interface(dispex_data_t
*info
, tid_t tid
)
356 hres
= process_interface(info
, tid
, NULL
);
358 ERR("process_interface failed: %08x\n", hres
);
361 static int dispid_cmp(const void *p1
, const void *p2
)
363 return ((const func_info_t
*)p1
)->id
- ((const func_info_t
*)p2
)->id
;
366 static int func_name_cmp(const void *p1
, const void *p2
)
368 return strcmpiW((*(func_info_t
* const*)p1
)->name
, (*(func_info_t
* const*)p2
)->name
);
371 static dispex_data_t
*preprocess_dispex_data(const dispex_static_data_t
*desc
, compat_mode_t compat_mode
)
380 hres
= get_typeinfo(desc
->disp_tid
, &dti
);
382 ERR("Could not get disp type info: %08x\n", hres
);
387 data
= heap_alloc(sizeof(dispex_data_t
));
389 ERR("Out of memory\n");
394 data
->func_disp_cnt
= 0;
395 data
->func_size
= 16;
396 data
->funcs
= heap_alloc_zero(data
->func_size
*sizeof(func_info_t
));
399 ERR("Out of memory\n");
402 list_add_tail(&dispex_data_list
, &data
->entry
);
405 desc
->init_info(data
, compat_mode
);
407 for(tid
= desc
->iface_tids
; *tid
; tid
++) {
408 hres
= process_interface(data
, *tid
, dti
);
413 if(!data
->func_cnt
) {
414 heap_free(data
->funcs
);
415 data
->name_table
= NULL
;
422 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
423 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
425 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
426 for(i
=0; i
< data
->func_cnt
; i
++)
427 data
->name_table
[i
] = data
->funcs
+i
;
428 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
432 static int id_cmp(const void *p1
, const void *p2
)
434 return *(const DISPID
*)p1
- *(const DISPID
*)p2
;
437 HRESULT
get_dispids(tid_t tid
, DWORD
*ret_size
, DISPID
**ret
)
439 unsigned i
, func_cnt
;
446 hres
= get_typeinfo(tid
, &ti
);
450 hres
= ITypeInfo_GetTypeAttr(ti
, &attr
);
452 ITypeInfo_Release(ti
);
456 func_cnt
= attr
->cFuncs
;
457 ITypeInfo_ReleaseTypeAttr(ti
, attr
);
459 ids
= heap_alloc(func_cnt
*sizeof(DISPID
));
461 ITypeInfo_Release(ti
);
462 return E_OUTOFMEMORY
;
465 for(i
=0; i
< func_cnt
; i
++) {
466 hres
= ITypeInfo_GetFuncDesc(ti
, i
, &funcdesc
);
470 ids
[i
] = funcdesc
->memid
;
471 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
474 ITypeInfo_Release(ti
);
480 qsort(ids
, func_cnt
, sizeof(DISPID
), id_cmp
);
482 *ret_size
= func_cnt
;
487 static inline BOOL
is_custom_dispid(DISPID id
)
489 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
492 static inline BOOL
is_dynamic_dispid(DISPID id
)
494 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
497 dispex_prop_type_t
get_dispid_type(DISPID id
)
499 if(is_dynamic_dispid(id
))
500 return DISPEXPROP_DYNAMIC
;
501 if(is_custom_dispid(id
))
502 return DISPEXPROP_CUSTOM
;
503 return DISPEXPROP_BUILTIN
;
506 static HRESULT
variant_copy(VARIANT
*dest
, VARIANT
*src
)
508 if(V_VT(src
) == VT_BSTR
&& !V_BSTR(src
)) {
509 V_VT(dest
) = VT_BSTR
;
514 return VariantCopy(dest
, src
);
517 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
)
519 if(This
->dynamic_data
)
520 return This
->dynamic_data
;
522 This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
));
523 if(!This
->dynamic_data
)
526 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->populate_props
)
527 This
->info
->desc
->vtbl
->populate_props(This
);
529 return This
->dynamic_data
;
532 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
534 const BOOL alloc
= flags
& fdexNameEnsure
;
535 dispex_dynamic_data_t
*data
;
536 dynamic_prop_t
*prop
;
538 data
= get_dynamic_data(This
);
540 return E_OUTOFMEMORY
;
542 for(prop
= data
->props
; prop
< data
->props
+data
->prop_cnt
; prop
++) {
543 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(prop
->name
, name
) : !strcmpW(prop
->name
, name
)) {
544 if(prop
->flags
& DYNPROP_DELETED
) {
546 return DISP_E_UNKNOWNNAME
;
547 prop
->flags
&= ~DYNPROP_DELETED
;
555 return DISP_E_UNKNOWNNAME
;
557 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
559 if(!data
->buf_size
) {
560 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
562 return E_OUTOFMEMORY
;
564 }else if(data
->buf_size
== data
->prop_cnt
) {
565 dynamic_prop_t
*new_props
;
567 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
569 return E_OUTOFMEMORY
;
571 data
->props
= new_props
;
572 data
->buf_size
<<= 1;
575 prop
= data
->props
+ data
->prop_cnt
;
577 prop
->name
= heap_strdupW(name
);
579 return E_OUTOFMEMORY
;
581 VariantInit(&prop
->var
);
588 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
590 dynamic_prop_t
*prop
;
593 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
601 HRESULT
dispex_get_dynid(DispatchEx
*This
, const WCHAR
*name
, DISPID
*id
)
603 dynamic_prop_t
*prop
;
606 hres
= get_dynamic_prop(This
, name
, fdexNameEnsure
, &prop
);
610 *id
= DISPID_DYNPROP_0
+ (prop
- This
->dynamic_data
->props
);
614 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
615 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
617 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->value
)
618 return This
->info
->desc
->vtbl
->value(This
, lcid
, flags
, params
, res
, ei
, caller
);
621 case DISPATCH_PROPERTYGET
:
623 V_BSTR(res
) = SysAllocString(objectW
);
625 return E_OUTOFMEMORY
;
628 FIXME("Unimplemented flags %x\n", flags
);
635 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
638 DISPPARAMS params
= {dp
->rgvarg
+dp
->cNamedArgs
, NULL
, dp
->cArgs
-dp
->cNamedArgs
, 0};
644 hres
= get_typeinfo(func
->tid
, &ti
);
646 ERR("Could not get type info: %08x\n", hres
);
650 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
652 ERR("Could not get iface %s: %08x\n", debugstr_mshtml_guid(tid_ids
[func
->tid
]), hres
);
656 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, ¶ms
, res
, ei
, &argerr
);
658 IUnknown_Release(unk
);
662 static inline func_disp_t
*impl_from_IUnknown(IUnknown
*iface
)
664 return CONTAINING_RECORD(iface
, func_disp_t
, IUnknown_iface
);
667 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
669 func_disp_t
*This
= impl_from_IUnknown(iface
);
671 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
673 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
674 *ppv
= &This
->IUnknown_iface
;
675 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
676 return *ppv
? S_OK
: E_NOINTERFACE
;
679 return E_NOINTERFACE
;
682 IUnknown_AddRef((IUnknown
*)*ppv
);
686 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
688 func_disp_t
*This
= impl_from_IUnknown(iface
);
689 LONG ref
= InterlockedIncrement(&This
->ref
);
691 TRACE("(%p) ref=%d\n", This
, ref
);
696 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
698 func_disp_t
*This
= impl_from_IUnknown(iface
);
699 LONG ref
= InterlockedDecrement(&This
->ref
);
701 TRACE("(%p) ref=%d\n", This
, ref
);
705 release_dispex(&This
->dispex
);
712 static const IUnknownVtbl FunctionUnkVtbl
= {
713 Function_QueryInterface
,
718 static inline func_disp_t
*impl_from_DispatchEx(DispatchEx
*iface
)
720 return CONTAINING_RECORD(iface
, func_disp_t
, dispex
);
723 static HRESULT
function_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
724 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
726 func_disp_t
*This
= impl_from_DispatchEx(dispex
);
730 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
734 case DISPATCH_METHOD
:
737 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
739 case DISPATCH_PROPERTYGET
: {
744 static const WCHAR func_prefixW
[] =
745 {'\n','f','u','n','c','t','i','o','n',' '};
746 static const WCHAR func_suffixW
[] =
747 {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
749 /* FIXME: This probably should be more generic. Also we should try to get IID_IActiveScriptSite and SID_GetCaller. */
751 return E_ACCESSDENIED
;
753 name_len
= SysStringLen(This
->info
->name
);
754 ptr
= str
= SysAllocStringLen(NULL
, name_len
+ (sizeof(func_prefixW
)+sizeof(func_suffixW
))/sizeof(WCHAR
));
756 return E_OUTOFMEMORY
;
758 memcpy(ptr
, func_prefixW
, sizeof(func_prefixW
));
759 ptr
+= sizeof(func_prefixW
)/sizeof(WCHAR
);
761 memcpy(ptr
, This
->info
->name
, name_len
*sizeof(WCHAR
));
764 memcpy(ptr
, func_suffixW
, sizeof(func_suffixW
));
771 FIXME("Unimplemented flags %x\n", flags
);
778 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
785 static const tid_t function_iface_tids
[] = {0};
787 static dispex_static_data_t function_dispex
= {
788 &function_dispex_vtbl
,
793 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
797 ret
= heap_alloc_zero(sizeof(func_disp_t
));
801 ret
->IUnknown_iface
.lpVtbl
= &FunctionUnkVtbl
;
802 init_dispex(&ret
->dispex
, &ret
->IUnknown_iface
, &function_dispex
);
810 static HRESULT
invoke_disp_value(DispatchEx
*This
, IDispatch
*func_disp
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
811 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
813 DISPID named_arg
= DISPID_THIS
;
814 DISPPARAMS new_dp
= {NULL
, &named_arg
, 0, 1};
819 FIXME("named args not supported\n");
823 new_dp
.rgvarg
= heap_alloc((dp
->cArgs
+1)*sizeof(VARIANTARG
));
825 return E_OUTOFMEMORY
;
827 new_dp
.cArgs
= dp
->cArgs
+1;
828 memcpy(new_dp
.rgvarg
+1, dp
->rgvarg
, dp
->cArgs
*sizeof(VARIANTARG
));
830 V_VT(new_dp
.rgvarg
) = VT_DISPATCH
;
831 V_DISPATCH(new_dp
.rgvarg
) = (IDispatch
*)&This
->IDispatchEx_iface
;
833 hres
= IDispatch_QueryInterface(func_disp
, &IID_IDispatchEx
, (void**)&dispex
);
835 if(SUCCEEDED(hres
)) {
836 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, flags
, &new_dp
, res
, ei
, caller
);
837 IDispatchEx_Release(dispex
);
840 hres
= IDispatch_Invoke(func_disp
, DISPID_VALUE
, &IID_NULL
, lcid
, flags
, &new_dp
, res
, ei
, &err
);
843 TRACE("<<< %s\n", debugstr_variant(res
));
845 WARN("<<< %08x\n", hres
);
847 heap_free(new_dp
.rgvarg
);
851 static HRESULT
get_func_obj_entry(DispatchEx
*This
, func_info_t
*func
, func_obj_entry_t
**ret
)
853 dispex_dynamic_data_t
*dynamic_data
;
854 func_obj_entry_t
*entry
;
856 dynamic_data
= get_dynamic_data(This
);
858 return E_OUTOFMEMORY
;
860 if(!dynamic_data
->func_disps
) {
861 dynamic_data
->func_disps
= heap_alloc_zero(This
->info
->func_disp_cnt
* sizeof(*dynamic_data
->func_disps
));
862 if(!dynamic_data
->func_disps
)
863 return E_OUTOFMEMORY
;
866 entry
= dynamic_data
->func_disps
+ func
->func_disp_idx
;
867 if(!entry
->func_obj
) {
868 entry
->func_obj
= create_func_disp(This
, func
);
870 return E_OUTOFMEMORY
;
872 IDispatchEx_AddRef(&entry
->func_obj
->dispex
.IDispatchEx_iface
);
873 V_VT(&entry
->val
) = VT_DISPATCH
;
874 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
881 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
886 max
= data
->func_cnt
-1;
891 if(data
->funcs
[n
].id
== id
) {
892 *ret
= data
->funcs
+n
;
896 if(data
->funcs
[n
].id
< id
)
902 WARN("invalid id %x\n", id
);
903 return DISP_E_UNKNOWNNAME
;
906 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
911 max
= This
->info
->func_cnt
-1;
916 c
= strcmpiW(This
->info
->name_table
[n
]->name
, name
);
918 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(This
->info
->name_table
[n
]->name
, name
))
921 *ret
= This
->info
->name_table
[n
]->id
;
931 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->get_dispid
) {
934 hres
= This
->info
->desc
->vtbl
->get_dispid(This
, name
, grfdex
, ret
);
935 if(hres
!= DISP_E_UNKNOWNNAME
)
939 return DISP_E_UNKNOWNNAME
;
942 static HRESULT
change_type(VARIANT
*dst
, VARIANT
*src
, VARTYPE vt
, IServiceProvider
*caller
)
944 V_VT(dst
) = VT_EMPTY
;
947 IVariantChangeType
*change_type
= NULL
;
950 hres
= IServiceProvider_QueryService(caller
, &SID_VariantConversion
, &IID_IVariantChangeType
, (void**)&change_type
);
951 if(SUCCEEDED(hres
)) {
952 hres
= IVariantChangeType_ChangeType(change_type
, dst
, src
, LOCALE_NEUTRAL
, vt
);
953 IVariantChangeType_Release(change_type
);
960 if(V_VT(src
) == VT_BSTR
) {
962 V_BOOL(dst
) = V_BSTR(src
) && *V_BSTR(src
) ? VARIANT_TRUE
: VARIANT_FALSE
;
968 return VariantChangeType(dst
, src
, 0, vt
);
971 static HRESULT
builtin_propget(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
)
976 if(dp
&& dp
->cArgs
) {
977 FIXME("cArgs %d\n", dp
->cArgs
);
981 assert(func
->get_vtbl_off
);
983 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
984 if(SUCCEEDED(hres
)) {
985 switch(func
->prop_vt
) {
986 #define CASE_VT(vt,type,access) \
989 hres = ((HRESULT (WINAPI*)(IUnknown*,type*))((void**)iface->lpVtbl)[func->get_vtbl_off])(iface,&val); \
990 if(SUCCEEDED(hres)) \
994 BUILTIN_TYPES_SWITCH
;
997 FIXME("Unhandled vt %d\n", func
->prop_vt
);
1000 IUnknown_Release(iface
);
1006 if(func
->prop_vt
!= VT_VARIANT
)
1007 V_VT(res
) = func
->prop_vt
== VT_PTR
? VT_DISPATCH
: func
->prop_vt
;
1011 static HRESULT
builtin_propput(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, IServiceProvider
*caller
)
1017 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1018 || dp
->cNamedArgs
> 1) {
1019 FIXME("invalid args\n");
1020 return E_INVALIDARG
;
1023 if(!func
->put_vtbl_off
) {
1024 FIXME("No setter\n");
1029 if(func
->prop_vt
!= VT_VARIANT
&& V_VT(v
) != func
->prop_vt
) {
1030 hres
= change_type(&tmpv
, v
, func
->prop_vt
, caller
);
1036 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1037 if(SUCCEEDED(hres
)) {
1038 switch(func
->prop_vt
) {
1039 #define CASE_VT(vt,type,access) \
1041 hres = ((HRESULT (WINAPI*)(IUnknown*,type))((void**)iface->lpVtbl)[func->put_vtbl_off])(iface,access(v)); \
1043 BUILTIN_TYPES_SWITCH
;
1046 FIXME("Unimplemented vt %d\n", func
->prop_vt
);
1050 IUnknown_Release(iface
);
1058 static HRESULT
invoke_builtin_function(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
, IServiceProvider
*caller
)
1060 VARIANT arg_buf
[MAX_ARGS
], *arg_ptrs
[MAX_ARGS
], *arg
, retv
, ret_ref
, vhres
;
1061 unsigned i
, nconv
= 0;
1065 if(dp
->cNamedArgs
) {
1066 FIXME("Named arguments not supported\n");
1070 if(dp
->cArgs
!= func
->argc
) {
1071 FIXME("Invalid argument count (expected %u, got %u)\n", func
->argc
, dp
->cArgs
);
1072 return E_INVALIDARG
;
1075 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1079 for(i
=0; i
< func
->argc
; i
++) {
1080 arg
= dp
->rgvarg
+dp
->cArgs
-i
-1;
1081 if(func
->arg_types
[i
] == V_VT(arg
)) {
1084 hres
= change_type(arg_buf
+nconv
, arg
, func
->arg_types
[i
], caller
);
1087 arg_ptrs
[i
] = arg_buf
+ nconv
++;
1091 if(SUCCEEDED(hres
)) {
1092 if(func
->prop_vt
== VT_VOID
) {
1093 V_VT(&retv
) = VT_EMPTY
;
1095 V_VT(&retv
) = func
->prop_vt
;
1096 arg_ptrs
[func
->argc
] = &ret_ref
;
1097 V_VT(&ret_ref
) = VT_BYREF
|func
->prop_vt
;
1099 switch(func
->prop_vt
) {
1100 #define CASE_VT(vt,type,access) \
1102 V_BYREF(&ret_ref) = &access(&retv); \
1104 BUILTIN_TYPES_SWITCH
;
1111 V_VT(&vhres
) = VT_ERROR
;
1112 hres
= DispCallFunc(iface
, func
->call_vtbl_off
*sizeof(void*), CC_STDCALL
, VT_ERROR
,
1113 func
->argc
+ (func
->prop_vt
== VT_VOID
? 0 : 1), func
->arg_types
, arg_ptrs
, &vhres
);
1117 VariantClear(arg_buf
+nconv
);
1118 IUnknown_Release(iface
);
1121 if(FAILED(V_ERROR(&vhres
)))
1122 return V_ERROR(&vhres
);
1127 VariantClear(&retv
);
1128 return V_ERROR(&vhres
);
1131 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
1132 EXCEPINFO
*ei
, IServiceProvider
*caller
)
1137 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1139 return E_INVALIDARG
;
1141 case DISPATCH_METHOD
:
1142 if(This
->dynamic_data
&& This
->dynamic_data
->func_disps
1143 && This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1144 func_obj_entry_t
*entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1146 if(V_VT(&entry
->val
) != VT_DISPATCH
) {
1147 FIXME("calling %s not supported\n", debugstr_variant(&entry
->val
));
1151 if((IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
!= V_DISPATCH(&entry
->val
)) {
1152 if(!V_DISPATCH(&entry
->val
)) {
1153 FIXME("Calling null\n");
1157 hres
= invoke_disp_value(This
, V_DISPATCH(&entry
->val
), 0, flags
, dp
, res
, ei
, NULL
);
1162 if(func
->call_vtbl_off
)
1163 hres
= invoke_builtin_function(This
, func
, dp
, res
, caller
);
1165 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1167 case DISPATCH_PROPERTYGET
: {
1168 func_obj_entry_t
*entry
;
1170 if(func
->id
== DISPID_VALUE
) {
1173 ret
= SysAllocString(objectW
);
1175 return E_OUTOFMEMORY
;
1177 V_VT(res
) = VT_BSTR
;
1182 hres
= get_func_obj_entry(This
, func
, &entry
);
1186 V_VT(res
) = VT_EMPTY
;
1187 return VariantCopy(res
, &entry
->val
);
1189 case DISPATCH_PROPERTYPUT
: {
1190 func_obj_entry_t
*entry
;
1192 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1193 || dp
->cNamedArgs
> 1) {
1194 FIXME("invalid args\n");
1195 return E_INVALIDARG
;
1199 * NOTE: Although we have IDispatchEx tests showing, that it's not allowed to set
1200 * function property using InvokeEx, it's possible to do that from jscript.
1201 * Native probably uses some undocumented interface in this case, but it should
1202 * be fine for us to allow IDispatchEx handle that.
1204 hres
= get_func_obj_entry(This
, func
, &entry
);
1208 return VariantCopy(&entry
->val
, dp
->rgvarg
);
1211 FIXME("Unimplemented flags %x\n", flags
);
1218 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
1219 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1224 hres
= get_builtin_func(This
->info
, id
, &func
);
1225 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
1226 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
1230 if(func
->func_disp_idx
!= -1)
1231 return function_invoke(This
, func
, flags
, dp
, res
, ei
, caller
);
1234 case DISPATCH_PROPERTYPUT
:
1236 V_VT(res
) = VT_EMPTY
;
1237 hres
= builtin_propput(This
, func
, dp
, caller
);
1239 case DISPATCH_PROPERTYGET
:
1240 hres
= builtin_propget(This
, func
, dp
, res
);
1243 if(!func
->get_vtbl_off
) {
1244 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1248 hres
= builtin_propget(This
, func
, NULL
, &v
);
1252 if(flags
!= (DISPATCH_PROPERTYGET
|DISPATCH_METHOD
) || dp
->cArgs
) {
1253 if(V_VT(&v
) != VT_DISPATCH
) {
1254 FIXME("Not a function %s flags %08x\n", debugstr_variant(&v
), flags
);
1259 hres
= invoke_disp_value(This
, V_DISPATCH(&v
), lcid
, flags
, dp
, res
, ei
, caller
);
1260 IDispatch_Release(V_DISPATCH(&v
));
1272 HRESULT
remove_attribute(DispatchEx
*This
, DISPID id
, VARIANT_BOOL
*success
)
1274 switch(get_dispid_type(id
)) {
1275 case DISPEXPROP_CUSTOM
:
1276 FIXME("DISPEXPROP_CUSTOM not supported\n");
1279 case DISPEXPROP_DYNAMIC
: {
1280 DWORD idx
= id
- DISPID_DYNPROP_0
;
1281 dynamic_prop_t
*prop
;
1283 prop
= This
->dynamic_data
->props
+idx
;
1284 VariantClear(&prop
->var
);
1285 prop
->flags
|= DYNPROP_DELETED
;
1286 *success
= VARIANT_TRUE
;
1289 case DISPEXPROP_BUILTIN
: {
1291 DISPPARAMS dp
= {&var
,NULL
,1,0};
1295 hres
= get_builtin_func(This
->info
, id
, &func
);
1299 /* For builtin functions, we set their value to the original function. */
1300 if(func
->func_disp_idx
!= -1) {
1301 func_obj_entry_t
*entry
;
1303 if(!This
->dynamic_data
|| !This
->dynamic_data
->func_disps
1304 || !This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1305 *success
= VARIANT_FALSE
;
1309 entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1310 if(V_VT(&entry
->val
) == VT_DISPATCH
1311 && V_DISPATCH(&entry
->val
) == (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
) {
1312 *success
= VARIANT_FALSE
;
1316 VariantClear(&entry
->val
);
1317 V_VT(&entry
->val
) = VT_DISPATCH
;
1318 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
1319 IDispatch_AddRef(V_DISPATCH(&entry
->val
));
1320 *success
= VARIANT_TRUE
;
1324 V_VT(&var
) = VT_EMPTY
;
1325 hres
= builtin_propput(This
, func
, &dp
, NULL
);
1329 *success
= VARIANT_TRUE
;
1338 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
1340 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
1343 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
1345 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1347 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
1350 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
1352 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1354 return IUnknown_AddRef(This
->outer
);
1357 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
1359 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1361 return IUnknown_Release(This
->outer
);
1364 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
1366 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1368 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1374 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
1375 LCID lcid
, ITypeInfo
**ppTInfo
)
1377 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1380 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1382 hres
= get_typeinfo(This
->info
->desc
->disp_tid
, ppTInfo
);
1386 ITypeInfo_AddRef(*ppTInfo
);
1390 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
1391 LPOLESTR
*rgszNames
, UINT cNames
,
1392 LCID lcid
, DISPID
*rgDispId
)
1394 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1398 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1401 for(i
=0; i
< cNames
; i
++) {
1402 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
1410 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
1411 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1412 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1414 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1416 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1417 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1419 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
, pDispParams
,
1420 pVarResult
, pExcepInfo
, NULL
);
1423 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
1425 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1426 dynamic_prop_t
*dprop
;
1429 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
1431 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
1432 FIXME("Unsupported grfdex %x\n", grfdex
);
1434 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
1435 if(hres
!= DISP_E_UNKNOWNNAME
)
1438 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
1442 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
1446 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
1447 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
1449 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1452 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1454 if(wFlags
== (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
))
1455 wFlags
= DISPATCH_PROPERTYPUT
;
1457 switch(get_dispid_type(id
)) {
1458 case DISPEXPROP_CUSTOM
:
1459 if(!This
->info
->desc
->vtbl
|| !This
->info
->desc
->vtbl
->invoke
)
1460 return DISP_E_UNKNOWNNAME
;
1461 return This
->info
->desc
->vtbl
->invoke(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1463 case DISPEXPROP_DYNAMIC
: {
1464 DWORD idx
= id
- DISPID_DYNPROP_0
;
1465 dynamic_prop_t
*prop
;
1467 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1468 return DISP_E_UNKNOWNNAME
;
1470 prop
= This
->dynamic_data
->props
+idx
;
1473 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1475 return E_INVALIDARG
;
1477 case DISPATCH_METHOD
:
1478 if(V_VT(&prop
->var
) != VT_DISPATCH
) {
1479 FIXME("invoke %s\n", debugstr_variant(&prop
->var
));
1483 return invoke_disp_value(This
, V_DISPATCH(&prop
->var
), lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1484 case DISPATCH_PROPERTYGET
:
1485 if(prop
->flags
& DYNPROP_DELETED
)
1486 return DISP_E_UNKNOWNNAME
;
1487 V_VT(pvarRes
) = VT_EMPTY
;
1488 return variant_copy(pvarRes
, &prop
->var
);
1489 case DISPATCH_PROPERTYPUT
:
1490 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1491 || pdp
->cNamedArgs
> 1) {
1492 FIXME("invalid args\n");
1493 return E_INVALIDARG
;
1496 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
1497 VariantClear(&prop
->var
);
1498 hres
= variant_copy(&prop
->var
, pdp
->rgvarg
);
1502 prop
->flags
&= ~DYNPROP_DELETED
;
1505 FIXME("unhandled wFlags %x\n", wFlags
);
1509 case DISPEXPROP_BUILTIN
:
1510 if(wFlags
== DISPATCH_CONSTRUCT
) {
1511 if(id
== DISPID_VALUE
) {
1512 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->value
) {
1513 return This
->info
->desc
->vtbl
->value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1515 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
1518 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
1522 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1529 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
1531 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1533 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
1535 /* Not implemented by IE */
1539 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
1541 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1543 TRACE("(%p)->(%x)\n", This
, id
);
1545 /* Not implemented by IE */
1549 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1551 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1552 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1556 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1558 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1562 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1564 if(is_dynamic_dispid(id
)) {
1565 DWORD idx
= id
- DISPID_DYNPROP_0
;
1567 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1568 return DISP_E_UNKNOWNNAME
;
1570 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1572 return E_OUTOFMEMORY
;
1577 hres
= get_builtin_func(This
->info
, id
, &func
);
1581 *pbstrName
= SysAllocString(func
->name
);
1583 return E_OUTOFMEMORY
;
1587 static HRESULT
next_dynamic_id(DispatchEx
*dispex
, DWORD idx
, DISPID
*ret_id
)
1589 while(idx
< dispex
->dynamic_data
->prop_cnt
&& dispex
->dynamic_data
->props
[idx
].flags
& DYNPROP_DELETED
)
1592 if(idx
== dispex
->dynamic_data
->prop_cnt
) {
1593 *ret_id
= DISPID_STARTENUM
;
1597 *ret_id
= DISPID_DYNPROP_0
+idx
;
1601 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1603 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1607 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1609 if(is_dynamic_dispid(id
)) {
1610 DWORD idx
= id
- DISPID_DYNPROP_0
;
1612 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1613 return DISP_E_UNKNOWNNAME
;
1615 return next_dynamic_id(This
, idx
+1, pid
);
1618 if(id
== DISPID_STARTENUM
) {
1619 func
= This
->info
->funcs
;
1621 hres
= get_builtin_func(This
->info
, id
, &func
);
1627 while(func
< This
->info
->funcs
+ This
->info
->func_cnt
) {
1628 /* FIXME: Skip hidden properties */
1629 if(func
->func_disp_idx
== -1) {
1636 if(get_dynamic_data(This
) && This
->dynamic_data
->prop_cnt
)
1637 return next_dynamic_id(This
, 0, pid
);
1639 *pid
= DISPID_STARTENUM
;
1643 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1645 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1646 FIXME("(%p)->(%p)\n", This
, ppunk
);
1650 static IDispatchExVtbl DispatchExVtbl
= {
1651 DispatchEx_QueryInterface
,
1654 DispatchEx_GetTypeInfoCount
,
1655 DispatchEx_GetTypeInfo
,
1656 DispatchEx_GetIDsOfNames
,
1658 DispatchEx_GetDispID
,
1659 DispatchEx_InvokeEx
,
1660 DispatchEx_DeleteMemberByName
,
1661 DispatchEx_DeleteMemberByDispID
,
1662 DispatchEx_GetMemberProperties
,
1663 DispatchEx_GetMemberName
,
1664 DispatchEx_GetNextDispID
,
1665 DispatchEx_GetNameSpaceParent
1668 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1670 if(IsEqualGUID(&IID_IDispatch
, riid
))
1671 *ppv
= &This
->IDispatchEx_iface
;
1672 else if(IsEqualGUID(&IID_IDispatchEx
, riid
))
1673 *ppv
= &This
->IDispatchEx_iface
;
1674 else if(IsEqualGUID(&IID_IDispatchJS
, riid
))
1676 else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
))
1682 IUnknown_AddRef((IUnknown
*)*ppv
);
1686 void dispex_traverse(DispatchEx
*This
, nsCycleCollectionTraversalCallback
*cb
)
1688 dynamic_prop_t
*prop
;
1690 if(!This
->dynamic_data
)
1693 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1694 if(V_VT(&prop
->var
) == VT_DISPATCH
)
1695 note_cc_edge((nsISupports
*)V_DISPATCH(&prop
->var
), "dispex_data", cb
);
1698 /* FIXME: Traverse func_disps */
1701 void dispex_unlink(DispatchEx
*This
)
1703 dynamic_prop_t
*prop
;
1705 if(!This
->dynamic_data
)
1708 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1709 if(V_VT(&prop
->var
) == VT_DISPATCH
) {
1710 V_VT(&prop
->var
) = VT_EMPTY
;
1711 IDispatch_Release(V_DISPATCH(&prop
->var
));
1713 VariantClear(&prop
->var
);
1718 const dispex_static_data_vtbl_t
*dispex_get_vtbl(DispatchEx
*dispex
)
1720 return dispex
->info
->desc
->vtbl
;
1723 void release_dispex(DispatchEx
*This
)
1725 dynamic_prop_t
*prop
;
1727 if(!This
->dynamic_data
)
1730 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1731 VariantClear(&prop
->var
);
1732 heap_free(prop
->name
);
1735 heap_free(This
->dynamic_data
->props
);
1737 if(This
->dynamic_data
->func_disps
) {
1738 func_obj_entry_t
*iter
;
1740 for(iter
= This
->dynamic_data
->func_disps
; iter
< This
->dynamic_data
->func_disps
+ This
->info
->func_disp_cnt
; iter
++) {
1741 if(iter
->func_obj
) {
1742 iter
->func_obj
->obj
= NULL
;
1743 IDispatchEx_Release(&iter
->func_obj
->dispex
.IDispatchEx_iface
);
1745 VariantClear(&iter
->val
);
1748 heap_free(This
->dynamic_data
->func_disps
);
1751 heap_free(This
->dynamic_data
);
1754 void init_dispex_with_compat_mode(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
, compat_mode_t compat_mode
)
1756 assert(compat_mode
< COMPAT_MODE_CNT
);
1758 if(!data
->info_cache
[compat_mode
]) {
1759 EnterCriticalSection(&cs_dispex_static_data
);
1760 if(!data
->info_cache
[compat_mode
])
1761 data
->info_cache
[compat_mode
] = preprocess_dispex_data(data
, compat_mode
);
1762 LeaveCriticalSection(&cs_dispex_static_data
);
1765 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
1766 dispex
->outer
= outer
;
1767 dispex
->info
= data
->info_cache
[compat_mode
];
1768 dispex
->dynamic_data
= NULL
;