From 59f7fbeeb01ac75ad723ffedf6e071f60baf3738 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gabriel=20Iv=C4=83ncescu?= Date: Fri, 26 May 2023 17:04:38 +0300 Subject: [PATCH] mshtml: Implement classList's contains() method. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel Ivăncescu --- dlls/mshtml/htmlelem.c | 20 ++++++++++++++++++-- dlls/mshtml/tests/dom.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c index 42572637238..13941e98ee8 100644 --- a/dlls/mshtml/htmlelem.c +++ b/dlls/mshtml/htmlelem.c @@ -7573,10 +7573,26 @@ static HRESULT WINAPI token_list_toggle(IWineDOMTokenList *iface, BSTR token, VA static HRESULT WINAPI token_list_contains(IWineDOMTokenList *iface, BSTR token, VARIANT_BOOL *p) { struct token_list *token_list = impl_from_IWineDOMTokenList(iface); + unsigned len; + HRESULT hres; + BSTR list; - FIXME("(%p)->(%s %p)\n", token_list, debugstr_w(token), p); + TRACE("(%p)->(%s %p)\n", token_list, debugstr_w(token), p); - return E_NOTIMPL; + if(!token || !*token) + return E_INVALIDARG; + + for(len = 0; token[len]; len++) + if(iswspace(token[len])) + return E_INVALIDARG; + + hres = IHTMLElement_get_className(token_list->element, &list); + if(FAILED(hres)) + return hres; + + *p = find_token(list, token, len) ? VARIANT_TRUE : VARIANT_FALSE; + SysFreeString(list); + return S_OK; } static HRESULT WINAPI token_list_get_length(IWineDOMTokenList *iface, LONG *p) diff --git a/dlls/mshtml/tests/dom.js b/dlls/mshtml/tests/dom.js index 85890074431..8f43b924a88 100644 --- a/dlls/mshtml/tests/dom.js +++ b/dlls/mshtml/tests/dom.js @@ -685,6 +685,43 @@ sync_test("classList", function() { } ok(exception, "Expected exception for classList.add(\"e f\")"); + exception = false; + try + { + classList.contains(); + } + catch(e) + { + exception = true; + } + ok(exception, "Expected exception for classList.contains()"); + + exception = false; + try + { + classList.contains(""); + } + catch(e) + { + exception = true; + } + ok(exception, "Expected exception for classList.contains(\"\")"); + + exception = false; + try + { + classList.contains("a b"); + } + catch(e) + { + exception = true; + } + ok(exception, "Expected exception for classList.contains(\"a b\")"); + + ok(classList.contains("4") === true, "contains: expected '4' to return true"); + ok(classList.contains("b") === true, "contains: expected 'b' to return true"); + ok(classList.contains("d") === false, "contains: expected 'd' to return false"); + classList.remove("e"); ok(elem.className === "a b c 4", "remove: expected className 'a b c 4', got " + elem.className); -- 2.11.4.GIT