[PATCH v8 0/2] MR10589: vbscript: Add missing runtime error constants and tests.
Add VBSE_DUPLICATE_KEY (457) and VBSE_CLASS_NOT_DEFINED (506) error code definitions with their string resources, and add tests for runtime errors 11, 94, 429, 451, 457, and 506. Errors 94 and 506 are marked todo_wine as Wine currently returns incorrect error codes for those cases. -- v8: vbscript: Return proper error for New on undefined or non-class identifier. https://gitlab.winehq.org/wine/wine/-/merge_requests/10589
From: Francis De Brabandere <francisdb@gmail.com> Add VBSE_DUPLICATE_KEY (457) and VBSE_CLASS_NOT_DEFINED (506) error code definitions with their string resources, and add tests for runtime errors 11, 94, 429, 451, 457, and 506. Errors 94 and 506 are marked todo_wine as Wine currently returns incorrect error codes for those cases. --- dlls/vbscript/tests/lang.vbs | 55 +++++++++++++++++++++++++++++++++++ dlls/vbscript/vbscript.rc | 2 ++ dlls/vbscript/vbscript_defs.h | 2 ++ 3 files changed, 59 insertions(+) diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 777d7bfc5a9..27c43dd7c9f 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -3183,4 +3183,59 @@ Call ok(Err.Number = 13, "bool var as statement: err = " & Err.Number) On Error GoTo 0 +' Tests for missing runtime error codes +On Error Resume Next + +' Error 11: Division by zero +Err.Clear +Dim divZeroResult +divZeroResult = 1 \ 0 +Call ok(Err.Number = 11, "division by zero: err.number = " & Err.Number) + +' Error 94: Invalid use of Null +Err.Clear +Dim nullResult +nullResult = CLng(Null) +todo_wine_ok Err.Number = 94, "CLng(Null): err.number = " & Err.Number + +' Error 429: ActiveX component can't create object +Err.Clear +Dim badObj +Set badObj = CreateObject("No.Such.Object.XXXXXX") +Call ok(Err.Number = 429, "CreateObject bad ProgID: err.number = " & Err.Number) + +' Error 451: Object not a collection +Err.Clear +Dim forEachVar +For Each forEachVar In 42 +Next +Call ok(Err.Number = 451, "For Each over integer: err.number = " & Err.Number) + +' Error 457: Duplicate key in Dictionary +Err.Clear +Dim dictObj +Set dictObj = CreateObject("Scripting.Dictionary") +dictObj.Add "key1", 1 +dictObj.Add "key1", 2 +Call ok(Err.Number = 457, "duplicate Dictionary key: err.number = " & Err.Number) + +' Error 500: `New` with an undeclared identifier resolves the name as a +' variable first and fails with "Variable is undefined" before reaching +' class lookup. +Err.Clear +Dim undefinedNewTarget +Set undefinedNewTarget = New NoSuchClass +todo_wine_ok Err.Number = 500, "New undeclared identifier: err.number = " & Err.Number + +' Error 506: Class not defined. To reach the class lookup path, the +' identifier must be a declared variable that isn't a class. +Err.Clear +Dim notAClass +notAClass = 42 +Dim undefinedClassObj +Set undefinedClassObj = New notAClass +todo_wine_ok Err.Number = 506, "New non-class variable: err.number = " & Err.Number + +On Error GoTo 0 + reportSuccess() diff --git a/dlls/vbscript/vbscript.rc b/dlls/vbscript/vbscript.rc index f80635bd665..89d11e5a9e7 100644 --- a/dlls/vbscript/vbscript.rc +++ b/dlls/vbscript/vbscript.rc @@ -56,12 +56,14 @@ STRINGTABLE VBSE_PARAMETER_NOT_OPTIONAL "Argument not optional" VBSE_FUNC_ARITY_MISMATCH "Wrong number of arguments or invalid property assignment" VBSE_NOT_ENUM "Object not a collection" + VBSE_DUPLICATE_KEY "This key is already associated with an element of this collection" 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_ILLEGAL_ASSIGNMENT "Illegal assignment" VBSE_UNQUALIFIED_REFERENCE "Invalid or unqualified reference" + VBSE_CLASS_NOT_DEFINED "Class not defined" VBSE_SYNTAX_ERROR "Syntax error" VBSE_EXPECTED_LPAREN "Expected '('" VBSE_EXPECTED_RPAREN "Expected ')'" diff --git a/dlls/vbscript/vbscript_defs.h b/dlls/vbscript/vbscript_defs.h index 9cf9cce7ad9..bd81d9d69ff 100644 --- a/dlls/vbscript/vbscript_defs.h +++ b/dlls/vbscript/vbscript_defs.h @@ -267,12 +267,14 @@ #define VBSE_PARAMETER_NOT_OPTIONAL 449 #define VBSE_FUNC_ARITY_MISMATCH 450 #define VBSE_NOT_ENUM 451 +#define VBSE_DUPLICATE_KEY 457 #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_ILLEGAL_ASSIGNMENT 501 #define VBSE_UNQUALIFIED_REFERENCE 505 +#define VBSE_CLASS_NOT_DEFINED 506 #define VBSE_SYNTAX_ERROR 1002 #define VBSE_EXPECTED_LPAREN 1005 #define VBSE_EXPECTED_RPAREN 1006 -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10589
From: Francis De Brabandere <francisdb@gmail.com> When the class lookup in interp_new() fails, distinguish whether the name is otherwise unknown (return VBSE_VARIABLE_UNDEFINED, error 500) or resolves to an existing identifier that is not a class (return VBSE_CLASS_NOT_DEFINED, error 506), matching the behavior reported by the Windows VBScript runtime. --- dlls/vbscript/interp.c | 11 ++++++++--- dlls/vbscript/tests/lang.vbs | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 994da407169..34827eedf97 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -1255,7 +1255,7 @@ static HRESULT interp_deref(exec_ctx_t *ctx) static HRESULT interp_new(exec_ctx_t *ctx) { - const WCHAR *arg = ctx->instr->arg1.bstr; + BSTR arg = ctx->instr->arg1.bstr; class_desc_t *class_desc = NULL; vbdisp_t *obj; VARIANT v; @@ -1281,8 +1281,13 @@ static HRESULT interp_new(exec_ctx_t *ctx) if(!vbs_wcsicmp(class_desc->name, arg)) break; if(!class_desc) { - FIXME("Class %s not found\n", debugstr_w(arg)); - return E_FAIL; + ref_t ref; + + hres = lookup_identifier(ctx, arg, VBDISP_ANY, &ref); + if(FAILED(hres)) + return hres; + return MAKE_VBSERROR(ref.type == REF_NONE ? VBSE_VARIABLE_UNDEFINED + : VBSE_CLASS_NOT_DEFINED); } hres = create_vbdisp(class_desc, &obj); diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 27c43dd7c9f..fcaf946d5a5 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -3225,7 +3225,7 @@ Call ok(Err.Number = 457, "duplicate Dictionary key: err.number = " & Err.Number Err.Clear Dim undefinedNewTarget Set undefinedNewTarget = New NoSuchClass -todo_wine_ok Err.Number = 500, "New undeclared identifier: err.number = " & Err.Number +Call ok(Err.Number = 500, "New undeclared identifier: err.number = " & Err.Number) ' Error 506: Class not defined. To reach the class lookup path, the ' identifier must be a declared variable that isn't a class. @@ -3234,7 +3234,7 @@ Dim notAClass notAClass = 42 Dim undefinedClassObj Set undefinedClassObj = New notAClass -todo_wine_ok Err.Number = 506, "New non-class variable: err.number = " & Err.Number +Call ok(Err.Number = 506, "New non-class variable: err.number = " & Err.Number) On Error GoTo 0 -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10589
This merge request was approved by Jacek Caban. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10589
participants (3)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb) -
Jacek Caban (@jacek)