From: Francis De Brabandere <francisdb@gmail.com> When Option Explicit is set and a For loop uses an undefined variable, return MAKE_VBSERROR(VBSE_VARIABLE_UNDEFINED) (error 500) instead of E_FAIL. Fix both interp_step and interp_incc to handle REF_NONE by returning the proper VBS error code with description. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57511 --- dlls/vbscript/interp.c | 7 +++++-- dlls/vbscript/tests/error.vbs | 10 ++++++++++ dlls/vbscript/tests/run.c | 1 + dlls/vbscript/vbscript.rc | 1 + dlls/vbscript/vbscript_defs.h | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 127fcc2c05e..dee0c952e6d 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -906,8 +906,7 @@ static HRESULT assign_ident(exec_ctx_t *ctx, BSTR name, WORD flags, DISPPARAMS * return E_NOTIMPL; case REF_NONE: if(ctx->func->code_ctx->option_explicit) { - FIXME("throw exception\n"); - hres = E_FAIL; + return MAKE_VBSERROR(VBSE_VARIABLE_UNDEFINED); }else { VARIANT *new_var; @@ -1447,6 +1446,8 @@ static HRESULT interp_step(exec_ctx_t *ctx) return hres; if(ref.type != REF_VAR) { + if(ref.type == REF_NONE) + return MAKE_VBSERROR(VBSE_VARIABLE_UNDEFINED); FIXME("%s is not REF_VAR\n", debugstr_w(ident)); return E_FAIL; } @@ -2381,6 +2382,8 @@ static HRESULT interp_incc(exec_ctx_t *ctx) return hres; if(ref.type != REF_VAR) { + if(ref.type == REF_NONE) + return MAKE_VBSERROR(VBSE_VARIABLE_UNDEFINED); FIXME("ref.type is not REF_VAR\n"); return E_FAIL; } diff --git a/dlls/vbscript/tests/error.vbs b/dlls/vbscript/tests/error.vbs index 9b74dc8773e..da9548bf220 100644 --- a/dlls/vbscript/tests/error.vbs +++ b/dlls/vbscript/tests/error.vbs @@ -223,6 +223,15 @@ sub testThrow call todo_wine_ok(x = 6, "x = " & x) call todo_wine_ok(Err.Number = VB_E_FORLOOPNOTINITIALIZED, "Err.Number = " & Err.Number) + Err.clear() + y = 0 + for undefinedVar = 0 To 3 + y = y + 1 + next + call ok(y = 1, "y = " & y) + call ok(Err.Number = 500, "Err.Number = " & Err.Number) + call ok(Err.Description <> "", "Err.Description should not be empty, got: " & Err.Description) + select case throwInt(E_TESTERROR) case true call ok(false, "unexpected case true") @@ -476,4 +485,5 @@ ok err.helpfile = "test.chm", "err.helpfile = " & err.helpfile on error goto 0 + call reportSuccess() diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 8aaafbedf54..9da7fc09fbb 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -3410,6 +3410,7 @@ static void run_tests(void) ok(FAILED(hres), "script didn't fail\n"); CHECK_CALLED(OnScriptError); + SET_EXPECT(global_success_d); SET_EXPECT(global_success_i); parse_script_w(L"' comment\r" diff --git a/dlls/vbscript/vbscript.rc b/dlls/vbscript/vbscript.rc index cf157f77526..50e7cf12f93 100644 --- a/dlls/vbscript/vbscript.rc +++ b/dlls/vbscript/vbscript.rc @@ -56,6 +56,7 @@ STRINGTABLE VBSE_INVALID_DLL_FUNCTION_NAME "Specified DLL function not found" VBSE_INVALID_TYPELIB_VARIABLE "Variable uses an Automation type not supported in VBScript" VBSE_SERVER_NOT_FOUND "The remote server machine does not exist or is unavailable" + VBSE_VARIABLE_UNDEFINED "Variable is undefined" VBSE_UNQUALIFIED_REFERENCE "Invalid or unqualified reference" VBS_COMPILE_ERROR "Microsoft VBScript compilation error" diff --git a/dlls/vbscript/vbscript_defs.h b/dlls/vbscript/vbscript_defs.h index 139b71255a0..92bd236ad6b 100644 --- a/dlls/vbscript/vbscript_defs.h +++ b/dlls/vbscript/vbscript_defs.h @@ -267,6 +267,7 @@ #define VBSE_INVALID_DLL_FUNCTION_NAME 453 #define VBSE_INVALID_TYPELIB_VARIABLE 458 #define VBSE_SERVER_NOT_FOUND 462 +#define VBSE_VARIABLE_UNDEFINED 500 #define VBSE_UNQUALIFIED_REFERENCE 505 #define VBS_COMPILE_ERROR 4096 -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10374