Jacek Caban : mshtml: Add IHTMLElement6::hasAttribute implementation.

Alexandre Julliard julliard at winehq.org
Fri Apr 23 15:20:18 CDT 2021


Module: wine
Branch: master
Commit: 696e8faaa914e2de645de8e9c79e025471f9f62a
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=696e8faaa914e2de645de8e9c79e025471f9f62a

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Apr 23 19:40:03 2021 +0200

mshtml: Add IHTMLElement6::hasAttribute implementation.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/htmlelem.c   | 25 ++++++++++++++++++++++---
 dlls/mshtml/tests/dom.js | 20 ++++++++++++++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c
index b71d7ed3fa5..ea6f7cd64c6 100644
--- a/dlls/mshtml/htmlelem.c
+++ b/dlls/mshtml/htmlelem.c
@@ -202,6 +202,22 @@ HRESULT elem_string_attr_setter(HTMLElement *elem, const WCHAR *name, const WCHA
     return S_OK;
 }
 
+static VARIANT_BOOL element_has_attribute(HTMLElement *element, const WCHAR *name)
+{
+    nsAString name_str;
+    cpp_bool r;
+    nsresult nsres;
+
+    if(!element->dom_element) {
+        WARN("no DOM element\n");
+        return VARIANT_FALSE;
+    }
+
+    nsAString_InitDepend(&name_str, name);
+    nsres = nsIDOMElement_HasAttribute(element->dom_element, &name_str, &r);
+    return variant_bool(NS_SUCCEEDED(nsres) && r);
+}
+
 HRESULT get_readystate_string(READYSTATE readystate, BSTR *p)
 {
     static const LPCWSTR readystate_strs[] = {
@@ -4453,11 +4469,14 @@ static HRESULT WINAPI HTMLElement6_removeAttributeNode(IHTMLElement6 *iface, IHT
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI HTMLElement6_hasAttribute(IHTMLElement6 *iface, BSTR name, VARIANT_BOOL *pfHasAttribute)
+static HRESULT WINAPI HTMLElement6_hasAttribute(IHTMLElement6 *iface, BSTR name, VARIANT_BOOL *p)
 {
     HTMLElement *This = impl_from_IHTMLElement6(iface);
-    FIXME("(%p)->(%s %p)\n", This, debugstr_w(name), pfHasAttribute);
-    return E_NOTIMPL;
+
+    TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), p);
+
+    *p = element_has_attribute(This, name);
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLElement6_getElementsByTagNameNS(IHTMLElement6 *iface, VARIANT *varNS, BSTR bstrLocalName, IHTMLElementCollection **pelColl)
diff --git a/dlls/mshtml/tests/dom.js b/dlls/mshtml/tests/dom.js
index f9d0873bb89..9edaf9befbc 100644
--- a/dlls/mshtml/tests/dom.js
+++ b/dlls/mshtml/tests/dom.js
@@ -468,3 +468,23 @@ sync_test("title", function() {
     ok(elem.title === "test", "div.title = " + elem.title);
     ok(elem.getAttribute("title") === "test", "title attribute = " + elem.getAttribute("title"));
 });
+
+sync_test("hasAttribute", function() {
+    document.body.innerHTML = '<div attr="test"></div>';
+    var elem = document.body.firstChild, r;
+
+    r = elem.hasAttribute("attr");
+    ok(r === true, "hasAttribute(attr) returned " + r);
+    r = elem.hasAttribute("attr2");
+    ok(r === false, "hasAttribute(attr2) returned " + r);
+
+    elem.setAttribute("attr2", "abc");
+    r = elem.hasAttribute("attr2");
+    todo_wine.
+    ok(r === true, "hasAttribute(attr2) returned " + r);
+
+    elem.removeAttribute("attr");
+    r = elem.hasAttribute("attr");
+    todo_wine.
+    ok(r === false, "hasAttribute(attr) returned " + r);
+});




More information about the wine-cvs mailing list