Commit 89327655 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Fixed SetScriptSite called before InitNew handling.

parent d9f097ad
......@@ -36,6 +36,7 @@ typedef struct {
DWORD safeopt;
script_ctx_t *ctx;
LONG thread_id;
LCID lcid;
IActiveScriptSite *site;
......@@ -127,6 +128,26 @@ static void exec_queued_code(JScript *This)
clear_script_queue(This);
}
static HRESULT set_ctx_site(JScript *This)
{
HRESULT hres;
This->ctx->lcid = This->lcid;
if(!This->ctx->script_disp) {
hres = create_dispex(This->ctx, NULL, NULL, &This->ctx->script_disp);
if(FAILED(hres))
return hres;
}
hres = init_global(This->ctx);
if(FAILED(hres))
return hres;
change_state(This, SCRIPTSTATE_INITIALIZED);
return S_OK;
}
#define ACTSCRIPT_THIS(iface) DEFINE_THIS(JScript, IActiveScript, iface)
static HRESULT WINAPI JScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
......@@ -211,22 +232,6 @@ static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
if(This->site)
return E_UNEXPECTED;
if(!This->ctx) {
hres = IActiveScriptParse_InitNew(ASPARSE(This));
if(FAILED(hres))
return hres;
}
if(!This->ctx->script_disp) {
hres = create_dispex(This->ctx, NULL, NULL, &This->ctx->script_disp);
if(FAILED(hres))
return hres;
}
hres = init_global(This->ctx);
if(FAILED(hres))
return hres;
if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
return E_UNEXPECTED;
......@@ -237,8 +242,7 @@ static HRESULT WINAPI JScript_SetScriptSite(IActiveScript *iface,
if(hres == S_OK)
This->ctx->lcid = lcid;
change_state(This, SCRIPTSTATE_INITIALIZED);
return S_OK;
return This->ctx ? set_ctx_site(This) : S_OK;
}
static HRESULT WINAPI JScript_GetScriptSite(IActiveScript *iface, REFIID riid,
......@@ -517,7 +521,7 @@ static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
return E_UNEXPECTED;
}
return S_OK;
return This->site ? set_ctx_site(This) : S_OK;
}
static HRESULT WINAPI JScriptParse_AddScriptlet(IActiveScriptParse *iface,
......
......@@ -339,11 +339,64 @@ static void test_jscript(void)
ok(!ref, "ref = %d\n", ref);
}
static void test_jscript2(void)
{
IActiveScriptParse *parse;
IActiveScript *script;
IUnknown *unk;
ULONG ref;
HRESULT hres;
hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
&IID_IUnknown, (void**)&unk);
ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
if(FAILED(hres))
return;
hres = IUnknown_QueryInterface(unk, &IID_IActiveScript, (void**)&script);
ok(hres == S_OK, "Could not get IActiveScript: %08x\n", hres);
hres = IUnknown_QueryInterface(unk, &IID_IActiveScriptParse, (void**)&parse);
ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
test_state(script, SCRIPTSTATE_UNINITIALIZED);
SET_EXPECT(GetLCID);
hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
CHECK_CALLED(GetLCID);
test_state(script, SCRIPTSTATE_UNINITIALIZED);
SET_EXPECT(OnStateChange_INITIALIZED);
hres = IActiveScriptParse_InitNew(parse);
ok(hres == S_OK, "InitNew failed: %08x\n", hres);
CHECK_CALLED(OnStateChange_INITIALIZED);
hres = IActiveScriptParse_InitNew(parse);
ok(hres == E_UNEXPECTED, "InitNew failed: %08x, expected E_UNEXPECTED\n", hres);
SET_EXPECT(OnStateChange_CLOSED);
hres = IActiveScript_Close(script);
ok(hres == S_OK, "Close failed: %08x\n", hres);
CHECK_CALLED(OnStateChange_CLOSED);
test_state(script, SCRIPTSTATE_CLOSED);
test_script_dispatch(script, FALSE);
IActiveScriptParse_Release(parse);
IActiveScript_Release(script);
ref = IUnknown_Release(unk);
ok(!ref, "ref = %d\n", ref);
}
START_TEST(jscript)
{
CoInitialize(NULL);
test_jscript();
test_jscript2();
CoUninitialize();
}
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