|
17 | 17 |
|
18 | 18 | namespace Web::DOM {
|
19 | 19 |
|
| 20 | +// https://dom.spec.whatwg.org/#dom-parentnode-queryselector |
20 | 21 | WebIDL::ExceptionOr<JS::GCPtr<Element>> ParentNode::query_selector(StringView selector_text)
|
21 | 22 | {
|
| 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. |
22 | 29 | auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(*this), selector_text);
|
| 30 | + |
| 31 | + // 2. If s is failure, then throw a "SyntaxError" DOMException. |
23 | 32 | if (!maybe_selectors.has_value())
|
24 | 33 | return WebIDL::SyntaxError::create(realm(), "Failed to parse selector");
|
25 | 34 |
|
26 | 35 | auto selectors = maybe_selectors.value();
|
27 | 36 |
|
| 37 | + // 3. Return the result of match a selector against a tree with s and node’s root using scoping root node. |
28 | 38 | JS::GCPtr<Element> result;
|
29 | 39 | // FIXME: This should be shadow-including. https://drafts.csswg.org/selectors-4/#match-a-selector-against-a-tree
|
30 | 40 | for_each_in_subtree_of_type<Element>([&](auto& element) {
|
31 | 41 | for (auto& selector : selectors) {
|
32 |
| - if (SelectorEngine::matches(selector, element)) { |
| 42 | + if (SelectorEngine::matches(selector, element, {}, this)) { |
33 | 43 | result = &element;
|
34 | 44 | return IterationDecision::Break;
|
35 | 45 | }
|
|
0 commit comments