Skip to content

Commit 4e6fb65

Browse files
skyrisingawesomekling
authored andcommitted
LibWeb: Pass scope in ParentNode::query_selector
1 parent f3ba44a commit 4e6fb65

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Userland/Libraries/LibWeb/DOM/ParentNode.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,29 @@
1717

1818
namespace Web::DOM {
1919

20+
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
2021
WebIDL::ExceptionOr<JS::GCPtr<Element>> ParentNode::query_selector(StringView selector_text)
2122
{
23+
// The querySelector(selectors) method steps are to return the first result of running scope-match a selectors string selectors against this,
24+
// if the result is not an empty list; otherwise null.
25+
26+
// https://dom.spec.whatwg.org/#scope-match-a-selectors-string
27+
// To scope-match a selectors string selectors against a node, run these steps:
28+
// 1. Let s be the result of parse a selector selectors.
2229
auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(*this), selector_text);
30+
31+
// 2. If s is failure, then throw a "SyntaxError" DOMException.
2332
if (!maybe_selectors.has_value())
2433
return WebIDL::SyntaxError::create(realm(), "Failed to parse selector");
2534

2635
auto selectors = maybe_selectors.value();
2736

37+
// 3. Return the result of match a selector against a tree with s and node’s root using scoping root node.
2838
JS::GCPtr<Element> result;
2939
// FIXME: This should be shadow-including. https://drafts.csswg.org/selectors-4/#match-a-selector-against-a-tree
3040
for_each_in_subtree_of_type<Element>([&](auto& element) {
3141
for (auto& selector : selectors) {
32-
if (SelectorEngine::matches(selector, element)) {
42+
if (SelectorEngine::matches(selector, element, {}, this)) {
3343
result = &element;
3444
return IterationDecision::Break;
3545
}

0 commit comments

Comments
 (0)