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))) {