From d55373067d16fef61d4702dbcb78f266a8134cfc Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Mon, 20 Mar 2023 23:45:12 +0100 Subject: [PATCH] LibWeb: Pass scope in Element::matches --- Userland/Libraries/LibWeb/DOM/Element.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 7b947883b5..83c3ce79c2 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -532,13 +532,17 @@ JS::GCPtr Element::shadow_root() const // https://dom.spec.whatwg.org/#dom-element-matches WebIDL::ExceptionOr Element::matches(StringView selectors) const { + // 1. Let s be the result of parse a selector from selectors. auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(static_cast(const_cast(*this))), selectors); + + // 2. If s is failure, then throw a "SyntaxError" DOMException. if (!maybe_selectors.has_value()) return WebIDL::SyntaxError::create(realm(), "Failed to parse selector"); + // 3. If the result of match a selector against an element, using s, this, and scoping root this, returns success, then return true; otherwise, return false. auto sel = maybe_selectors.value(); for (auto& s : sel) { - if (SelectorEngine::matches(s, *this)) + if (SelectorEngine::matches(s, *this, {}, static_cast(this))) return true; } return false;