vbscript: Added class_initializer support.

This commit is contained in:
Jacek Caban 2011-09-16 13:29:25 +02:00 committed by Alexandre Julliard
parent 888ce00531
commit 28bddf8dd1
4 changed files with 29 additions and 0 deletions

View File

@ -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;

View File

@ -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()

View File

@ -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;
}

View File

@ -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;