Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/compile.c | 5 ----- dlls/vbscript/interp.c | 6 +++--- dlls/vbscript/vbscript.h | 1 - 3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index cc78daa..164c2d1 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -1867,8 +1867,6 @@ void release_vbscode(vbscode_t *code) for(i=0; i < code->bstr_cnt; i++) SysFreeString(code->bstr_pool[i]);
- if(code->context) - IDispatch_Release(code->context); if(code->named_item) release_named_item(code->named_item); heap_pool_free(&code->heap); @@ -2016,9 +2014,6 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *item ctx.code = NULL; release_compiler(&ctx);
- if(item && item->disp) - IDispatch_AddRef(code->context = item->disp); - list_add_tail(&script->code_list, &code->entry); *ret = code; return S_OK; diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index d2e1d2a..95614b1 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -181,11 +181,11 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_ } }
- if(ctx->func->code_ctx->context) { - hres = disp_get_id(ctx->func->code_ctx->context, name, invoke_type, TRUE, &id); + if(ctx->func->code_ctx->named_item && ctx->func->code_ctx->named_item->disp) { + hres = disp_get_id(ctx->func->code_ctx->named_item->disp, name, invoke_type, TRUE, &id); if(SUCCEEDED(hres)) { ref->type = REF_DISP; - ref->u.d.disp = ctx->func->code_ctx->context; + ref->u.d.disp = ctx->func->code_ctx->named_item->disp; ref->u.d.id = id; return S_OK; } diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h index 27ddae3..aa75b1c 100644 --- a/dlls/vbscript/vbscript.h +++ b/dlls/vbscript/vbscript.h @@ -348,7 +348,6 @@ struct _vbscode_t { BOOL pending_exec; BOOL is_persistent; function_t main_code; - IDispatch *context; named_item_t *named_item;
BSTR *bstr_pool;
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/vbscript.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 86902d8..52bc4ff 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -198,6 +198,27 @@ static void exec_queued_code(script_ctx_t *ctx) } }
+static HRESULT retrieve_named_item_disp(IActiveScriptSite *site, named_item_t *item) +{ + IUnknown *unk; + HRESULT hres; + + hres = IActiveScriptSite_GetItemInfo(site, item->name, SCRIPTINFO_IUNKNOWN, &unk, NULL); + if(FAILED(hres)) { + WARN("GetItemInfo failed: %08x\n", hres); + return hres; + } + + hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp); + IUnknown_Release(unk); + if(FAILED(hres)) { + WARN("object does not implement IDispatch\n"); + return hres; + } + + return S_OK; +} + named_item_t *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned flags) { named_item_t *item; @@ -209,22 +230,10 @@ named_item_t *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned f hres = create_script_disp(ctx, &item->script_obj); if(FAILED(hres)) return NULL; } + if(!item->disp && (flags || !(item->flags & SCRIPTITEM_CODEONLY))) { - 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; - } + hres = retrieve_named_item_disp(ctx->site, item); + if(FAILED(hres)) continue; }
return item;
Signed-off-by: Jacek Caban jacek@codeweavers.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/vbscript.c | 46 ++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 52bc4ff..858cacb 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -262,6 +262,7 @@ void release_named_item(named_item_t *item)
static void release_script(script_ctx_t *ctx) { + named_item_t *item, *item_next; vbscode_t *code, *code_next;
collect_objects(ctx); @@ -282,14 +283,19 @@ static void release_script(script_ctx_t *ctx) } }
- while(!list_empty(&ctx->named_items)) { - named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry); - - list_remove(&iter->entry); - if(iter->disp) - IDispatch_Release(iter->disp); - release_named_item_script_obj(iter); - release_named_item(iter); + LIST_FOR_EACH_ENTRY_SAFE(item, item_next, &ctx->named_items, named_item_t, entry) + { + if(item->disp) + { + IDispatch_Release(item->disp); + item->disp = NULL; + } + release_named_item_script_obj(item); + if(!(item->flags & SCRIPTITEM_ISPERSISTENT)) + { + list_remove(&item->entry); + release_named_item(item); + } }
if(ctx->secmgr) { @@ -321,6 +327,15 @@ static void release_code_list(script_ctx_t *ctx) } }
+static void release_named_item_list(script_ctx_t *ctx) +{ + while(!list_empty(&ctx->named_items)) { + named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry); + list_remove(&iter->entry); + release_named_item(iter); + } +} + static void decrease_state(VBScript *This, SCRIPTSTATE state) { switch(This->state) { @@ -340,8 +355,10 @@ static void decrease_state(VBScript *This, SCRIPTSTATE state) break; release_script(This->ctx); This->thread_id = 0; - if(state == SCRIPTSTATE_CLOSED) + if(state == SCRIPTSTATE_CLOSED) { release_code_list(This->ctx); + release_named_item_list(This->ctx); + } break; case SCRIPTSTATE_CLOSED: break; @@ -539,6 +556,7 @@ static ULONG WINAPI VBScript_Release(IActiveScript *iface) static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass) { VBScript *This = impl_from_IActiveScript(iface); + named_item_t *item; LCID lcid; HRESULT hres;
@@ -553,6 +571,16 @@ static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScript if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0)) return E_UNEXPECTED;
+ /* Retrieve new dispatches for persistent named items */ + LIST_FOR_EACH_ENTRY(item, &This->ctx->named_items, named_item_t, entry) + { + if(!item->disp) + { + hres = retrieve_named_item_disp(pass, item); + if(FAILED(hres)) return hres; + } + } + hres = create_script_disp(This->ctx, &This->ctx->script_obj); if(FAILED(hres)) return hres;
Signed-off-by: Jacek Caban jacek@codeweavers.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/tests/vbscript.c | 84 ++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 5 deletions(-)
diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c index 8653463..7545ca3 100644 --- a/dlls/vbscript/tests/vbscript.c +++ b/dlls/vbscript/tests/vbscript.c @@ -101,6 +101,7 @@ DEFINE_EXPECT(GetItemInfo_global); DEFINE_EXPECT(GetItemInfo_global_code); DEFINE_EXPECT(GetItemInfo_visible); DEFINE_EXPECT(GetItemInfo_visible_code); +DEFINE_EXPECT(GetItemInfo_persistent); DEFINE_EXPECT(testCall);
DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8); @@ -151,7 +152,7 @@ static ULONG WINAPI Dispatch_Release(IDispatch *iface) return 1; }
-static ULONG global_named_item_ref, visible_named_item_ref, visible_code_named_item_ref; +static ULONG global_named_item_ref, visible_named_item_ref, visible_code_named_item_ref, persistent_named_item_ref;
static ULONG WINAPI global_AddRef(IDispatch *iface) { @@ -183,6 +184,16 @@ static ULONG WINAPI visible_code_Release(IDispatch *iface) return --visible_code_named_item_ref; }
+static ULONG WINAPI persistent_AddRef(IDispatch *iface) +{ + return ++persistent_named_item_ref; +} + +static ULONG WINAPI persistent_Release(IDispatch *iface) +{ + return --persistent_named_item_ref; +} + static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo) { ok(0, "unexpected call\n"); @@ -266,6 +277,18 @@ static const IDispatchVtbl visible_code_named_item_vtbl = {
static IDispatch visible_code_named_item = { &visible_code_named_item_vtbl };
+static const IDispatchVtbl persistent_named_item_vtbl = { + Dispatch_QueryInterface, + persistent_AddRef, + persistent_Release, + Dispatch_GetTypeInfoCount, + Dispatch_GetTypeInfo, + Dispatch_GetIDsOfNames, + Dispatch_Invoke +}; + +static IDispatch persistent_named_item = { &persistent_named_item_vtbl }; + static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv) { *ppv = NULL; @@ -325,6 +348,12 @@ static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPC *item_unk = (IUnknown*)&visible_code_named_item; return S_OK; } + if(!wcscmp(name, L"persistent")) { + CHECK_EXPECT(GetItemInfo_persistent); + IDispatch_AddRef(&persistent_named_item); + *item_unk = (IUnknown*)&persistent_named_item; + return S_OK; + } ok(0, "unexpected call %s\n", wine_dbgstr_w(name)); return E_NOTIMPL; } @@ -1818,6 +1847,8 @@ static void test_named_items(void) ok(hres == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hres); hres = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY); ok(hres == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hres); + hres = IActiveScript_AddNamedItem(script, L"persistent", SCRIPTITEM_ISPERSISTENT | SCRIPTITEM_CODEONLY); + ok(hres == E_UNEXPECTED, "AddNamedItem returned: %08x\n", hres);
SET_EXPECT(GetLCID); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); @@ -1835,10 +1866,13 @@ static void test_named_items(void) ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); hres = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); + hres = IActiveScript_AddNamedItem(script, L"persistent", SCRIPTITEM_ISPERSISTENT | SCRIPTITEM_CODEONLY); + ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
ok(global_named_item_ref > 0, "global_named_item_ref = %u\n", global_named_item_ref); ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref); ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref); + ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
hres = IActiveScript_GetScriptDispatch(script, L"noContext", &disp); ok(hres == E_INVALIDARG, "GetScriptDispatch returned: %08x\n", hres); @@ -1920,6 +1954,7 @@ static void test_named_items(void) ok(global_named_item_ref > 0, "global_named_item_ref = %u\n", global_named_item_ref); ok(visible_named_item_ref == 1, "visible_named_item_ref = %u\n", visible_named_item_ref); ok(visible_code_named_item_ref == 1, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref); + ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
SET_EXPECT(testCall); parse_script(parse, "visibleItem.testCall\n"); @@ -2087,6 +2122,28 @@ static void test_named_items(void) IDispatchEx_Release(script_disp2); IDispatchEx_Release(script_disp);
+ SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"x = 13\n", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"x = 10\n", L"persistent", NULL, NULL, 0, 0, 0, NULL, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"x", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + ok(V_VT(&var) == VT_I2 && V_I2(&var) == 10, "Unexpected 'x': V_VT = %d, V_I2 = %d\n", V_VT(&var), V_I2(&var)); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + + script_disp = get_script_dispatch(script, L"persistent"); + SET_EXPECT(OnStateChange_DISCONNECTED); SET_EXPECT(OnStateChange_INITIALIZED); SET_EXPECT(OnStateChange_UNINITIALIZED); @@ -2100,30 +2157,46 @@ static void test_named_items(void) ok(global_named_item_ref == 0, "global_named_item_ref = %u\n", global_named_item_ref); ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref); ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref); + ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
hres = IActiveScript_GetScriptDispatch(script, L"codeOnlyItem", &disp); ok(hres == E_UNEXPECTED, "hres = %08x, expected E_UNEXPECTED\n", hres);
SET_EXPECT(GetLCID); SET_EXPECT(OnStateChange_INITIALIZED); + SET_EXPECT(GetItemInfo_persistent); hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite); ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres); CHECK_CALLED(GetLCID); CHECK_CALLED(OnStateChange_INITIALIZED); + CHECK_CALLED(GetItemInfo_persistent); + ok(persistent_named_item_ref > 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
hres = IActiveScript_AddNamedItem(script, L"codeOnlyItem", SCRIPTITEM_CODEONLY); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
SET_EXPECT(OnStateChange_CONNECTED); - SET_EXPECT_MULTI(OnEnterScript, 4); - SET_EXPECT_MULTI(OnLeaveScript, 4); + SET_EXPECT_MULTI(OnEnterScript, 5); + SET_EXPECT_MULTI(OnLeaveScript, 5); hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_CONNECTED); ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_CONNECTED) failed: %08x\n", hres); CHECK_CALLED(OnStateChange_CONNECTED); - CHECK_CALLED_MULTI(OnEnterScript, 4); - CHECK_CALLED_MULTI(OnLeaveScript, 4); + CHECK_CALLED_MULTI(OnEnterScript, 5); + CHECK_CALLED_MULTI(OnLeaveScript, 5); test_state(script, SCRIPTSTATE_CONNECTED);
+ script_disp2 = get_script_dispatch(script, L"persistent"); + ok(script_disp != script_disp2, "Same script dispatch returned for "persistent" named item\n"); + IDispatchEx_Release(script_disp2); + IDispatchEx_Release(script_disp); + SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"x", L"persistent", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + ok(V_VT(&var) == VT_I2 && V_I2(&var) == 13, "Unexpected 'x': V_VT = %d, V_I2 = %d\n", V_VT(&var), V_I2(&var)); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + script_disp = get_script_dispatch(script, NULL); for (i = 0; i < ARRAY_SIZE(global_idents); i++) { @@ -2237,6 +2310,7 @@ static void test_named_items(void) ok(global_named_item_ref == 0, "global_named_item_ref = %u\n", global_named_item_ref); ok(visible_named_item_ref == 0, "visible_named_item_ref = %u\n", visible_named_item_ref); ok(visible_code_named_item_ref == 0, "visible_code_named_item_ref = %u\n", visible_code_named_item_ref); + ok(persistent_named_item_ref == 0, "persistent_named_item_ref = %u\n", persistent_named_item_ref);
test_state(script, SCRIPTSTATE_CLOSED);
Signed-off-by: Jacek Caban jacek@codeweavers.com