From dd2e51de9985a1c9d381607c2b314b6562545d37 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 10 Apr 2024 08:31:31 +0200 Subject: [PATCH] Remove getHTML() shouldn't branch on shadow root's mode As with clonable and delegatesFocus, serializable is an explicit API and therefore fine from an encapsulation point of view. For https://github.com/whatwg/html/pull/10260. --- shadow-dom/declarative/gethtml.html | 31 +++++++++-------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/shadow-dom/declarative/gethtml.html b/shadow-dom/declarative/gethtml.html index d950ca7734ea1f..ff70653477f6a9 100644 --- a/shadow-dom/declarative/gethtml.html +++ b/shadow-dom/declarative/gethtml.html @@ -29,7 +29,6 @@ } let shadowRoot; - const isOpen = mode === 'open'; let initDict = {mode: mode, delegatesFocus: delegatesFocus, clonable}; let expectedSerializable = null; switch (serializable) { @@ -47,12 +46,8 @@ `shadowrootmode=${mode}${delegatesAttr}${serializableAttr}` + `${clonableAttr}>`; wrapper.setHTMLUnsafe(html); - if (isOpen) { - shadowRoot = wrapper.firstElementChild.shadowRoot; - } else { - // For closed shadow root, we rely on the behavior of attachShadow to return it to us - shadowRoot = wrapper.firstElementChild.attachShadow(initDict); - } + // Get hold of the declarative shadow root in a way that works when its mode is "closed" + shadowRoot = wrapper.firstElementChild.attachShadow(initDict); } else { // Imperative shadow dom const element = document.createElement(elementType); @@ -78,22 +73,14 @@ assert_equals(shadowRoot.clonable,clonable); shadowRoot.appendChild(document.createElement('slot')); const emptyElement = `<${elementType}>${lightDOMContent}`; - if (isOpen) { - if (expectedSerializable) { - assert_equals(wrapper.getHTML({serializableShadowRoots: true}), - correctHtml); - assert_equals(wrapper.firstElementChild.getHTML({ - serializableShadowRoots: true}), - `${correctShadowHtml}${lightDOMContent}`); - } else { - assert_equals(wrapper.getHTML({serializableShadowRoots: true}), emptyElement); - } - } else { - // Closed shadow roots should not be returned unless shadowRoots specifically contains the shadow root: + if (expectedSerializable) { assert_equals(wrapper.getHTML({serializableShadowRoots: true}), - emptyElement); - assert_equals(wrapper.getHTML({serializableShadowRoots: true, - shadowRoots: []}), emptyElement); + correctHtml); + assert_equals(wrapper.firstElementChild.getHTML({ + serializableShadowRoots: true}), + `${correctShadowHtml}${lightDOMContent}`); + } else { + assert_equals(wrapper.getHTML({serializableShadowRoots: true}), emptyElement); } // If we provide the shadow root, serialize it, regardless of serializableShadowRoots. assert_equals(wrapper.getHTML({serializableShadowRoots: true, shadowRoots: