From da4e8995188f85b425cc720235e0266bbe72267c Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 12 Dec 2024 18:30:29 +0100 Subject: [PATCH 1/5] Remove quadratic behavior from clone a node Strictly speaking this should be an editorial change, but as it's fairly significant not marking it as such. This improves integration with HTML as well. As part of this change we move the shadow tree behavior under creating the element clone as that is a more logical fit. Unfortunately subtree has to be passed everywhere as HTML needs it for its template element logic. That's also why clone a node's children is exported. Corresponding HTML PR: SOON. Fixes #1219. Closes #1220. --- dom.bs | 147 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 61 deletions(-) diff --git a/dom.bs b/dom.bs index 4c3fe8ed..b1f494ac 100644 --- a/dom.bs +++ b/dom.bs @@ -4097,7 +4097,7 @@ interface Node : EventTarget { [CEReactions] attribute DOMString? textContent; [CEReactions] undefined normalize(); - [CEReactions, NewObject] Node cloneNode(optional boolean deep = false); + [CEReactions, NewObject] Node cloneNode(optional boolean subtree = false); boolean isEqualNode(Node? otherNode); boolean isSameNode(Node? otherNode); // legacy alias of === @@ -4521,9 +4521,9 @@ each descendant exclusive Text node nod
-
node . cloneNode([deep = false]) +
node . cloneNode([subtree = false])
Returns a copy of node. If - deep is true, the copy also includes the + subtree is true, the copy also includes the node's descendants.
node . {{Node/isEqualNode(otherNode)}} @@ -4533,33 +4533,82 @@ each descendant exclusive Text node nod
+
Specifications may define cloning steps for all or some nodes. The -algorithm is passed copy, node, document, and an optional -clone children flag, as indicated in the clone algorithm. +algorithm is passed node, copy, and subtree as +indicated in the clone a node algorithm. -

HTML defines cloning steps for <{script}> and <{input}> -elements. SVG ought to do the same for its <{script}> elements, but does not call this out -at the moment. +

HTML defines cloning steps for several elements, such as <{input}>, <{script}>, +and <{template}>. SVG ought to do the same for its <{script}> elements, but does not. +

-

To clone a -node, with an optional document and clone children flag, run these -steps: - +

+

To clone a node given a node node +and an optional document document +(default node's node document), boolean +subtree (default false), and +node-or-null parent (default null):

    -
  1. If document is not given, then set document to node's - node document. +

  2. Assert: node is not a document or node is + document. -

  3. Assert: node is not a document or node is +
  4. Let copy be the result of cloning a single node given node and document. +

  5. If parent is non-null, then append copy to + parent. + +

  6. Run any cloning steps defined for node in + other applicable specifications and pass node, copy, and + subtree as parameters. + +

  7. If subtree is true, then for each child of node's + children, in tree order: clone a node given child with + document set to document, + subtree set to subtree, and + parent set to copy. + +

  8. +

    If node is an element, shadow host, and its + shadow root's clonable is true: + +

      +
    1. Assert: copy is not a shadow host. + +

    2. Attach a shadow root with copy, node's + shadow root's mode, true, node's + shadow root's serializable, node's + shadow root's delegates focus, and node's + shadow root's slot assignment. + +

    3. Set copy's shadow root's declarative + to node's shadow root's declarative. + +

    4. For each child of node's shadow root's + children, in tree order: clone a node given child with + document set to document, + subtree set to subtree, and + parent set to copy's shadow root. +

    + +
  9. Return copy. +

+
+ +
+

To clone a single node given a node node and +document document: + +

    +
  1. Let copy be null. +

  2. If node is an element:

      -
    1. Let copy be the result of creating an element, given +

    2. Set copy to the result of creating an element, given document, node's local name, node's namespace, node's namespace prefix, and node's is value. @@ -4569,16 +4618,15 @@ dom-Range-extractContents, dom-Range-cloneContents --> attribute list:

        -
      1. Let copyAttribute be a clone of attribute. +

      2. Let copyAttribute be the result of cloning a single node given + attribute and document.

      3. Append copyAttribute to copy.

      -
    -
  3. -

    Otherwise, let copy be a node that implements the same +

    Otherwise, set copy to a node that implements the same interfaces as node, and fulfills these additional requirements, switching on the interface node implements: @@ -4608,54 +4656,28 @@ dom-Range-extractContents, dom-Range-cloneContents -->

    Do nothing.

+
  • Assert: copy is a node. +

  • If node is a document, then set document to copy.

  • Set copy's node document to document. -

  • Run any cloning steps defined for node in - other applicable specifications and pass copy, node, - document, and the clone children flag if set, as parameters. - -

  • If the clone children flag is set, then for each child - child of node, in tree order: append the result of - cloning child with document and the - clone children flag set, to copy. - -

  • -

    If node is a shadow host whose shadow root's - clonable is true: - -

      -
    1. Assert: copy is not a shadow host. - -

    2. Run attach a shadow root with copy, node's - shadow root's mode, true, node's - shadow root's serializable, node's - shadow root's delegates focus, and node's - shadow root's slot assignment. - -

    3. Set copy's shadow root's declarative - to node's shadow root's declarative. - -

    4. For each child child of node's - shadow root, in tree order: append the result of - cloning child with document and the - clone children flag set, to copy's shadow root. -

    -
  • Return copy. + -

    The cloneNode(deep) method steps are: +

    +

    The cloneNode(subtree) method steps are:

    1. If this is a shadow root, then throw a "{{NotSupportedError!!exception}}" {{DOMException}}. -

    2. Return a clone of this, with the - clone children flag set if deep is true. +

    3. Return the result of cloning a node given this with + subtree set to subtree.

    +

    A node A equals a node B if all of the following conditions are true: @@ -5127,7 +5149,7 @@ interface Document : Node { [NewObject] Comment createComment(DOMString data); [NewObject] ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data); - [CEReactions, NewObject] Node importNode(Node node, optional boolean deep = false); + [CEReactions, NewObject] Node importNode(Node node, optional boolean subtree = false); [CEReactions] Node adoptNode(Node node); [NewObject] Attr createAttribute(DOMString localName); @@ -5554,9 +5576,9 @@ method steps are:


    -
    clone = document . importNode(node [, deep = false]) +
    clone = document . importNode(node [, subtree = false])
    -

    Returns a copy of node. If deep is true, the copy also includes the +

    Returns a copy of node. If subtree is true, the copy also includes the node's descendants.

    If node is a document or a shadow root, throws a @@ -5573,16 +5595,19 @@ method steps are: "{{HierarchyRequestError!!exception}}" {{DOMException}}.

    -

    The importNode(node, deep) +

    +

    The importNode(node, subtree) method steps are:

    1. If node is a document or shadow root, then throw a "{{NotSupportedError!!exception}}" {{DOMException}}. -

    2. Return a clone of node, with this and the - clone children flag set if deep is true. +

    3. Return the result of cloning a node given node with + document set to this and + subtree set to subtree.

    +

    Specifications may define adopting steps for all or some nodes. The From 1962240a181a869b1619586bbd81bcd94ff45ad6 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 16 Dec 2024 11:44:30 +0100 Subject: [PATCH 2/5] CI fix --- dom.bs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dom.bs b/dom.bs index b1f494ac..480e8777 100644 --- a/dom.bs +++ b/dom.bs @@ -972,8 +972,8 @@ object, an event listener is a broader concept as can be seen above. which takes an event event, and returns an {{EventTarget}} object. Unless specified otherwise it returns null. -

    Nodes, shadow roots, and documents -override the get the parent algorithm. +

    Nodes, shadow roots, and documents override the +get the parent algorithm.

    Each {{EventTarget}} object can have an associated activation behavior algorithm. The @@ -4294,7 +4294,7 @@ statement, switching on the interface this implements:

    node . {{Node/ownerDocument}}
    Returns the node document. - Returns null for documents. + Returns null for documents.
    node . {{Node/getRootNode()}}
    Returns node's root. @@ -5210,9 +5210,9 @@ is "quirks", and mode is "limited-quirks".
    -

    The mode is only ever changed from the default for documents created - by the HTML parser based on the presence, absence, or value of the DOCTYPE string, and by a - new browsing context (initial "about:blank"). [[!HTML]] +

    The mode is only ever changed from the default for documents + created by the HTML parser based on the presence, absence, or value of the DOCTYPE string, + and by a new browsing context (initial "about:blank"). [[!HTML]]

    No-quirks mode was originally known as "standards mode" and limited-quirks mode was once known as "almost standards mode". They have been renamed because their details are now From 371e70d8ae73307599abcb8574800dedc12ff6f2 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 16 Dec 2024 11:46:04 +0100 Subject: [PATCH 3/5] CI fix 2 --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 480e8777..1563ae1b 100644 --- a/dom.bs +++ b/dom.bs @@ -2218,7 +2218,7 @@ It is represented as follows:

    • - Document + Document
      • Doctype: html
      • {{Element}}: html class="e" From 00e77d7c3bc95c83a7c8814d029d4eb30c3f42eb Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 17 Dec 2024 08:40:32 +0100 Subject: [PATCH 4/5] final review comments --- dom.bs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dom.bs b/dom.bs index 1563ae1b..ef1195ba 100644 --- a/dom.bs +++ b/dom.bs @@ -4557,13 +4557,13 @@ and an optional document docume
      • Let copy be the result of cloning a single node given node and document. -

      • If parent is non-null, then append copy to - parent. -

      • Run any cloning steps defined for node in other applicable specifications and pass node, copy, and subtree as parameters. +

      • If parent is non-null, then append copy to + parent. +

      • If subtree is true, then for each child of node's children, in tree order: clone a node given child with document set to document, @@ -4571,8 +4571,9 @@ and an optional document docume parent set to copy.

      • -

        If node is an element, shadow host, and its - shadow root's clonable is true: +

        If node is an element, node is a + shadow host, and node's shadow root's + clonable is true:

        1. Assert: copy is not a shadow host. From 76beba985763b339f4727917bf1ebc3f1dfddf7e Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 17 Dec 2024 08:42:01 +0100 Subject: [PATCH 5/5] Update dom.bs --- dom.bs | 1 + 1 file changed, 1 insertion(+) diff --git a/dom.bs b/dom.bs index ef1195ba..44de9d21 100644 --- a/dom.bs +++ b/dom.bs @@ -10428,6 +10428,7 @@ Daniel Clark, Daniel Glazman, Darien Maillet Valentine, Darin Fisher, +David Baron, David Bruant, David Flanagan, David Håsäther,