This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 21166 - [Shadow]: The olderShadowRoot property should be defined on ShadowRoot
Summary: [Shadow]: The olderShadowRoot property should be defined on ShadowRoot
Status: RESOLVED DUPLICATE of bug 20260
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 14978
  Show dependency treegraph
 
Reported: 2013-03-01 21:05 UTC by Dominic Cooney
Modified: 2013-03-01 21:51 UTC (History)
0 users

See Also:


Attachments

Description Dominic Cooney 2013-03-01 21:05:41 UTC
Defining olderShadowRoot on HTMLShadowElement is inconvenient for code that wants to walk the list of ShadowRoots. It is necessary to write something like:

function forEachShadowRoot(host, f) {
  for (var s = host.shadowRoot; s; s = olderShadowRootOf(s)) {
    f(s);
  }
}

function olderShadowRootOf(s) {
  var shadowElements = s.querySelectorAll('shadow');
  for (var i = 0; i < shadowElements.length; i++) {
    var shadowElement = shadowElements[i];
    if (shadowElement.olderShadowRoot) {
      return shadowElement.olderShadowRoot;
    }
  }
  // There were no shadow elements, or they were all inert
  shadowElement = document.createElement('shadow');
  s.appendChild(shadowElement);
  var result = shadowElement.olderShadowRoot;
  shadowElement.remove();
  return result;
}

This seems excessively complicated for this use case; it would be better if olderShadowRoot was defined on ShadowRoot, then one could simply write the loop in a straightforward way:

function forEachShadowRoot(host, f) {
  for (var s = host.shadowRoot; s; s = s.olderShadowRoot) {
    f(s);
  }
}
Comment 1 Dominic Cooney 2013-03-01 21:51:15 UTC

*** This bug has been marked as a duplicate of bug 20260 ***