Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com ---
v5: Don't use an extra parameter, instead calculate it based on 'flags'.
dlls/vbscript/tests/vbscript.c | 56 +++++++++++++++++++++++++++++++++- dlls/vbscript/vbscript.c | 3 +- 2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c index 10af993..4e44758 100644 --- a/dlls/vbscript/tests/vbscript.c +++ b/dlls/vbscript/tests/vbscript.c @@ -97,6 +97,7 @@ DEFINE_EXPECT(OnEnterScript); DEFINE_EXPECT(OnLeaveScript); DEFINE_EXPECT(GetItemInfo_global); DEFINE_EXPECT(GetItemInfo_visible); +DEFINE_EXPECT(GetItemInfo_visible_code); DEFINE_EXPECT(testCall);
DEFINE_GUID(CLSID_VBScript, 0xb54f3741, 0x5b07, 0x11cf, 0xa4,0xb0, 0x00,0xaa,0x00,0x4a,0x55,0xe8); @@ -137,7 +138,7 @@ static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, voi return E_NOINTERFACE; }
-static ULONG global_named_item_ref, visible_named_item_ref; +static ULONG global_named_item_ref, visible_named_item_ref, visible_code_named_item_ref;
static ULONG WINAPI global_AddRef(IDispatch *iface) { @@ -159,6 +160,16 @@ static ULONG WINAPI visible_Release(IDispatch *iface) return --visible_named_item_ref; }
+static ULONG WINAPI visible_code_AddRef(IDispatch *iface) +{ + return ++visible_code_named_item_ref; +} + +static ULONG WINAPI visible_code_Release(IDispatch *iface) +{ + return --visible_code_named_item_ref; +} + static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo) { ok(0, "unexpected call\n"); @@ -214,6 +225,18 @@ static const IDispatchVtbl visible_named_item_vtbl = {
static IDispatch visible_named_item = { &visible_named_item_vtbl };
+static const IDispatchVtbl visible_code_named_item_vtbl = { + Dispatch_QueryInterface, + visible_code_AddRef, + visible_code_Release, + Dispatch_GetTypeInfoCount, + Dispatch_GetTypeInfo, + Dispatch_GetIDsOfNames, + Dispatch_Invoke +}; + +static IDispatch visible_code_named_item = { &visible_code_named_item_vtbl }; + static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv) { *ppv = NULL; @@ -261,6 +284,12 @@ static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPC *item_unk = (IUnknown*)&visible_named_item; return S_OK; } + if(!wcscmp(name, L"visibleCodeItem")) { + CHECK_EXPECT(GetItemInfo_visible_code); + IDispatch_AddRef(&visible_code_named_item); + *item_unk = (IUnknown*)&visible_code_named_item; + return S_OK; + } ok(0, "unexpected call %s\n", wine_dbgstr_w(name)); return E_NOTIMPL; } @@ -1704,6 +1733,7 @@ static void test_named_items(void) { IActiveScriptParse *parse; IActiveScript *script; + IDispatch *disp; ULONG ref; HRESULT hres;
@@ -1731,9 +1761,12 @@ static void test_named_items(void)
hres = IActiveScript_AddNamedItem(script, L"visibleItem", SCRIPTITEM_ISVISIBLE); ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres); + hres = IActiveScript_AddNamedItem(script, L"visibleCodeItem", SCRIPTITEM_ISVISIBLE | 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);
SET_EXPECT(OnStateChange_INITIALIZED); hres = IActiveScriptParse_InitNew(parse); @@ -1755,8 +1788,28 @@ static void test_named_items(void) CHECK_CALLED(GetItemInfo_visible); CHECK_CALLED(testCall);
+ SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + SET_EXPECT(testCall); + hres = IActiveScriptParse_ParseScriptText(parse, L"testCall\n", L"visibleCodeItem", NULL, NULL, 0, 0, 0, NULL, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + CHECK_CALLED(testCall); + + hres = IActiveScript_GetScriptDispatch(script, L"visibleCodeItem", &disp); + ok(hres == S_OK, "GetScriptDispatch returned: %08x\n", hres); + IDispatch_Release(disp); + + SET_EXPECT(GetItemInfo_visible_code); + SET_EXPECT(testCall); + parse_script(parse, "visibleCodeItem.testCall\n"); + CHECK_CALLED(GetItemInfo_visible_code); + CHECK_CALLED(testCall); + 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);
SET_EXPECT(testCall); parse_script(parse, "visibleItem.testCall\n"); @@ -1773,6 +1826,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);
test_state(script, SCRIPTSTATE_CLOSED);
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 88574fe..670b66d 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -191,12 +191,13 @@ static void exec_queued_code(script_ctx_t *ctx)
named_item_t *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned flags) { + unsigned no_disp_flags = flags ? 0 : SCRIPTITEM_CODEONLY; named_item_t *item; HRESULT hres;
LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) { if((item->flags & flags) == flags && !wcsicmp(item->name, name)) { - if(!item->disp) { + if(!item->disp && !(item->flags & no_disp_flags)) { IUnknown *unk;
hres = IActiveScriptSite_GetItemInfo(ctx->site, item->name,