[PATCH] vbscript: Lookup the identifier in the named item's disp after its script dispatch.
Gabriel Ivăncescu
gabrielopcode at gmail.com
Fri Mar 27 11:06:41 CDT 2020
If the bytecode has a named item context, its disp is looked for the
identifier before any globals, but after its script dispatch.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
I don't know why Windows calls GetItemInfo_visible since visibleItem
already had it called, but only does it once (so it's definitely still
"stored" somewhere -- the refcount to it also show this). I know why it
calls GetIDsOfNames for the 'dim x', but for some reason we don't. So those
are marked todo_wine for now.
The logic follows the one from jscript.
dlls/vbscript/interp.c | 14 ++++++------
dlls/vbscript/tests/vbscript.c | 42 +++++++++++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c
index 95614b1..d50ef46 100644
--- a/dlls/vbscript/interp.c
+++ b/dlls/vbscript/interp.c
@@ -181,6 +181,13 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_
}
}
+ if(ctx->code->named_item) {
+ if(lookup_global_vars(ctx->code->named_item->script_obj, name, ref))
+ return S_OK;
+ if(lookup_global_funcs(ctx->code->named_item->script_obj, name, ref))
+ return S_OK;
+ }
+
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)) {
@@ -191,13 +198,6 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_
}
}
- if(ctx->code->named_item) {
- if(lookup_global_vars(ctx->code->named_item->script_obj, name, ref))
- return S_OK;
- if(lookup_global_funcs(ctx->code->named_item->script_obj, name, ref))
- return S_OK;
- }
-
if(lookup_global_vars(script_obj, name, ref))
return S_OK;
if(lookup_global_funcs(script_obj, name, ref))
diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c
index 7545ca3..a997a51 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(OnScriptError);
DEFINE_EXPECT(GetIDsOfNames);
+DEFINE_EXPECT(GetIDsOfNames_visible);
DEFINE_EXPECT(GetItemInfo_global);
DEFINE_EXPECT(GetItemInfo_global_code);
DEFINE_EXPECT(GetItemInfo_visible);
@@ -218,6 +219,19 @@ static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOL
return DISP_E_UNKNOWNNAME;
}
+static HRESULT WINAPI visible_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *names, UINT name_cnt,
+ LCID lcid, DISPID *ids)
+{
+ ok(name_cnt == 1, "name_cnt = %u\n", name_cnt);
+ if(!wcscmp(names[0], L"testCall")) {
+ *ids = 1;
+ return S_OK;
+ }
+
+ CHECK_EXPECT2(GetIDsOfNames_visible);
+ return DISP_E_UNKNOWNNAME;
+}
+
static HRESULT WINAPI Dispatch_Invoke(IDispatch *iface, DISPID id, REFIID riid, LCID lcid, WORD flags,
DISPPARAMS *dp, VARIANT *res, EXCEPINFO *ei, UINT *err)
{
@@ -259,7 +273,7 @@ static const IDispatchVtbl visible_named_item_vtbl = {
visible_Release,
Dispatch_GetTypeInfoCount,
Dispatch_GetTypeInfo,
- Dispatch_GetIDsOfNames,
+ visible_GetIDsOfNames,
Dispatch_Invoke
};
@@ -1998,6 +2012,32 @@ static void test_named_items(void)
CHECK_CALLED(OnEnterScript);
CHECK_CALLED(GetIDsOfNames);
CHECK_CALLED(OnLeaveScript);
+
+ SET_EXPECT(OnEnterScript);
+ SET_EXPECT(GetItemInfo_visible);
+ SET_EXPECT(GetIDsOfNames_visible);
+ SET_EXPECT(OnLeaveScript);
+ hres = IActiveScriptParse_ParseScriptText(parse, L"dim abc\n", L"visibleItem", NULL, NULL, 0, 0, 0, NULL, NULL);
+ ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
+ CHECK_CALLED(OnEnterScript);
+ todo_wine CHECK_CALLED(GetItemInfo_visible);
+ todo_wine CHECK_CALLED(GetIDsOfNames_visible);
+ CHECK_CALLED(OnLeaveScript);
+ SET_EXPECT(OnEnterScript);
+ SET_EXPECT(OnLeaveScript);
+ hres = IActiveScriptParse_ParseScriptText(parse, L"abc = 5\n", L"visibleItem", 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(GetIDsOfNames_visible);
+ SET_EXPECT(OnLeaveScript);
+ hres = IActiveScriptParse_ParseScriptText(parse, L"testVar_global = 5\n", L"visibleItem", NULL, NULL, 0, 0, 0, NULL, NULL);
+ ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
+ CHECK_CALLED(OnEnterScript);
+ CHECK_CALLED(GetIDsOfNames_visible);
+ CHECK_CALLED(OnLeaveScript);
+
SET_EXPECT(OnEnterScript);
SET_EXPECT(OnLeaveScript);
hres = IActiveScriptParse_ParseScriptText(parse, L"set global_me = me\n", L"globalItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISPERSISTENT, NULL, NULL);
--
2.21.0
More information about the wine-devel
mailing list