Commit 0242ae52 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

jscript: Lookup the named item using a helper function.

parent f6a4dda9
......@@ -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))
......
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment