From 28bddf8dd1599b00ca571d01636711b8f23f350c Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 16 Sep 2011 13:29:25 +0200 Subject: [PATCH] vbscript: Added class_initializer support. --- dlls/vbscript/compile.c | 12 ++++++++++++ dlls/vbscript/tests/lang.vbs | 4 ++++ dlls/vbscript/vbdisp.c | 12 ++++++++++++ dlls/vbscript/vbscript.h | 1 + 4 files changed, 29 insertions(+) diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index bcf7b52bba7..00dfc50e154 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -893,6 +893,8 @@ static HRESULT compile_class(compile_ctx_t *ctx, class_decl_t *class_decl) unsigned i; HRESULT hres; + static const WCHAR class_initializeW[] = {'c','l','a','s','s','_','i','n','i','t','i','a','l','i','z','e',0}; + if(lookup_dim_decls(ctx, class_decl->name) || lookup_funcs_name(ctx, class_decl->name) || lookup_class_name(ctx, class_decl->name)) { FIXME("%s: redefinition\n", debugstr_w(class_decl->name)); @@ -909,6 +911,7 @@ static HRESULT compile_class(compile_ctx_t *ctx, class_decl_t *class_decl) class_desc->func_cnt = 1; /* always allocate slot for default getter */ class_desc->prop_cnt = 0; + class_desc->class_initialize_id = 0; for(func_decl = class_decl->funcs; func_decl; func_decl = func_decl->next) { for(func_prop_decl = func_decl; func_prop_decl; func_prop_decl = func_prop_decl->next_prop_func) { @@ -932,6 +935,15 @@ static HRESULT compile_class(compile_ctx_t *ctx, class_decl_t *class_decl) } } + if(!strcmpiW(class_initializeW, func_decl->name)) { + if(func_decl->type != FUNC_SUB) { + FIXME("class initializer is not sub\n"); + return E_FAIL; + } + + class_desc->class_initialize_id = i; + } + hres = create_class_funcprop(ctx, func_decl, class_desc->funcs + (func_prop_decl ? 0 : i)); if(FAILED(hres)) return hres; diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 08f4736512f..46317b9f704 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -465,6 +465,7 @@ obj.publicProp = 3 Call ok(obj.publicProp = 3, "obj.publicProp = " & obj.publicProp) obj.publicProp() = 3 +Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp()) Call obj.setPrivateProp(6) Call ok(obj.getPrivateProp = 6, "obj.getPrivateProp = " & obj.getPrivateProp) @@ -485,6 +486,9 @@ funcCalled = "" Call ok(obj = 3, "(x = obj) = " & obj) Call ok(funcCalled = "GetDefVal", "funcCalled = " & funcCalled) +Call obj.Class_Initialize +Call ok(obj.getPrivateProp() = true, "obj.getPrivateProp() = " & obj.getPrivateProp()) + x = (New testclass).publicProp reportSuccess() diff --git a/dlls/vbscript/vbdisp.c b/dlls/vbscript/vbdisp.c index a5fa63cb000..e1386bee26c 100644 --- a/dlls/vbscript/vbdisp.c +++ b/dlls/vbscript/vbdisp.c @@ -375,6 +375,18 @@ HRESULT create_vbdisp(const class_desc_t *desc, vbdisp_t **ret) vbdisp->ref = 1; vbdisp->desc = desc; + if(desc->class_initialize_id) { + DISPPARAMS dp = {0}; + HRESULT hres; + + hres = exec_script(desc->ctx, desc->funcs[desc->class_initialize_id].entries[VBDISP_CALLGET], + (IDispatch*)&vbdisp->IDispatchEx_iface, &dp, NULL); + if(FAILED(hres)) { + IDispatchEx_Release(&vbdisp->IDispatchEx_iface); + return hres; + } + } + *ret = vbdisp; return S_OK; } diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h index 37931dbe432..270e223a091 100644 --- a/dlls/vbscript/vbscript.h +++ b/dlls/vbscript/vbscript.h @@ -76,6 +76,7 @@ typedef struct { typedef struct _class_desc_t { const WCHAR *name; script_ctx_t *ctx; + unsigned class_initialize_id; unsigned func_cnt; vbdisp_funcprop_desc_t *funcs; unsigned prop_cnt;