vbscript: Split named item lookup into a helper function.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2018-03-16 23:34:41 +01:00 committed by Alexandre Julliard
parent f94d0e7b3a
commit aa5b68ac40
3 changed files with 39 additions and 23 deletions

View File

@ -99,6 +99,7 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_
{ {
named_item_t *item; named_item_t *item;
function_t *func; function_t *func;
IDispatch *disp;
unsigned i; unsigned i;
DISPID id; DISPID id;
HRESULT hres; HRESULT hres;
@ -178,29 +179,11 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_
return S_OK; return S_OK;
} }
LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) { disp = lookup_named_item(ctx->script, name, SCRIPTITEM_ISVISIBLE);
if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpiW(item->name, name)) { if(disp) {
if(!item->disp) { ref->type = REF_OBJ;
IUnknown *unk; ref->u.obj = disp;
return S_OK;
hres = IActiveScriptSite_GetItemInfo(ctx->script->site, item->name, SCRIPTINFO_IUNKNOWN, &unk, NULL);
if(FAILED(hres)) {
WARN("GetItemInfo failed: %08x\n", hres);
continue;
}
hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
IUnknown_Release(unk);
if(FAILED(hres)) {
WARN("object does not implement IDispatch\n");
continue;
}
}
ref->type = REF_OBJ;
ref->u.obj = item->disp;
return S_OK;
}
} }
LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) { LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) {

View File

@ -96,6 +96,38 @@ static void exec_queued_code(script_ctx_t *ctx)
} }
} }
IDispatch *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned flags)
{
named_item_t *item;
HRESULT hres;
LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) {
if((item->flags & flags) == flags && !strcmpiW(item->name, name)) {
if(!item->disp) {
IUnknown *unk;
hres = IActiveScriptSite_GetItemInfo(ctx->site, item->name,
SCRIPTINFO_IUNKNOWN, &unk, NULL);
if(FAILED(hres)) {
WARN("GetItemInfo failed: %08x\n", hres);
continue;
}
hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
IUnknown_Release(unk);
if(FAILED(hres)) {
WARN("object does not implement IDispatch\n");
continue;
}
}
return item->disp;
}
}
return NULL;
}
static HRESULT set_ctx_site(VBScript *This) static HRESULT set_ctx_site(VBScript *This)
{ {
HRESULT hres; HRESULT hres;

View File

@ -355,6 +355,7 @@ void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN; HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
HRESULT exec_script(script_ctx_t*,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN; HRESULT exec_script(script_ctx_t*,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
void release_dynamic_vars(dynamic_var_t*) DECLSPEC_HIDDEN; void release_dynamic_vars(dynamic_var_t*) DECLSPEC_HIDDEN;
IDispatch *lookup_named_item(script_ctx_t*,const WCHAR*,unsigned) DECLSPEC_HIDDEN;
typedef struct { typedef struct {
UINT16 len; UINT16 len;