Bug 1494918 - FlattenAssignedNodes should check that slots are in shadow root , r=edgar
☠☠ backed out by 6237c17e8ac6 ☠ ☠
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Mon, 01 Oct 2018 19:11:12 +0300
changeset 487312 31863507b67034637f43ea3a75db362cf3538b85
parent 487311 3097e67f911488bc3b4e013b27a4aa584abe0e2e
child 487313 88ebd0e4c45e3759dbc7aac01b6e1848be254f10
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersedgar
bugs1494918
milestone64.0a1
Bug 1494918 - FlattenAssignedNodes should check that slots are in shadow root , r=edgar
dom/html/HTMLSlotElement.cpp
testing/web-platform/tests/shadow-dom/slots-outside-shadow-dom.html
--- a/dom/html/HTMLSlotElement.cpp
+++ b/dom/html/HTMLSlotElement.cpp
@@ -138,17 +138,18 @@ FlattenAssignedNodes(HTMLSlotElement* aS
       } else {
         aNodes.AppendElement(child);
       }
     }
     return;
   }
 
   for (const RefPtr<nsINode>& assignedNode : assignedNodes) {
-    if (auto* slot = HTMLSlotElement::FromNode(assignedNode)) {
+    auto* slot = HTMLSlotElement::FromNode(assignedNode);
+    if (slot && slot->GetContainingShadow()) {
       FlattenAssignedNodes(slot, aNodes);
     } else {
       aNodes.AppendElement(assignedNode);
     }
   }
 }
 
 void
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/shadow-dom/slots-outside-shadow-dom.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id="host1"><slot>foo</slot></div>
+<script>
+
+test(() => {
+  var host1 = document.getElementById("host1");
+  var sr = host1.attachShadow({mode: "open"});
+  sr.innerHTML = "<slot></slot>";
+  assert_array_equals(sr.firstChild.assignedNodes({ flatten: true }), [host1.firstChild]);
+}, "Light DOM slot element should be in flattened assignedNodes");
+
+</script>