[PATCH v8 0/1] MR10404: vbscript: Reject arguments on Class_Initialize and Class_Terminate.
Windows returns error 1053 when Class_Initialize or Class_Terminate are declared with arguments. Add the same check in compile_class() and store source location in function_decl_t for accurate error reporting. -- v8: vbscript: Reject arguments on Class_Initialize and Class_Terminate. https://gitlab.winehq.org/wine/wine/-/merge_requests/10404
From: Francis De Brabandere <francisdb@gmail.com> Windows returns error 1053 when Class_Initialize or Class_Terminate are declared with arguments. Add the same check in compile_class() and store source location in function_decl_t for accurate error reporting. --- dlls/vbscript/compile.c | 8 ++++++++ dlls/vbscript/parse.h | 1 + dlls/vbscript/parser.y | 19 ++++++++++--------- dlls/vbscript/tests/run.c | 21 ++++++++++++++++----- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index 6ef01832c47..54314372a13 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -1958,6 +1958,10 @@ static HRESULT compile_class(compile_ctx_t *ctx, class_decl_t *class_decl) FIXME("class initializer is not sub\n"); return E_FAIL; } + if(func_decl->args) { + ctx->loc = func_decl->loc; + return MAKE_VBSERROR(VBSE_CLASS_INIT_NO_ARGS); + } class_desc->class_initialize_id = i; }else if(!vbs_wcsicmp(L"class_terminate", func_decl->name)) { @@ -1965,6 +1969,10 @@ static HRESULT compile_class(compile_ctx_t *ctx, class_decl_t *class_decl) FIXME("class terminator is not sub\n"); return E_FAIL; } + if(func_decl->args) { + ctx->loc = func_decl->loc; + return MAKE_VBSERROR(VBSE_CLASS_INIT_NO_ARGS); + } class_desc->class_terminate_id = i; } diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h index 271122b59ae..a4d5079d10e 100644 --- a/dlls/vbscript/parse.h +++ b/dlls/vbscript/parse.h @@ -204,6 +204,7 @@ typedef struct _function_decl_t { BOOL is_default; arg_decl_t *args; statement_t *body; + unsigned loc; struct _function_decl_t *next; struct _function_decl_t *next_prop_func; } function_decl_t; diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index a7d95eaa707..f4b573e2d15 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -67,7 +67,7 @@ static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,unsigned,BOOL,dim_lis static dim_list_t *new_dim(parser_ctx_t*,unsigned,dim_list_t*); static redim_decl_t *new_redim_decl(parser_ctx_t*,const WCHAR*,expression_t*); static elseif_decl_t *new_elseif_decl(parser_ctx_t*,unsigned,expression_t*,statement_t*); -static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,unsigned,arg_decl_t*,statement_t*); +static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,unsigned,unsigned,arg_decl_t*,statement_t*); static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL); static const_decl_t *new_const_decl(parser_ctx_t*,const WCHAR*,expression_t*); static case_clausule_t *new_case_clausule(parser_ctx_t*,expression_t*,statement_t*,case_clausule_t*); @@ -495,21 +495,21 @@ ClassBody PropertyDecl : Storage_opt tPROPERTY tGET Identifier ArgumentsDecl_opt StSep BodyStatements tEND tPROPERTY - { $$ = new_function_decl(ctx, $4, FUNC_PROPGET, $1, $5, $7); CHECK_ERROR; } + { $$ = new_function_decl(ctx, $4, FUNC_PROPGET, @2, $1, $5, $7); CHECK_ERROR; } | Storage_opt tPROPERTY tLET Identifier '(' ArgumentDeclList ')' StSep BodyStatements tEND tPROPERTY - { $$ = new_function_decl(ctx, $4, FUNC_PROPLET, $1, $6, $9); CHECK_ERROR; } + { $$ = new_function_decl(ctx, $4, FUNC_PROPLET, @2, $1, $6, $9); CHECK_ERROR; } | Storage_opt tPROPERTY tSET Identifier '(' ArgumentDeclList ')' StSep BodyStatements tEND tPROPERTY - { $$ = new_function_decl(ctx, $4, FUNC_PROPSET, $1, $6, $9); CHECK_ERROR; } + { $$ = new_function_decl(ctx, $4, FUNC_PROPSET, @2, $1, $6, $9); CHECK_ERROR; } FunctionDecl : Storage_opt tSUB Identifier StSep BodyStatements tEND tSUB - { $$ = new_function_decl(ctx, $3, FUNC_SUB, $1, NULL, $5); CHECK_ERROR; } + { $$ = new_function_decl(ctx, $3, FUNC_SUB, @2, $1, NULL, $5); CHECK_ERROR; } | Storage_opt tSUB Identifier ArgumentsDecl Nl_opt BodyStatements tEND tSUB - { $$ = new_function_decl(ctx, $3, FUNC_SUB, $1, $4, $6); CHECK_ERROR; } + { $$ = new_function_decl(ctx, $3, FUNC_SUB, @2, $1, $4, $6); CHECK_ERROR; } | Storage_opt tFUNCTION Identifier StSep BodyStatements tEND tFUNCTION - { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, $1, NULL, $5); CHECK_ERROR; } + { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, @2, $1, NULL, $5); CHECK_ERROR; } | Storage_opt tFUNCTION Identifier ArgumentsDecl Nl_opt BodyStatements tEND tFUNCTION - { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, $1, $4, $6); CHECK_ERROR; } + { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, @2, $1, $4, $6); CHECK_ERROR; } Storage_opt : /* empty*/ { $$ = 0; } @@ -1089,7 +1089,7 @@ static arg_decl_t *new_argument_decl(parser_ctx_t *ctx, const WCHAR *name, BOOL } static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name, function_type_t type, - unsigned storage_flags, arg_decl_t *arg_decl, statement_t *body) + unsigned loc, unsigned storage_flags, arg_decl_t *arg_decl, statement_t *body) { function_decl_t *decl; BOOL is_default = FALSE; @@ -1114,6 +1114,7 @@ static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name, decl->is_default = is_default; decl->args = arg_decl; decl->body = body; + decl->loc = loc; decl->next = NULL; decl->next_prop_func = NULL; return decl; diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 70ccd517254..87672bbfe55 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -3001,13 +3001,24 @@ static void test_parse_errors(void) 1, 9, NULL, S_OK, -1049 }, - /* TODO: Wine allows arguments on Class_Initialize/Class_Terminate { - Class initialize/terminate no arguments - error 1053 - L"Class C\nSub Class_Initialize(x)\nEnd Sub\nEnd Class\n", - 1, 20, 1053 + /* Class_Initialize with arguments - error 1053 */ + L"Class C\n" + "Sub Class_Initialize(x)\n" + "End Sub\n" + "End Class\n", + 1, -23, + NULL, S_OK, 1053 + }, + { + /* Class_Terminate with arguments - error 1053 */ + L"Class C\n" + "Sub Class_Terminate(x)\n" + "End Sub\n" + "End Class\n", + 1, -22, + NULL, S_OK, 1053 }, - */ { /* Property Let/Set needs at least one argument - error 1054 */ L"Class C\nProperty Let x\nEnd Property\nEnd Class\n", -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10404
This merge request was approved by Jacek Caban. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10404
participants (3)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb) -
Jacek Caban (@jacek)