[PATCH v4 4/4] mshtml: Add console object stub implementation.

Paul Gofman pgofman at codeweavers.com
Wed Jul 7 19:34:22 CDT 2021


Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
v4:
    - move console class to omnavigator.c instead of a new file;
    - use actual compat mode for console creation (and delay console creation until the first query);
    - add test to ocumentmode.js (window_props).


 dlls/mshtml/htmlwindow.c             |  19 ++
 dlls/mshtml/mshtml_private.h         |   6 +-
 dlls/mshtml/mshtml_private_iface.idl |  46 +++++
 dlls/mshtml/omnavigator.c            | 258 +++++++++++++++++++++++++++
 dlls/mshtml/tests/documentmode.js    |   1 +
 dlls/mshtml/tests/es5.js             |  64 +++++++
 6 files changed, 393 insertions(+), 1 deletion(-)

diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c
index dce329d9ec6..870d7e8f100 100644
--- a/dlls/mshtml/htmlwindow.c
+++ b/dlls/mshtml/htmlwindow.c
@@ -316,6 +316,9 @@ static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface)
     TRACE("(%p) ref=%d\n", This, ref);
 
     if(!ref) {
+        if (This->console)
+            IWineMSHTMLConsole_Release(This->console);
+
         if(is_outer_window(This))
             release_outer_window(This->outer_window);
         else
@@ -3115,6 +3118,21 @@ static HRESULT WINAPI window_private_requestAnimationFrame(IWineHTMLWindowPrivat
     return hres;
 }
 
+static HRESULT WINAPI window_private_get_console(IWineHTMLWindowPrivate *iface, IDispatch **console)
+{
+    HTMLWindow *This = impl_from_IWineHTMLWindowPrivateVtbl(iface);
+
+    TRACE("iface %p, console %p.\n", iface, console);
+
+    if (!This->console)
+        create_console(dispex_compat_mode(&This->inner_window->event_target.dispex), &This->console);
+
+    *console = (IDispatch *)This->console;
+    if (This->console)
+        IWineMSHTMLConsole_AddRef(This->console);
+    return S_OK;
+}
+
 static const IWineHTMLWindowPrivateVtbl WineHTMLWindowPrivateVtbl = {
     window_private_QueryInterface,
     window_private_AddRef,
@@ -3124,6 +3142,7 @@ static const IWineHTMLWindowPrivateVtbl WineHTMLWindowPrivateVtbl = {
     window_private_GetIDsOfNames,
     window_private_Invoke,
     window_private_requestAnimationFrame,
+    window_private_get_console,
 };
 
 static inline HTMLWindow *impl_from_IDispatchEx(IDispatchEx *iface)
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 08b4df86e31..e2c1f221372 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -273,7 +273,8 @@ typedef struct EventTarget EventTarget;
     XIID(ISVGTextContentElement)
 
 #define PRIVATE_TID_LIST \
-    XIID(IWineHTMLWindowPrivate)
+    XIID(IWineHTMLWindowPrivate) \
+    XIID(IWineMSHTMLConsole)
 
 typedef enum {
 #define XIID(iface) iface ## _tid,
@@ -492,6 +493,8 @@ struct HTMLWindow {
     IProvideMultipleClassInfo IProvideMultipleClassInfo_iface;
     IWineHTMLWindowPrivate IWineHTMLWindowPrivate_iface;
 
+    IWineMSHTMLConsole *console;
+
     LONG ref;
 
     HTMLInnerWindow *inner_window;
@@ -1407,3 +1410,4 @@ void set_statustext(HTMLDocumentObj*,INT,LPCWSTR) DECLSPEC_HIDDEN;
 IInternetSecurityManager *get_security_manager(void) DECLSPEC_HIDDEN;
 
 extern HINSTANCE hInst DECLSPEC_HIDDEN;
+void create_console(compat_mode_t compat_mode, IWineMSHTMLConsole **ret) DECLSPEC_HIDDEN;
diff --git a/dlls/mshtml/mshtml_private_iface.idl b/dlls/mshtml/mshtml_private_iface.idl
index c147b2445dc..6c5c5db991f 100644
--- a/dlls/mshtml/mshtml_private_iface.idl
+++ b/dlls/mshtml/mshtml_private_iface.idl
@@ -30,6 +30,50 @@ library MSHTML_private
 
 importlib("stdole2.tlb");
 
+[
+    odl,
+    oleautomation,
+    dual,
+    hidden,
+    uuid(fd55b4b6-2813-4fb4-829d-380099474ab1)
+]
+interface IWineMSHTMLConsole : IDispatch
+{
+    [id(1)]
+    HRESULT assert([in] VARIANT_BOOL *assertion,
+                   [in, optional] VARIANT *varargStart);
+    [id(2)]
+    HRESULT clear();
+    [id(3)]
+    HRESULT count([in, optional] VARIANT *label);
+    [id(4)]
+    HRESULT debug([in, optional] VARIANT *varargStart);
+    [id(5)]
+    HRESULT dir([in, optional] VARIANT *object);
+    [id(6)]
+    HRESULT dirxml([in, optional] VARIANT *object);
+    [id(7)]
+    HRESULT error([in, optional] VARIANT *varargStart);
+    [id(8)]
+    HRESULT group([in, optional] VARIANT *label);
+    [id(9)]
+    HRESULT groupCollapsed([in, optional] VARIANT *label);
+    [id(10)]
+    HRESULT groupEnd();
+    [id(11)]
+    HRESULT info([in, optional] VARIANT *varargStart);
+    [id(12)]
+    HRESULT log([in, optional] VARIANT *varargStart);
+    [id(13)]
+    HRESULT time([in, optional] VARIANT *label);
+    [id(14)]
+    HRESULT timeEnd([in, optional] VARIANT *label);
+    [id(15)]
+    HRESULT trace([in, optional] VARIANT *varargStart);
+    [id(16)]
+    HRESULT warn([in, optional] VARIANT *varargStart);
+}
+
 [
     odl,
     oleautomation,
@@ -41,6 +85,8 @@ interface IWineHTMLWindowPrivate : IDispatch
 {
     [id(1)]
     HRESULT requestAnimationFrame([in] VARIANT *expr, [retval, out] VARIANT *timer_id);
+    [propget, id(2)]
+    HRESULT console([retval, out] IDispatch **console);
 }
 
 } /* library MSHTML_private */
diff --git a/dlls/mshtml/omnavigator.c b/dlls/mshtml/omnavigator.c
index a8f829b6a57..eff9576a955 100644
--- a/dlls/mshtml/omnavigator.c
+++ b/dlls/mshtml/omnavigator.c
@@ -2365,3 +2365,261 @@ HRESULT create_namespace_collection(compat_mode_t compat_mode, IHTMLNamespaceCol
     *ret = &namespaces->IHTMLNamespaceCollection_iface;
     return S_OK;
 }
+
+struct console {
+    DispatchEx dispex;
+    IWineMSHTMLConsole IWineMSHTMLConsole_iface;
+    LONG ref;
+};
+
+static inline struct console *impl_from_IWineMSHTMLConsole(IWineMSHTMLConsole *iface)
+{
+    return CONTAINING_RECORD(iface, struct console, IWineMSHTMLConsole_iface);
+}
+
+static HRESULT WINAPI console_QueryInterface(IWineMSHTMLConsole *iface, REFIID riid, void **ppv)
+{
+    struct console *console = impl_from_IWineMSHTMLConsole(iface);
+
+    TRACE("(%p)->(%s %p)\n", console, debugstr_mshtml_guid(riid), ppv);
+
+    if(IsEqualGUID(&IID_IUnknown, riid)) {
+        *ppv = &console->IWineMSHTMLConsole_iface;
+    }else if(IsEqualGUID(&IID_IWineMSHTMLConsole, riid)) {
+        *ppv = &console->IWineMSHTMLConsole_iface;
+    }else if(dispex_query_interface(&console->dispex, riid, ppv)) {
+        return *ppv ? S_OK : E_NOINTERFACE;
+    }else {
+        WARN("(%p)->(%s %p)\n", console, debugstr_mshtml_guid(riid), ppv);
+        *ppv = NULL;
+        return E_NOINTERFACE;
+    }
+
+    IUnknown_AddRef((IUnknown*)*ppv);
+    return S_OK;
+}
+
+static ULONG WINAPI console_AddRef(IWineMSHTMLConsole *iface)
+{
+    struct console *console = impl_from_IWineMSHTMLConsole(iface);
+    LONG ref = InterlockedIncrement(&console->ref);
+
+    TRACE("(%p) ref=%d\n", console, ref);
+
+    return ref;
+}
+
+static ULONG WINAPI console_Release(IWineMSHTMLConsole *iface)
+{
+    struct console *console = impl_from_IWineMSHTMLConsole(iface);
+    LONG ref = InterlockedDecrement(&console->ref);
+
+    TRACE("(%p) ref=%d\n", console, ref);
+
+    if(!ref) {
+        release_dispex(&console->dispex);
+        heap_free(console);
+    }
+
+    return ref;
+}
+
+static HRESULT WINAPI console_GetTypeInfoCount(IWineMSHTMLConsole *iface, UINT *pctinfo)
+{
+    struct console *console = impl_from_IWineMSHTMLConsole(iface);
+    FIXME("(%p)->(%p)\n", console, pctinfo);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI console_GetTypeInfo(IWineMSHTMLConsole *iface, UINT iTInfo,
+        LCID lcid, ITypeInfo **ppTInfo)
+{
+    struct console *console = impl_from_IWineMSHTMLConsole(iface);
+
+    return IDispatchEx_GetTypeInfo(&console->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
+}
+
+static HRESULT WINAPI console_GetIDsOfNames(IWineMSHTMLConsole *iface, REFIID riid,
+        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
+{
+    struct console *console = impl_from_IWineMSHTMLConsole(iface);
+
+    return IDispatchEx_GetIDsOfNames(&console->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
+            lcid, rgDispId);
+}
+
+static HRESULT WINAPI console_Invoke(IWineMSHTMLConsole *iface, DISPID dispIdMember,
+        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
+        VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+{
+    struct console *console = impl_from_IWineMSHTMLConsole(iface);
+
+    return IDispatchEx_Invoke(&console->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
+            pDispParams, pVarResult, pExcepInfo, puArgErr);
+}
+
+static HRESULT WINAPI console_assert(IWineMSHTMLConsole *iface, VARIANT_BOOL *assertion, VARIANT *vararg_start)
+{
+    FIXME("iface %p, assertion %p, vararg_start %p stub.\n", iface, assertion, vararg_start);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_clear(IWineMSHTMLConsole *iface)
+{
+    FIXME("iface %p stub.\n", iface);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_count(IWineMSHTMLConsole *iface, VARIANT *label)
+{
+    FIXME("iface %p, label %p stub.\n", iface, label);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_debug(IWineMSHTMLConsole *iface, VARIANT *vararg_start)
+{
+    FIXME("iface %p, vararg_start %p stub.\n", iface, vararg_start);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_dir(IWineMSHTMLConsole *iface, VARIANT *object)
+{
+    FIXME("iface %p, object %p stub.\n", iface, object);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_dirxml(IWineMSHTMLConsole *iface, VARIANT *object)
+{
+    FIXME("iface %p, object %p stub.\n", iface, object);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_error(IWineMSHTMLConsole *iface, VARIANT *vararg_start)
+{
+    FIXME("iface %p, vararg_start %p stub.\n", iface, vararg_start);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_group(IWineMSHTMLConsole *iface, VARIANT *label)
+{
+    FIXME("iface %p, label %p stub.\n", iface, label);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_group_collapsed(IWineMSHTMLConsole *iface, VARIANT *label)
+{
+    FIXME("iface %p, label %p stub.\n", iface, label);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_group_end(IWineMSHTMLConsole *iface)
+{
+    FIXME("iface %p, stub.\n", iface);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_info(IWineMSHTMLConsole *iface, VARIANT *vararg_start)
+{
+    FIXME("iface %p, vararg_start %p stub.\n", iface, vararg_start);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_log(IWineMSHTMLConsole *iface, VARIANT *vararg_start)
+{
+    FIXME("iface %p, vararg_start %p stub.\n", iface, vararg_start);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_time(IWineMSHTMLConsole *iface, VARIANT *label)
+{
+    FIXME("iface %p, label %p stub.\n", iface, label);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_time_end(IWineMSHTMLConsole *iface, VARIANT *label)
+{
+    FIXME("iface %p, label %p stub.\n", iface, label);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_trace(IWineMSHTMLConsole *iface, VARIANT *vararg_start)
+{
+    FIXME("iface %p, vararg_start %p stub.\n", iface, vararg_start);
+
+    return S_OK;
+}
+
+static HRESULT WINAPI console_warn(IWineMSHTMLConsole *iface, VARIANT *vararg_start)
+{
+    FIXME("iface %p, vararg_start %p stub.\n", iface, vararg_start);
+
+    return S_OK;
+}
+
+static const IWineMSHTMLConsoleVtbl WineMSHTMLConsoleVtbl = {
+    console_QueryInterface,
+    console_AddRef,
+    console_Release,
+    console_GetTypeInfoCount,
+    console_GetTypeInfo,
+    console_GetIDsOfNames,
+    console_Invoke,
+    console_assert,
+    console_clear,
+    console_count,
+    console_debug,
+    console_dir,
+    console_dirxml,
+    console_error,
+    console_group,
+    console_group_collapsed,
+    console_group_end,
+    console_info,
+    console_log,
+    console_time,
+    console_time_end,
+    console_trace,
+    console_warn,
+};
+
+static const tid_t console_iface_tids[] = {
+    IWineMSHTMLConsole_tid,
+    0
+};
+static dispex_static_data_t console_dispex = {
+    NULL,
+    IWineMSHTMLConsole_tid,
+    console_iface_tids
+};
+
+void create_console(compat_mode_t compat_mode, IWineMSHTMLConsole **ret)
+{
+    struct console *obj;
+
+    obj = heap_alloc_zero(sizeof(*obj));
+    if(!obj)
+    {
+        ERR("No memory.\n");
+        return;
+    }
+
+    obj->IWineMSHTMLConsole_iface.lpVtbl = &WineMSHTMLConsoleVtbl;
+    obj->ref = 1;
+    init_dispatch(&obj->dispex, (IUnknown*)&obj->IWineMSHTMLConsole_iface, &console_dispex, compat_mode);
+
+    *ret = &obj->IWineMSHTMLConsole_iface;
+}
diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js
index 26aa451db0b..859e1fe53db 100644
--- a/dlls/mshtml/tests/documentmode.js
+++ b/dlls/mshtml/tests/documentmode.js
@@ -121,6 +121,7 @@ sync_test("window_props", function() {
     test_exposed("Set", v >= 11);
     if(v >= 9) /* FIXME: native exposes it in all compat modes */
         test_exposed("performance", true);
+    test_exposed("console", v >= 10);
 });
 
 sync_test("xhr_props", function() {
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index a520253569c..e57aed5ca35 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -1448,3 +1448,67 @@ sync_test("functions scope", function() {
     ok(val == 8, "val != 8");
     ok(w == 9, "w != 9");
 });
+
+sync_test("console", function() {
+    var except
+
+    window.console.log('1', '2');
+    console.info('1', '2', '3');
+    console.info();
+    console.log();
+    console.trace();
+    console.warn();
+    console.debug();
+    console.error();
+
+    console.assert(false, '1');
+    console.assert(true, '1');
+    console.assert('1');
+
+    console.clear();
+    console.count('1');
+    console.count(1);
+
+
+    except = false;
+    try
+    {
+        console.countReset('1');
+    }
+    catch(e)
+    {
+        except = true;
+    }
+    ok(except, "console.countReset: expected exception");
+    console.dir(document);
+    console.dir();
+    console.dirxml(document);
+    console.group('1');
+    console.groupCollapsed('1');
+    console.groupEnd();
+
+    except = false;
+    try
+    {
+        console.table(['1', '2']);
+    }
+    catch(e)
+    {
+        except = true;
+    }
+    ok(except, "console.table: expected exception");
+
+    console.time('1');
+    console.timeEnd('1');
+
+    except = false;
+    try
+    {
+        console.timeLog('1');
+    }
+    catch(e)
+    {
+        except = true;
+    }
+    ok(except, "console.timeLog: expected exception");
+});
-- 
2.31.1




More information about the wine-devel mailing list