Commit 1e01a176 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Added this object to identifier lookup chanin.

parent 308b2641
...@@ -30,6 +30,7 @@ typedef struct { ...@@ -30,6 +30,7 @@ typedef struct {
instr_t *instr; instr_t *instr;
script_ctx_t *script; script_ctx_t *script;
function_t *func; function_t *func;
IDispatch *this_obj;
VARIANT *args; VARIANT *args;
VARIANT *vars; VARIANT *vars;
...@@ -113,6 +114,14 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_ ...@@ -113,6 +114,14 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_
} }
} }
hres = disp_get_id(ctx->this_obj, name, TRUE, &id);
if(SUCCEEDED(hres)) {
ref->type = REF_DISP;
ref->u.d.disp = ctx->this_obj;
ref->u.d.id = id;
return S_OK;
}
if(lookup_dynamic_vars(ctx->script->global_vars, name, ref)) if(lookup_dynamic_vars(ctx->script->global_vars, name, ref))
return S_OK; return S_OK;
...@@ -125,8 +134,8 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_ ...@@ -125,8 +134,8 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_
} }
LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) { LIST_FOR_EACH_ENTRY(item, &ctx->script->named_items, named_item_t, entry) {
if(item->flags & SCRIPTITEM_GLOBALMEMBERS) { if((item->flags & SCRIPTITEM_GLOBALMEMBERS) && item->disp != ctx->this_obj) {
hres = disp_get_id(item->disp, name, &id); hres = disp_get_id(item->disp, name, FALSE, &id);
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
ref->type = REF_DISP; ref->type = REF_DISP;
ref->u.d.disp = item->disp; ref->u.d.disp = item->disp;
...@@ -294,7 +303,7 @@ static HRESULT do_icall(exec_ctx_t *ctx, VARIANT *res) ...@@ -294,7 +303,7 @@ static HRESULT do_icall(exec_ctx_t *ctx, VARIANT *res)
return hres; return hres;
break; break;
case REF_FUNC: case REF_FUNC:
hres = exec_script(ctx->script, ref.u.f, &dp, res); hres = exec_script(ctx->script, ref.u.f, NULL, &dp, res);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
break; break;
...@@ -347,7 +356,7 @@ static HRESULT do_mcall(exec_ctx_t *ctx, VARIANT *res) ...@@ -347,7 +356,7 @@ static HRESULT do_mcall(exec_ctx_t *ctx, VARIANT *res)
vbstack_to_dp(ctx, arg_cnt, &dp); vbstack_to_dp(ctx, arg_cnt, &dp);
hres = disp_get_id(obj, identifier, &id); hres = disp_get_id(obj, identifier, FALSE, &id);
if(SUCCEEDED(hres)) if(SUCCEEDED(hres))
hres = disp_call(ctx->script, obj, id, &dp, res); hres = disp_call(ctx->script, obj, id, &dp, res);
IDispatch_Release(obj); IDispatch_Release(obj);
...@@ -480,7 +489,7 @@ static HRESULT interp_assign_member(exec_ctx_t *ctx) ...@@ -480,7 +489,7 @@ static HRESULT interp_assign_member(exec_ctx_t *ctx)
return hres; return hres;
} }
hres = disp_get_id(obj, identifier, &id); hres = disp_get_id(obj, identifier, FALSE, &id);
if(SUCCEEDED(hres)) if(SUCCEEDED(hres))
hres = disp_propput(ctx->script, obj, id, val.v); hres = disp_propput(ctx->script, obj, id, val.v);
...@@ -1084,6 +1093,9 @@ static void release_exec(exec_ctx_t *ctx) ...@@ -1084,6 +1093,9 @@ static void release_exec(exec_ctx_t *ctx)
VariantClear(&ctx->ret_val); VariantClear(&ctx->ret_val);
if(ctx->this_obj)
IDispatch_Release(ctx->this_obj);
if(ctx->args) { if(ctx->args) {
for(i=0; i < ctx->func->arg_cnt; i++) for(i=0; i < ctx->func->arg_cnt; i++)
VariantClear(ctx->args+i); VariantClear(ctx->args+i);
...@@ -1099,7 +1111,7 @@ static void release_exec(exec_ctx_t *ctx) ...@@ -1099,7 +1111,7 @@ static void release_exec(exec_ctx_t *ctx)
heap_free(ctx->stack); heap_free(ctx->stack);
} }
HRESULT exec_script(script_ctx_t *ctx, function_t *func, DISPPARAMS *dp, VARIANT *res) HRESULT exec_script(script_ctx_t *ctx, function_t *func, IDispatch *this_obj, DISPPARAMS *dp, VARIANT *res)
{ {
exec_ctx_t exec = {func->code_ctx}; exec_ctx_t exec = {func->code_ctx};
vbsop_t op; vbsop_t op;
...@@ -1159,6 +1171,14 @@ HRESULT exec_script(script_ctx_t *ctx, function_t *func, DISPPARAMS *dp, VARIANT ...@@ -1159,6 +1171,14 @@ HRESULT exec_script(script_ctx_t *ctx, function_t *func, DISPPARAMS *dp, VARIANT
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
if(this_obj)
exec.this_obj = this_obj;
else if (ctx->host_global)
exec.this_obj = ctx->host_global;
else
exec.this_obj = (IDispatch*)&ctx->script_obj->IDispatchEx_iface;
IDispatch_AddRef(exec.this_obj);
exec.instr = exec.code->instrs + func->code_off; exec.instr = exec.code->instrs + func->code_off;
exec.script = ctx; exec.script = ctx;
exec.func = func; exec.func = func;
......
...@@ -388,6 +388,7 @@ End Class ...@@ -388,6 +388,7 @@ End Class
Class TestClass Class TestClass
Public Function publicFunction() Public Function publicFunction()
privateSub()
publicFunction = 4 publicFunction = 4
End Function End Function
......
...@@ -46,6 +46,15 @@ static BOOL get_func_id(vbdisp_t *This, const WCHAR *name, BOOL search_private, ...@@ -46,6 +46,15 @@ static BOOL get_func_id(vbdisp_t *This, const WCHAR *name, BOOL search_private,
return FALSE; return FALSE;
} }
static HRESULT vbdisp_get_id(vbdisp_t *This, BSTR name, BOOL search_private, DISPID *id)
{
if(get_func_id(This, name, search_private, id))
return S_OK;
*id = -1;
return DISP_E_UNKNOWNNAME;
}
static inline vbdisp_t *impl_from_IDispatchEx(IDispatchEx *iface) static inline vbdisp_t *impl_from_IDispatchEx(IDispatchEx *iface)
{ {
return CONTAINING_RECORD(iface, vbdisp_t, IDispatchEx_iface); return CONTAINING_RECORD(iface, vbdisp_t, IDispatchEx_iface);
...@@ -144,11 +153,7 @@ static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DW ...@@ -144,11 +153,7 @@ static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DW
return E_NOTIMPL; return E_NOTIMPL;
} }
if(get_func_id(This, bstrName, FALSE, pid)) return vbdisp_get_id(This, bstrName, FALSE, pid);
return S_OK;
*pid = -1;
return DISP_E_UNKNOWNNAME;
} }
static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp, static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
...@@ -176,7 +181,7 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc ...@@ -176,7 +181,7 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
return DISP_E_MEMBERNOTFOUND; return DISP_E_MEMBERNOTFOUND;
} }
return exec_script(This->desc->ctx, func, pdp, pvarRes); return exec_script(This->desc->ctx, func, (IDispatch*)&This->IDispatchEx_iface, pdp, pvarRes);
default: default:
FIXME("flags %x\n", wFlags); FIXME("flags %x\n", wFlags);
return DISP_E_MEMBERNOTFOUND; return DISP_E_MEMBERNOTFOUND;
...@@ -247,6 +252,13 @@ static IDispatchExVtbl DispatchExVtbl = { ...@@ -247,6 +252,13 @@ static IDispatchExVtbl DispatchExVtbl = {
DispatchEx_GetNameSpaceParent DispatchEx_GetNameSpaceParent
}; };
static inline vbdisp_t *unsafe_impl_from_IDispatch(IDispatch *iface)
{
return iface->lpVtbl == (IDispatchVtbl*)&DispatchExVtbl
? CONTAINING_RECORD(iface, vbdisp_t, IDispatchEx_iface)
: NULL;
}
HRESULT create_vbdisp(const class_desc_t *desc, vbdisp_t **ret) HRESULT create_vbdisp(const class_desc_t *desc, vbdisp_t **ret)
{ {
vbdisp_t *vbdisp; vbdisp_t *vbdisp;
...@@ -269,13 +281,15 @@ HRESULT init_global(script_ctx_t *ctx) ...@@ -269,13 +281,15 @@ HRESULT init_global(script_ctx_t *ctx)
return create_vbdisp(&ctx->script_desc, &ctx->script_obj); return create_vbdisp(&ctx->script_desc, &ctx->script_obj);
} }
HRESULT disp_get_id(IDispatch *disp, BSTR name, DISPID *id) HRESULT disp_get_id(IDispatch *disp, BSTR name, BOOL search_private, DISPID *id)
{ {
IDispatchEx *dispex; IDispatchEx *dispex;
vbdisp_t *vbdisp;
HRESULT hres; HRESULT hres;
if(disp->lpVtbl == (IDispatchVtbl*)&DispatchExVtbl) vbdisp = unsafe_impl_from_IDispatch(disp);
FIXME("properly handle builtin objects\n"); if(vbdisp)
return vbdisp_get_id(vbdisp, name, search_private, id);
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex); hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
if(FAILED(hres)) { if(FAILED(hres)) {
......
...@@ -77,7 +77,7 @@ static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code) ...@@ -77,7 +77,7 @@ static HRESULT exec_global_code(script_ctx_t *ctx, vbscode_t *code)
code->global_executed = TRUE; code->global_executed = TRUE;
IActiveScriptSite_OnEnterScript(ctx->site); IActiveScriptSite_OnEnterScript(ctx->site);
hres = exec_script(ctx, &code->global_code, NULL, NULL); hres = exec_script(ctx, &code->global_code, NULL, NULL, NULL);
IActiveScriptSite_OnLeaveScript(ctx->site); IActiveScriptSite_OnLeaveScript(ctx->site);
return hres; return hres;
......
...@@ -85,7 +85,7 @@ typedef struct { ...@@ -85,7 +85,7 @@ typedef struct {
} vbdisp_t; } vbdisp_t;
HRESULT create_vbdisp(const class_desc_t*,vbdisp_t**); HRESULT create_vbdisp(const class_desc_t*,vbdisp_t**);
HRESULT disp_get_id(IDispatch*,BSTR,DISPID*); HRESULT disp_get_id(IDispatch*,BSTR,BOOL,DISPID*);
HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*); HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*);
HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,VARIANT*); HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,VARIANT*);
...@@ -241,7 +241,7 @@ struct _vbscode_t { ...@@ -241,7 +241,7 @@ struct _vbscode_t {
void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN; void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
HRESULT compile_script(script_ctx_t*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN; HRESULT compile_script(script_ctx_t*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
HRESULT exec_script(script_ctx_t*,function_t*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN; HRESULT exec_script(script_ctx_t*,function_t*,IDispatch*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**); HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment