From c431e0f7e6806a11ff60e2c1f7a495bbd2314162 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 21 Jul 2025 12:02:32 +0200 Subject: [PATCH] Scope non-scoped (global) registries to a single document This preserves existing behavior. We throw exceptions in certain corner cases to give us some wiggle room in the future to change some of this around. Corresponding HTML PR: TODO Tests: https://github.com/web-platform-tests/wpt/pull/53791. Fixes #1390. --- dom.bs | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 11 deletions(-) diff --git a/dom.bs b/dom.bs index 0c81d339..4a8b34f6 100644 --- a/dom.bs +++ b/dom.bs @@ -4854,6 +4854,10 @@ and an optional document docume
  • Let shadowRootRegistry be node's shadow root's custom element registry. +

  • If shadowRootRegistry is a global custom element registry, then set + shadowRootRegistry to document's + effective global custom element registry. +

  • Attach a shadow root with copy, node's shadow root's mode, true, node's shadow root's serializable, node's @@ -4896,6 +4900,9 @@ and an optional document docume

  • If registry is null, then set registry to fallbackRegistry. +

  • If registry is a global custom element registry, then set + registry to document's effective global custom element registry. +

  • Set copy to the result of creating an element, given document, node's local name, node's namespace, node's namespace prefix, @@ -4920,10 +4927,18 @@ and an optional document docume

    {{Document}} -

    Set copy's encoding, content type, - URL, origin, type, - mode, allow declarative shadow roots, and - custom element registry to those of node. +

    +
      +
    1. Set copy's encoding, content type, + URL, origin, type, + mode, and allow declarative shadow roots, to those of + node. + +

    2. If node's custom element registry's + is scoped is true, then set copy's + custom element registry to node's + custom element registry. +

    {{DocumentType}}

    Set copy's name, public ID, and @@ -5774,6 +5789,7 @@ method steps are to return the list of elements with class names classNa

    The HTML Standard will, e.g., define that for html and the HTML namespace, the {{HTMLHtmlElement}} interface is used. [[!HTML]] +

    The createElement(localName, options) method steps are: @@ -5795,7 +5811,9 @@ method steps are:

  • Return the result of creating an element given this, localName, namespace, null, is, true, and registry. +

  • +

    The internal createElementNS steps, given document, namespace, qualifiedName, and options, are as follows: @@ -5811,13 +5829,17 @@ method steps are: localName, namespace, prefix, is, true, and registry. +

    +

    The createElementNS(namespace, qualifiedName, options) method steps are to return the result of running the internal createElementNS steps, given this, namespace, qualifiedName, and options. +

    +

    To flatten element creation options, given a string or {{ElementCreationOptions}} dictionary options and a document document: @@ -5833,6 +5855,10 @@ dictionary options and a document document:

  • If options["{{ElementCreationOptions/customElementRegistry}}"] exists, then set registry to it. +

  • If registry's is scoped is false and + registry is not document's custom element registry, + then throw a "{{NotSupportedError!!exception}}" {{DOMException}}. +

  • If options["{{ElementCreationOptions/is}}"] exists, then set is to it. @@ -5848,6 +5874,7 @@ dictionary options and a document document:

    {{Document/createElement()}} and {{Document/createElementNS()}}'s options parameter is allowed to be a string for web compatibility. +

  • The createDocumentFragment() method steps are to return a new {{DocumentFragment}} node whose node document is @@ -5944,6 +5971,10 @@ method steps are:

  • If options["{{ImportNodeOptions/customElementRegistry}}"] exists, then set registry to it. + +

  • If registry's is scoped is false and + registry is not this's custom element registry, then + throw a "{{NotSupportedError!!exception}}" {{DOMException}}.

  • If registry is null, then set registry to the result of @@ -5956,11 +5987,14 @@ method steps are: +

    Specifications may define adopting steps for all or some nodes. The -algorithm is passed node and oldDocument, as indicated in the adopt -algorithm. +algorithm is passed node and oldDocument, as indicated in the +adopt algorithm. +

    +

    To adopt a node into a document, run these steps: @@ -5981,9 +6015,24 @@ these steps:

    1. Set inclusiveDescendant's node document to document. -

    2. If inclusiveDescendant is an element, then set the - node document of each attribute in inclusiveDescendant's - attribute list to document. +

    3. If inclusiveDescendant is a shadow root and + inclusiveDescendant's custom element registry + is a global custom element registry, then set inclusiveDescendant's + custom element registry to document's + effective global custom element registry. + +

    4. +

      Otherwise, if inclusiveDescendant is an element: + +

        +
      1. Set the node document of each attribute in + inclusiveDescendant's attribute list to document. + +

      2. If inclusiveDescendant's custom element registry + is a global custom element registry, then set inclusiveDescendant's + custom element registry to document's + effective global custom element registry. +

  • For each inclusiveDescendant in node's @@ -5997,7 +6046,9 @@ these steps: adopting steps with inclusiveDescendant and oldDocument. + +

    The adoptNode(node) method steps are:

      @@ -6014,6 +6065,24 @@ these steps:
    1. Return node.

    +
    + +
    + +

    Null or a {{CustomElementRegistry}} object registry +is a global custom element registry if registry is non-null and +registry's is scoped is false.

    + +

    A document document's effective global custom element registry +is: + +

      +
    1. If document's custom element registry + is a global custom element registry, then return document's + custom element registry. + +

    2. Return null. +


    @@ -7515,8 +7584,17 @@ are:
    1. Let registry be this's custom element registry. -

    2. If init["{{ShadowRootInit/customElementRegistry}}"] is non-null, then set - registry to it. +

    3. +

      If init["{{ShadowRootInit/customElementRegistry}}"] is non-null: + +

        +
      1. Set registry to init["{{ShadowRootInit/customElementRegistry}}"]. + +

      2. If registry's is scoped is false and + registry is not this's node document's + custom element registry, then throw a + "{{NotSupportedError!!exception}}" {{DOMException}}. +

    4. Run attach a shadow root with this, init["{{ShadowRootInit/mode}}"], init["{{ShadowRootInit/clonable}}"],