summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
authorSimon Wanner <simon+git@skyrising.xyz>2023-03-20 23:48:59 +0100
committerAndreas Kling <kling@serenityos.org>2023-03-21 10:45:19 +0100
commit4e6fb65ea30181c17cee5598d8318e5ffedea8b4 (patch)
treea7e1987292ef0a2018d565853e737e92cd715db2 /Userland/Libraries/LibWeb/DOM
parentf3ba44a9f2fa6706c4872791b59bd493c450d334 (diff)
downloadserenity-4e6fb65ea30181c17cee5598d8318e5ffedea8b4.zip
LibWeb: Pass scope in ParentNode::query_selector
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r--Userland/Libraries/LibWeb/DOM/ParentNode.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
index 0cce06ddd6..1f4bbb9104 100644
--- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
+++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
@@ -17,19 +17,29 @@
namespace Web::DOM {
+// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
WebIDL::ExceptionOr<JS::GCPtr<Element>> ParentNode::query_selector(StringView selector_text)
{
+ // The querySelector(selectors) method steps are to return the first result of running scope-match a selectors string selectors against this,
+ // if the result is not an empty list; otherwise null.
+
+ // https://dom.spec.whatwg.org/#scope-match-a-selectors-string
+ // To scope-match a selectors string selectors against a node, run these steps:
+ // 1. Let s be the result of parse a selector selectors.
auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(*this), selector_text);
+
+ // 2. If s is failure, then throw a "SyntaxError" DOMException.
if (!maybe_selectors.has_value())
return WebIDL::SyntaxError::create(realm(), "Failed to parse selector");
auto selectors = maybe_selectors.value();
+ // 3. Return the result of match a selector against a tree with s and node’s root using scoping root node.
JS::GCPtr<Element> result;
// FIXME: This should be shadow-including. https://drafts.csswg.org/selectors-4/#match-a-selector-against-a-tree
for_each_in_subtree_of_type<Element>([&](auto& element) {
for (auto& selector : selectors) {
- if (SelectorEngine::matches(selector, element)) {
+ if (SelectorEngine::matches(selector, element, {}, this)) {
result = &element;
return IterationDecision::Break;
}