Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com ---
This will simplify the 7th patch.
dlls/jscript/engine.c | 34 ++++++---------------------------- dlls/jscript/jscript.c | 35 +++++++++++++++++++++++++++++++++++ dlls/jscript/jscript.h | 2 ++ 3 files changed, 43 insertions(+), 28 deletions(-)
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index f94cfd1..4e28b63 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -662,34 +662,12 @@ static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, exprval_t *re return S_OK; }
- for(item = ctx->named_items; item; item = item->next) { - if((item->flags & SCRIPTITEM_ISVISIBLE) && !wcscmp(item->name, identifier)) { - if(!item->disp) { - IUnknown *unk; - - if(!ctx->site) - break; - - hres = IActiveScriptSite_GetItemInfo(ctx->site, identifier, - SCRIPTINFO_IUNKNOWN, &unk, NULL); - if(FAILED(hres)) { - WARN("GetItemInfo failed: %08x\n", hres); - break; - } - - hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp); - IUnknown_Release(unk); - if(FAILED(hres)) { - WARN("object does not implement IDispatch\n"); - break; - } - } - - IDispatch_AddRef(item->disp); - ret->type = EXPRVAL_JSVAL; - ret->u.val = jsval_disp(item->disp); - return S_OK; - } + item = lookup_named_item(ctx, identifier, SCRIPTITEM_ISVISIBLE); + if(item) { + IDispatch_AddRef(item->disp); + ret->type = EXPRVAL_JSVAL; + ret->u.val = jsval_disp(item->disp); + return S_OK; }
if(lookup_global_members(ctx, identifier, ret)) diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index 98fe759..1970437 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -108,6 +108,41 @@ static inline BOOL is_started(script_ctx_t *ctx) || ctx->state == SCRIPTSTATE_DISCONNECTED; }
+named_item_t *lookup_named_item(script_ctx_t *ctx, const WCHAR *item_name, unsigned flags) +{ + named_item_t *item; + HRESULT hr; + + for(item = ctx->named_items; item; item = item->next) { + if((item->flags & flags) == flags && !wcscmp(item->name, item_name)) { + if(!item->disp) { + IUnknown *unk; + + if(!ctx->site) + return NULL; + + hr = IActiveScriptSite_GetItemInfo(ctx->site, item_name, + SCRIPTINFO_IUNKNOWN, &unk, NULL); + if(FAILED(hr)) { + WARN("GetItemInfo failed: %08x\n", hr); + continue; + } + + hr = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp); + IUnknown_Release(unk); + if(FAILED(hr)) { + WARN("object does not implement IDispatch\n"); + continue; + } + } + + return item; + } + } + + return NULL; +} + static inline JScriptError *impl_from_IActiveScriptError(IActiveScriptError *iface) { return CONTAINING_RECORD(iface, JScriptError, IActiveScriptError_iface); diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 113ec99..8297838 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -212,6 +212,8 @@ typedef struct named_item_t { struct named_item_t *next; } named_item_t;
+named_item_t *lookup_named_item(script_ctx_t*,const WCHAR*,unsigned) DECLSPEC_HIDDEN; + typedef struct { const WCHAR *name; builtin_invoke_t invoke;