[PATCH v5 03/10] msscript.ocx: Implement IScriptModuleCollection::get_Item.

Gabriel Ivăncescu gabrielopcode at gmail.com
Fri Jun 19 07:53:32 CDT 2020


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/msscript.ocx/msscript.c       | 39 ++++++++++++++++++++++++++++--
 dlls/msscript.ocx/tests/msscript.c | 36 ++++++++++++++++++++++-----
 2 files changed, 67 insertions(+), 8 deletions(-)

diff --git a/dlls/msscript.ocx/msscript.c b/dlls/msscript.ocx/msscript.c
index 3d65067..9a0cbcd 100644
--- a/dlls/msscript.ocx/msscript.c
+++ b/dlls/msscript.ocx/msscript.c
@@ -795,6 +795,17 @@ static void release_modules(ScriptHost *host, BOOL force_detach)
     heap_free(modules);
 }
 
+static ScriptModule *find_module(ScriptHost *host, BSTR name)
+{
+    unsigned int len = SysStringLen(name);
+
+    if (len == sizeof("Global") - 1 && !wcsicmp(name, L"Global"))
+        return host->modules[0];
+
+    /* FIXME: Look for other modules when they can be added */
+    return NULL;
+}
+
 static HRESULT WINAPI ScriptModuleCollection_QueryInterface(IScriptModuleCollection *iface, REFIID riid, void **ppv)
 {
     ScriptControl *This = impl_from_IScriptModuleCollection(iface);
@@ -901,10 +912,34 @@ static HRESULT WINAPI ScriptModuleCollection_get_Item(IScriptModuleCollection *i
         IScriptModule **ppmod)
 {
     ScriptControl *This = impl_from_IScriptModuleCollection(iface);
+    ScriptModule *module;
+    unsigned int i;
+    HRESULT hr;
 
-    FIXME("(%p)->(%s %p)\n", This, wine_dbgstr_variant(&index), ppmod);
+    TRACE("(%p)->(%s %p)\n", This, wine_dbgstr_variant(&index), ppmod);
 
-    return E_NOTIMPL;
+    if (!ppmod) return E_POINTER;
+    if (!This->host) return E_FAIL;
+
+    if (V_VT(&index) == VT_BSTR)
+    {
+        module = find_module(This->host, V_BSTR(&index));
+        if (!module) return CTL_E_ILLEGALFUNCTIONCALL;
+    }
+    else
+    {
+        hr = VariantChangeType(&index, &index, 0, VT_INT);
+        if (FAILED(hr)) return hr;
+
+        i = V_INT(&index) - 1;
+        if (i >= This->host->module_count) return 0x800a0009;
+
+        module = This->host->modules[i];
+    }
+
+    *ppmod = &module->IScriptModule_iface;
+    IScriptModule_AddRef(*ppmod);
+    return S_OK;
 }
 
 static HRESULT WINAPI ScriptModuleCollection_get_Count(IScriptModuleCollection *iface, LONG *plCount)
diff --git a/dlls/msscript.ocx/tests/msscript.c b/dlls/msscript.ocx/tests/msscript.c
index b6a5209..9ffb957 100644
--- a/dlls/msscript.ocx/tests/msscript.c
+++ b/dlls/msscript.ocx/tests/msscript.c
@@ -2340,9 +2340,9 @@ static void test_IScriptControl_get_Modules(void)
     V_VT(&var) = VT_I4;
     V_I4(&var) = -1;
     hr = IScriptModuleCollection_get_Item(mods, var, NULL);
-    todo_wine ok(hr == E_POINTER, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
+    ok(hr == E_POINTER, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
     hr = IScriptModuleCollection_get_Item(mods, var, &mod);
-    todo_wine ok(hr == 0x800a0009, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
+    ok(hr == 0x800a0009, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
 
     V_VT(&var) = VT_EMPTY;
     str = SysAllocString(L"foobar");
@@ -2377,19 +2377,28 @@ static void test_IScriptControl_get_Modules(void)
     V_VT(&var) = VT_I4;
     V_I4(&var) = count + 1;
     hr = IScriptModuleCollection_get_Item(mods, var, &mod);
-    todo_wine ok(hr == 0x800a0009, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
+    ok(hr == 0x800a0009, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
     V_VT(&var) = VT_BSTR;
     V_BSTR(&var) = SysAllocString(L"non-existent module");
     hr = IScriptModuleCollection_get_Item(mods, var, &mod);
-    todo_wine ok(hr == CTL_E_ILLEGALFUNCTIONCALL, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
+    ok(hr == CTL_E_ILLEGALFUNCTIONCALL, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
     ok(V_VT(&var) == VT_BSTR, "var type not BSTR, got %d.\n", V_VT(&var));
     VariantClear(&var);
 
     V_VT(&var) = VT_I4;
     V_I4(&var) = 1;
     hr = IScriptModuleCollection_get_Item(mods, var, &mod);
-    todo_wine ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
-    if (hr == S_OK) IScriptModule_Release(mod);
+    ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
+    hr = IScriptModule_get_Name(mod, NULL);
+    todo_wine ok(hr == E_POINTER, "IScriptModule_get_Name returned: 0x%08x.\n", hr);
+    hr = IScriptModule_get_Name(mod, &str);
+    todo_wine ok(hr == S_OK, "IScriptModule_get_Name failed: 0x%08x.\n", hr);
+    if (hr == S_OK) SysFreeString(str);
+    str = SysAllocString(L"function add(a, b) { return a + b; }\n");
+    hr = IScriptModule_AddCode(mod, str);
+    todo_wine ok(hr == S_OK, "IScriptModule_AddCode failed: 0x%08x.\n", hr);
+    IScriptModule_Release(mod);
+    SysFreeString(str);
 
     V_VT(&var) = VT_BSTR;
     V_BSTR(&var) = SysAllocString(L"some other module");
@@ -2405,6 +2414,17 @@ static void test_IScriptControl_get_Modules(void)
     todo_wine ok(hr == S_OK, "IScriptModuleCollection_get_Item failed: 0x%08x.\n", hr);
     if (hr == S_OK) IScriptModule_Release(mod);
 
+    /* The 'Global' module is the same as the script control */
+    str = SysAllocString(L"add(10, 5)");
+    hr = IScriptControl_Eval(sc, str, &var);
+    todo_wine ok(hr == S_OK, "IScriptControl_Eval failed: 0x%08x.\n", hr);
+    todo_wine ok(V_VT(&var) == VT_I4 && V_I4(&var) == 15, "V_VT(var) = %d, V_I4(var) = %d.\n", V_VT(&var), V_I4(&var));
+    SysFreeString(str);
+    str = SysAllocString(L"sub(10, 5)");
+    hr = IScriptControl_Eval(sc, str, &var);
+    ok(FAILED(hr), "IScriptControl_Eval succeeded: 0x%08x.\n", hr);
+    SysFreeString(str);
+
     str = SysAllocString(L"vbscript");
     hr = IScriptControl_put_Language(sc, str);
     ok(hr == S_OK, "IScriptControl_put_Language failed: 0x%08x.\n", hr);
@@ -2419,6 +2439,10 @@ static void test_IScriptControl_get_Modules(void)
 
     hr = IScriptModuleCollection_get_Count(mods, &count);
     ok(hr == E_FAIL, "IScriptModuleCollection_get_Count returned: 0x%08x.\n", hr);
+    V_VT(&var) = VT_I4;
+    V_I4(&var) = 1;
+    hr = IScriptModuleCollection_get_Item(mods, var, &mod);
+    ok(hr == E_FAIL, "IScriptModuleCollection_get_Item returned: 0x%08x.\n", hr);
 
     IScriptModuleCollection_Release(mods);
     hr = IScriptControl_get_Modules(sc, &mods);
-- 
2.21.0




More information about the wine-devel mailing list