summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-01-20 21:33:16 +0000
committerLinus Groh <mail@linusgroh.de>2022-01-20 22:18:07 +0000
commit5ac57db5e9909b3e4371e7785d0bfe4945194d94 (patch)
tree7afa25d339ec2c1fe99c0cd39389147306b38764 /Userland
parent29cb7316d06b2f5dc0de802805f88fcec81c4a25 (diff)
downloadserenity-5ac57db5e9909b3e4371e7785d0bfe4945194d94.zip
LibWeb: Don't match the node querySelector(All) was called on
In querySelector(All)'s use of "Match a Selector Against a Tree", it passes in the node the function was called on as the "optional scoping root", which causes it and the nodes which aren't descendants of it to be excluded from the list of possible nodes to match against. For us, this is the equivalent of using the non-inclusive variant of `for_each_in_subtree_of_type`. This was tripping up the node re-ordering logic of d3 and would cause it to try and reinsert nodes into their parent, causing an exception to be thrown. Note that this should be shadow-including, but we don't currently have shadow-including tree traversal as per https://dom.spec.whatwg.org/#concept-shadow-including-tree-order https://drafts.csswg.org/selectors-4/#match-a-selector-against-a-tree https://dom.spec.whatwg.org/#scope-match-a-selectors-string
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/DOM/ParentNode.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
index e924c5320f..eee4fc3100 100644
--- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
+++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp
@@ -23,7 +23,8 @@ ExceptionOr<RefPtr<Element>> ParentNode::query_selector(StringView selector_text
auto selectors = maybe_selectors.value();
RefPtr<Element> result;
- for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
+ // 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)) {
result = element;
@@ -45,7 +46,8 @@ ExceptionOr<NonnullRefPtr<NodeList>> ParentNode::query_selector_all(StringView s
auto selectors = maybe_selectors.value();
NonnullRefPtrVector<Node> elements;
- for_each_in_inclusive_subtree_of_type<Element>([&](auto& element) {
+ // 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)) {
elements.append(element);