[PATCH] vbscript: Add UBound implementation
Piotr Caban <[email protected]> Mon, 6 Nov 2017 16:53:08 +0100
| Newsgroups | gmane.comp.emulators.wine.patches |
|---|---|
| Message-ID | <[email protected]> |
Signed-off-by: Piotr Caban <[email protected]> --- dlls/vbscript/global.c | 38 +++++++++++++++++++++++++++++++++++--- dlls/vbscript/tests/api.vbs | 10 ++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-)
0001-vbscript-Add-UBound-implementation.txt
(text/x-patch, 2.7 KB)
diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
index f523820b2a..a5df54acad 100644
--- a/dlls/vbscript/global.c
+++ b/dlls/vbscript/global.c
@@ -822,8 +822,40 @@ static HRESULT Global_LBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VA
static HRESULT Global_UBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{
- FIXME("\n");
- return E_NOTIMPL;
+ SAFEARRAY *sa;
+ HRESULT hres;
+ LONG ubound;
+ int dim;
+
+ assert(args_cnt == 1 || args_cnt == 2);
+
+ TRACE("%s %s\n", debugstr_variant(arg), args_cnt == 2 ? debugstr_variant(arg + 1) : "1");
+
+ switch(V_VT(arg)) {
+ case VT_VARIANT|VT_ARRAY:
+ sa = V_ARRAY(arg);
+ break;
+ case VT_VARIANT|VT_ARRAY|VT_BYREF:
+ sa = *V_ARRAYREF(arg);
+ break;
+ default:
+ FIXME("arg %s not supported\n", debugstr_variant(arg));
+ return E_NOTIMPL;
+ }
+
+ if(args_cnt == 2) {
+ hres = to_int(arg + 1, &dim);
+ if(FAILED(hres))
+ return hres;
+ }else {
+ dim = 1;
+ }
+
+ hres = SafeArrayGetUBound(sa, dim, &ubound);
+ if(FAILED(hres))
+ return hres;
+
+ return return_int(res, ubound);
}
static HRESULT Global_RGB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
@@ -2256,7 +2288,7 @@ static const builtin_prop_t global_props[] = {
{DISPID_GLOBAL_RND, Global_Rnd, 0, 1},
{DISPID_GLOBAL_TIMER, Global_Timer, 0, 0},
{DISPID_GLOBAL_LBOUND, Global_LBound, 0, 1},
- {DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1},
+ {DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1, 2},
{DISPID_GLOBAL_RGB, Global_RGB, 0, 3},
{DISPID_GLOBAL_LEN, Global_Len, 0, 1},
{DISPID_GLOBAL_LENB, Global_LenB, 0, 1},
diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs
index baa0553225..8ebbfb6c5c 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -227,6 +227,16 @@ new_array = x
x(0) = "new value"
Call ok(new_array(0) = "a1", "new_array(0) = " & new_array(0))
+Call ok(getVT(UBound(x)) = "VT_I4", "getVT(UBound(x)) = " & getVT(UBound(x)))
+Call ok(UBound(x) = 2, "UBound(x) = " & UBound(x))
+Call ok(getVT(UBound(x, 1)) = "VT_I4", "getVT(UBound(x, 1)) = " & getVT(UBound(x, 1)))
+Call ok(UBound(x, 1) = 2, "UBound(x) = " & UBound(x, 1))
+
+Dim arr2(2, 4)
+Call ok(UBound(arr2) = 2, "UBound(x) = " & UBound(x))
+Call ok(UBound(arr2, 1) = 2, "UBound(x) = " & UBound(x))
+Call ok(UBound(arr2, 2) = 4, "UBound(x) = " & UBound(x))
+
Dim newObject
Set newObject = New ValClass
newObject.myval = 1