From aa5b68ac400726132aa61a6e590e33d17f087f94 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 16 Mar 2018 23:34:41 +0100 Subject: [PATCH] vbscript: Split named item lookup into a helper function. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/vbscript/interp.c | 29 ++++++----------------------- dlls/vbscript/vbscript.c | 32 ++++++++++++++++++++++++++++++++ dlls/vbscript/vbscript.h | 1 + 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 9ec329924c5..4f746c74301 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -99,6 +99,7 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_ { named_item_t *item; function_t *func; + IDispatch *disp; unsigned i; DISPID id; HRESULT hres; @@ -178,29 +179,11 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_ return S_OK; } - LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) { - if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpiW(item->name, name)) { - if(!item->disp) { - IUnknown *unk; - - 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; - } + disp = lookup_named_item(ctx->script, name, SCRIPTITEM_ISVISIBLE); + if(disp) { + ref->type = REF_OBJ; + ref->u.obj = disp; + return S_OK; } LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) { diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 645068e347b..054d53bdfc6 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -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) { HRESULT hres; diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h index 5e935ff76af..42b3cd198b3 100644 --- a/dlls/vbscript/vbscript.h +++ b/dlls/vbscript/vbscript.h @@ -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 exec_script(script_ctx_t*,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*) 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 { UINT16 len; -- 2.11.4.GIT