[PATCH v4 0/1] MR10374: vbscript: Throw proper error for undefined variables with Option Explicit.
When Option Explicit is set and a For loop uses an undefined variable, throw error 500 (Variable is undefined) with proper description instead of just returning E_FAIL. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57511 -- v4: vbscript: Throw proper error for undefined variables with Option Explicit. https://gitlab.winehq.org/wine/wine/-/merge_requests/10374
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 | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index ad8ece8605d..c33a1745e3c 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -953,8 +953,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; @@ -1555,6 +1554,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; } @@ -2487,6 +2488,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 1ffe88318e9..4f4add00a3c 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") -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10374
participants (2)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb)