mirror of
https://github.com/reactos/wine.git
synced 2024-11-25 04:39:45 +00:00
jscript: Delay setting named info if SCRIPTITEM_GLOBALMEMBER flag is not set.
This commit is contained in:
parent
dfe41770e7
commit
4eb80d8d51
@ -459,6 +459,27 @@ static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, ex
|
||||
|
||||
for(item = ctx->parser->script->named_items; item; item = item->next) {
|
||||
if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpW(item->name, identifier)) {
|
||||
if(!item->disp) {
|
||||
IUnknown *unk;
|
||||
|
||||
if(!ctx->parser->script->site)
|
||||
break;
|
||||
|
||||
hres = IActiveScriptSite_GetItemInfo(ctx->parser->script->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;
|
||||
}
|
||||
}
|
||||
|
||||
ret->type = EXPRVAL_VARIANT;
|
||||
V_VT(&ret->u.var) = VT_DISPATCH;
|
||||
V_DISPATCH(&ret->u.var) = item->disp;
|
||||
|
@ -144,6 +144,9 @@ static HRESULT set_ctx_site(JScript *This)
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
IActiveScriptSite_AddRef(This->site);
|
||||
This->ctx->site = This->site;
|
||||
|
||||
change_state(This, SCRIPTSTATE_INITIALIZED);
|
||||
return S_OK;
|
||||
}
|
||||
@ -325,7 +328,8 @@ static HRESULT WINAPI JScript_Close(IActiveScript *iface)
|
||||
while(iter) {
|
||||
iter2 = iter->next;
|
||||
|
||||
IDispatch_Release(iter->disp);
|
||||
if(iter->disp)
|
||||
IDispatch_Release(iter->disp);
|
||||
heap_free(iter->name);
|
||||
heap_free(iter);
|
||||
iter = iter2;
|
||||
@ -334,6 +338,11 @@ static HRESULT WINAPI JScript_Close(IActiveScript *iface)
|
||||
This->ctx->named_items = NULL;
|
||||
}
|
||||
|
||||
if(This->ctx->site) {
|
||||
IActiveScriptSite_Release(This->ctx->site);
|
||||
This->ctx->site = NULL;
|
||||
}
|
||||
|
||||
if (This->site)
|
||||
change_state(This, SCRIPTSTATE_CLOSED);
|
||||
|
||||
@ -361,8 +370,7 @@ static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
|
||||
{
|
||||
JScript *This = ACTSCRIPT_THIS(iface);
|
||||
named_item_t *item;
|
||||
IDispatch *disp;
|
||||
IUnknown *unk;
|
||||
IDispatch *disp = NULL;
|
||||
HRESULT hres;
|
||||
|
||||
TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
|
||||
@ -370,22 +378,27 @@ static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
|
||||
if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->ctx->state == SCRIPTSTATE_CLOSED)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
|
||||
if(FAILED(hres)) {
|
||||
WARN("GetItemInfo failed: %08x\n", hres);
|
||||
return hres;
|
||||
}
|
||||
if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
|
||||
IUnknown *unk;
|
||||
|
||||
hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
|
||||
IUnknown_Release(unk);
|
||||
if(FAILED(hres)) {
|
||||
WARN("object does not implement IDispatch\n");
|
||||
return hres;
|
||||
hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
|
||||
if(FAILED(hres)) {
|
||||
WARN("GetItemInfo failed: %08x\n", hres);
|
||||
return hres;
|
||||
}
|
||||
|
||||
hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
|
||||
IUnknown_Release(unk);
|
||||
if(FAILED(hres)) {
|
||||
WARN("object does not implement IDispatch\n");
|
||||
return hres;
|
||||
}
|
||||
}
|
||||
|
||||
item = heap_alloc(sizeof(*item));
|
||||
if(!item) {
|
||||
IDispatch_Release(disp);
|
||||
if(disp)
|
||||
IDispatch_Release(disp);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
|
@ -165,6 +165,7 @@ struct _script_ctx_t {
|
||||
SCRIPTSTATE state;
|
||||
exec_ctx_t *exec_ctx;
|
||||
named_item_t *named_items;
|
||||
IActiveScriptSite *site;
|
||||
LCID lcid;
|
||||
|
||||
jsheap_t tmp_heap;
|
||||
|
@ -64,6 +64,7 @@ DEFINE_EXPECT(global_propput_i);
|
||||
DEFINE_EXPECT(global_success_d);
|
||||
DEFINE_EXPECT(global_success_i);
|
||||
DEFINE_EXPECT(testobj_delete);
|
||||
DEFINE_EXPECT(GetItemInfo_testVal);
|
||||
|
||||
#define DISPID_GLOBAL_TESTPROPGET 0x1000
|
||||
#define DISPID_GLOBAL_TESTPROPPUT 0x1001
|
||||
@ -74,6 +75,7 @@ DEFINE_EXPECT(testobj_delete);
|
||||
#define DISPID_GLOBAL_TESTOBJ 0x1006
|
||||
|
||||
static const WCHAR testW[] = {'t','e','s','t',0};
|
||||
static const WCHAR test_valW[] = {'t','e','s','t','V','a','l',0};
|
||||
|
||||
static BOOL strict_dispid_check;
|
||||
static const char *test_name = "(null)";
|
||||
@ -485,10 +487,14 @@ static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *p
|
||||
static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
|
||||
DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
|
||||
{
|
||||
ok(!lstrcmpW(pstrName, testW), "unexpected pstrName %s\n", debugstr_w(pstrName));
|
||||
ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
|
||||
ok(!ppti, "ppti != NULL\n");
|
||||
|
||||
if(!lstrcmpW(pstrName, test_valW))
|
||||
CHECK_EXPECT(GetItemInfo_testVal);
|
||||
else if(lstrcmpW(pstrName, testW))
|
||||
ok(0, "unexpected pstrName %s\n", debugstr_w(pstrName));
|
||||
|
||||
*ppiunkItem = (IUnknown*)&Global;
|
||||
return S_OK;
|
||||
}
|
||||
@ -673,6 +679,54 @@ static void run_from_res(const char *name)
|
||||
SysFreeString(str);
|
||||
}
|
||||
|
||||
static void test_isvisible(BOOL global_members)
|
||||
{
|
||||
IActiveScriptParse *parser;
|
||||
IActiveScript *engine;
|
||||
HRESULT hres;
|
||||
|
||||
static const WCHAR script_textW[] =
|
||||
{'v','a','r',' ','v',' ','=',' ','t','e','s','t','V','a','l',';',0};
|
||||
|
||||
engine = create_script();
|
||||
if(!engine)
|
||||
return;
|
||||
|
||||
hres = IActiveScript_QueryInterface(engine, &IID_IActiveScriptParse, (void**)&parser);
|
||||
ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
|
||||
|
||||
hres = IActiveScriptParse_InitNew(parser);
|
||||
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
|
||||
|
||||
hres = IActiveScript_SetScriptSite(engine, &ActiveScriptSite);
|
||||
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
|
||||
|
||||
if(global_members)
|
||||
SET_EXPECT(GetItemInfo_testVal);
|
||||
hres = IActiveScript_AddNamedItem(engine, test_valW,
|
||||
SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|
|
||||
(global_members ? SCRIPTITEM_GLOBALMEMBERS : 0));
|
||||
ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
|
||||
if(global_members)
|
||||
CHECK_CALLED(GetItemInfo_testVal);
|
||||
|
||||
hres = IActiveScript_SetScriptState(engine, SCRIPTSTATE_STARTED);
|
||||
ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
|
||||
|
||||
if(!global_members)
|
||||
SET_EXPECT(GetItemInfo_testVal);
|
||||
hres = IActiveScriptParse_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
|
||||
ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
|
||||
if(!global_members)
|
||||
CHECK_CALLED(GetItemInfo_testVal);
|
||||
|
||||
hres = IActiveScriptParse_ParseScriptText(parser, script_textW, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
|
||||
ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
|
||||
|
||||
IActiveScript_Release(engine);
|
||||
IActiveScriptParse_Release(parser);
|
||||
}
|
||||
|
||||
static void run_tests(void)
|
||||
{
|
||||
strict_dispid_check = TRUE;
|
||||
@ -707,6 +761,9 @@ static void run_tests(void)
|
||||
run_from_res("lang.js");
|
||||
run_from_res("api.js");
|
||||
run_from_res("regexp.js");
|
||||
|
||||
test_isvisible(FALSE);
|
||||
test_isvisible(TRUE);
|
||||
}
|
||||
|
||||
START_TEST(run)
|
||||
|
Loading…
Reference in New Issue
Block a user