Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/interp.c | 4 +++- dlls/vbscript/tests/vbscript.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index b0046cb..27a4aee 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -1527,7 +1527,9 @@ static HRESULT interp_me(exec_ctx_t *ctx) if(ctx->vbthis) disp = (IDispatch*)&ctx->vbthis->IDispatchEx_iface; else if(ctx->code->named_item) - disp = (IDispatch*)&ctx->code->named_item->script_obj->IDispatchEx_iface; + disp = (ctx->code->named_item->flags & SCRIPTITEM_CODEONLY) + ? (IDispatch*)&ctx->code->named_item->script_obj->IDispatchEx_iface + : ctx->code->named_item->disp; else if(ctx->script->host_global) disp = ctx->script->host_global; else diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c index 19689b5..8536ee1 100644 --- a/dlls/vbscript/tests/vbscript.c +++ b/dlls/vbscript/tests/vbscript.c @@ -1858,6 +1858,15 @@ static void test_named_items(void)
hres = IActiveScript_GetScriptDispatch(script, L"visibleCodeItem", &disp); ok(hres == S_OK, "GetScriptDispatch returned: %08x\n", hres); + SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"me", L"visibleCodeItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == disp, + "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var)); + VariantClear(&var); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); IDispatch_Release(disp);
SET_EXPECT(GetItemInfo_visible_code); @@ -1993,6 +2002,15 @@ static void test_named_items(void) CHECK_CALLED(OnLeaveScript); SET_EXPECT(OnEnterScript); SET_EXPECT(OnLeaveScript); + hres = IActiveScriptParse_ParseScriptText(parse, L"me", L"globalItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); + ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); + ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == &global_named_item, + "Unexpected 'me': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var)); + VariantClear(&var); + CHECK_CALLED(OnEnterScript); + CHECK_CALLED(OnLeaveScript); + SET_EXPECT(OnEnterScript); + SET_EXPECT(OnLeaveScript); hres = IActiveScriptParse_ParseScriptText(parse, L"me", L"codeOnlyItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hres == S_OK, "ParseScriptText failed: %08x\n", hres); ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == (IDispatch*)script_disp2,
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/vbscript/tests/vbscript.c | 3 +++ dlls/vbscript/vbscript.c | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c index 8536ee1..9c62678 100644 --- a/dlls/vbscript/tests/vbscript.c +++ b/dlls/vbscript/tests/vbscript.c @@ -1813,6 +1813,9 @@ static void test_named_items(void) ok(hres == E_INVALIDARG, "GetScriptDispatch returned: %08x\n", hres);
script_disp = get_script_dispatch(script, NULL); + script_disp2 = get_script_dispatch(script, L"globalItem"); + ok(script_disp == script_disp2, "get_script_dispatch returned different dispatch objects.\n"); + IDispatchEx_Release(script_disp2); script_disp2 = get_script_dispatch(script, L"codeONLYitem"); ok(script_disp != script_disp2, "get_script_dispatch returned same dispatch objects.\n");
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 27985bf..c563a09 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -91,6 +91,16 @@ static inline BOOL is_started(VBScript *This) || This->state == SCRIPTSTATE_DISCONNECTED; }
+static HRESULT create_named_item_script_obj(script_ctx_t *ctx, named_item_t *item) +{ + if(item->flags & SCRIPTITEM_GLOBALMEMBERS) { + item->script_obj = ctx->script_obj; + IDispatchEx_AddRef(&item->script_obj->IDispatchEx_iface); + return S_OK; + } + return create_script_disp(ctx, &item->script_obj); +} + static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res) { ScriptDisp *obj = ctx->script_obj; @@ -101,7 +111,7 @@ static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code, VARIANT *res
if(code->named_item) { if(!code->named_item->script_obj) { - hres = create_script_disp(ctx, &code->named_item->script_obj); + hres = create_named_item_script_obj(ctx, code->named_item); if(FAILED(hres)) return hres; } obj = code->named_item->script_obj; @@ -206,7 +216,7 @@ named_item_t *lookup_named_item(script_ctx_t *ctx, const WCHAR *name, unsigned f LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) { if((item->flags & flags) == flags && !wcsicmp(item->name, name)) { if(!item->script_obj) { - hres = create_script_disp(ctx, &item->script_obj); + hres = create_named_item_script_obj(ctx, item); if(FAILED(hres)) return NULL; } if(!item->disp && (flags || !(item->flags & SCRIPTITEM_CODEONLY))) {
On 24.02.2020 14:44, Gabriel Ivăncescu wrote:
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com
dlls/vbscript/tests/vbscript.c | 3 +++ dlls/vbscript/vbscript.c | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c index 8536ee1..9c62678 100644 --- a/dlls/vbscript/tests/vbscript.c +++ b/dlls/vbscript/tests/vbscript.c @@ -1813,6 +1813,9 @@ static void test_named_items(void) ok(hres == E_INVALIDARG, "GetScriptDispatch returned: %08x\n", hres);
script_disp = get_script_dispatch(script, NULL);
- script_disp2 = get_script_dispatch(script, L"globalItem");
- ok(script_disp == script_disp2, "get_script_dispatch returned different dispatch objects.\n");
- IDispatchEx_Release(script_disp2); script_disp2 = get_script_dispatch(script, L"codeONLYitem"); ok(script_disp != script_disp2, "get_script_dispatch returned same dispatch objects.\n");
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 27985bf..c563a09 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -91,6 +91,16 @@ static inline BOOL is_started(VBScript *This) || This->state == SCRIPTSTATE_DISCONNECTED; }
+static HRESULT create_named_item_script_obj(script_ctx_t *ctx, named_item_t *item) +{
- if(item->flags & SCRIPTITEM_GLOBALMEMBERS) {
item->script_obj = ctx->script_obj;
IDispatchEx_AddRef(&item->script_obj->IDispatchEx_iface);
ctx->script_obj may not be right anymore at this point, see the attached test. It would be probably better to do that in AddNamedItem(). We already have SCRIPTITEM_GLOBALMEMBERS special treatment there.
Thanks,
Jacek
On 25/02/2020 13:58, Jacek Caban wrote:
On 24.02.2020 14:44, Gabriel Ivăncescu wrote:
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com
dlls/vbscript/tests/vbscript.c | 3 +++ dlls/vbscript/vbscript.c | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/tests/vbscript.c b/dlls/vbscript/tests/vbscript.c index 8536ee1..9c62678 100644 --- a/dlls/vbscript/tests/vbscript.c +++ b/dlls/vbscript/tests/vbscript.c @@ -1813,6 +1813,9 @@ static void test_named_items(void) ok(hres == E_INVALIDARG, "GetScriptDispatch returned: %08x\n", hres); script_disp = get_script_dispatch(script, NULL); + script_disp2 = get_script_dispatch(script, L"globalItem"); + ok(script_disp == script_disp2, "get_script_dispatch returned different dispatch objects.\n"); + IDispatchEx_Release(script_disp2); script_disp2 = get_script_dispatch(script, L"codeONLYitem"); ok(script_disp != script_disp2, "get_script_dispatch returned same dispatch objects.\n"); diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index 27985bf..c563a09 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -91,6 +91,16 @@ static inline BOOL is_started(VBScript *This) || This->state == SCRIPTSTATE_DISCONNECTED; } +static HRESULT create_named_item_script_obj(script_ctx_t *ctx, named_item_t *item) +{ + if(item->flags & SCRIPTITEM_GLOBALMEMBERS) { + item->script_obj = ctx->script_obj; + IDispatchEx_AddRef(&item->script_obj->IDispatchEx_iface);
ctx->script_obj may not be right anymore at this point, see the attached test. It would be probably better to do that in AddNamedItem(). We already have SCRIPTITEM_GLOBALMEMBERS special treatment there.
Right, I'll have to see what happens when it is restarted and try to add a test if it's not too hackish.
Thanks, Gabriel
So, it looks like the simplest approach to handle some weird situations is to not link the item to the vbscode at all if GLOBALMEMBERS is set; this includes some corner cases with both GLOBALMEMBERS and CODEONLY, as well as returning the global script dispatch, or the global host (disp).
I will send updated patches for both this and jscript, after the CODEONLY patch is committed, since the tests will depend on it.