From 5920e1cc0dbc0bb50d1f3a47993d3b05e79d4b1a Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 19 Aug 2024 16:08:41 +0200 Subject: [PATCH 01/61] Initial atomic move skeleton --- dom.bs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/dom.bs b/dom.bs index 04d9bb20e..23478a53c 100644 --- a/dom.bs +++ b/dom.bs @@ -4126,6 +4126,8 @@ interface Node : EventTarget { [CEReactions] Node appendChild(Node node); [CEReactions] Node replaceChild(Node node, Node child); [CEReactions] Node removeChild(Node child); + + [CEReactions] Node moveBefore(Node node, Node? child); }; dictionary GetRootNodeOptions { @@ -5037,6 +5039,36 @@ within this.

The removeChild(child) method steps are to return the result of pre-removing child from this. +

The moveBefore(node, child) +method steps are: + +

    +
  1. Let perform state-preserving atomic move be true if this is + connected, node is connected, this's node + document is fully active, and this's root is the same as + node's root.

  2. . + +
  3. If perform state-preserving atomic move is true, then set this's node document's state-preserving atomic move in progress to true.

  4. + +
  5. Let oldFlag be the value of this's node document's fire + mutation events flag.

  6. + +
  7. Set this's node document's fire mutation events flag to + false.

  8. + +
  9. Let return node be the result of pre-inserting node into + this before child.

  10. + +
  11. Set this's node document's fire mutation events flag to + oldFlag.

  12. + +
  13. Set this's node document's state-preserving atomic move in + progress to false.

  14. + +
  15. Return return node.

  16. +
+

The From 442ef6dfd577806f89f16612473e5f30357d96ef Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:03:24 -0400 Subject: [PATCH 02/61] Most of the `MutationObserver` integration --- dom.bs | 79 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/dom.bs b/dom.bs index 23478a53c..e35927db0 100644 --- a/dom.bs +++ b/dom.bs @@ -2765,6 +2765,9 @@ before a child, with an optional suppress observers flag, run

  • Let nodes be node's children, if node is a {{DocumentFragment}} node; otherwise « node ». +

  • Let state-preserving atomic move in progress be parent's + node document state-preserving atomic move in progress. +

  • Let count be nodes's size.

  • If count is 0, then return. @@ -2773,12 +2776,14 @@ before a child, with an optional suppress observers flag, run

    If node is a {{DocumentFragment}} node:

      +
    1. Assert: state-preserving atomic move in progress is false. +

    2. Remove its children with the suppress observers flag set.

    3. -

      Queue a tree mutation record for node with « », nodes, null, and - null. +

      Queue a tree mutation record for node with « », nodes, « », + null, and null.

      This step intentionally does not pay attention to the suppress observers flag. @@ -2850,8 +2855,24 @@ before a child, with an optional suppress observers flag, run

    -
  • If suppress observers flag is unset, then queue a tree mutation record for - parent with nodes, « », previousSibling, and child. +

  • +

    If suppress observers flag is unset, then: + +

      +
    1. +

      If state-preserving atomic move in progress, then + queue a tree mutation record for parent with « », « », nodes, + previousSibling, and child.

      + +

      This exposes nodes in the corresponding + {{MutationRecord/movedNodes}}.

      +
    2. + +
    3. If state-preserving atomic move in progress, then + queue a tree mutation record for parent with nodes, « », « », + previousSibling, and child.

    4. +
    +
  • Run the children changed steps for parent. @@ -2965,7 +2986,7 @@ within a parent, run these steps: with the suppress observers flag set.

  • Queue a tree mutation record for parent with nodes, - removedNodes, previousSibling, and referenceChild. + removedNodes, « », previousSibling, and referenceChild.

  • Return child. @@ -2992,7 +3013,7 @@ within a parent, run these steps:

  • If either addedNodes or removedNodes is not empty, then queue a tree mutation record for parent with addedNodes, - removedNodes, null, and null. + removedNodes, « », null, and null.

    This algorithm does not make any checks with regards to the @@ -3108,7 +3129,7 @@ optional suppress observers flag, run these steps: registered observer list.

  • If suppress observers flag is unset, then queue a tree mutation record for - parent with « », « node », oldPreviousSibling, and + parent with « », « node », « », oldPreviousSibling, and oldNextSibling.

  • Run the children changed steps for parent. @@ -3896,9 +3917,14 @@ method steps are:

    Queuing a mutation record

    + +state-preserving atomic move in progress +

    To queue a mutation record of type for target with name, namespace, oldValue, addedNodes, -removedNodes, previousSibling, and nextSibling, run these steps: +removedNodes, movedNodes, previousSibling, and +nextSibling, run these steps:

    1. Let interestedObservers be an empty map. @@ -3958,6 +3984,7 @@ method steps are: interestedObservers:

        +
      1. Let record be a new {{MutationRecord}} object with its {{MutationRecord/type}} set to type, {{MutationRecord/target}} set to target, {{MutationRecord/attributeName}} set to name, {{MutationRecord/attributeNamespace}} @@ -3978,15 +4005,28 @@ method steps are:

      To queue a tree mutation record for target with -addedNodes, removedNodes, previousSibling, and -nextSibling, run these steps: +addedNodes, removedNodes, movedNodes, previousSibling, +and nextSibling, run these steps:

        -
      1. Assert: either addedNodes or removedNodes is not empty. +

      2. +

        Assert: one of the following conditions is true:

        + +
          +
        1. target's node document's + state-preserving atomic move in progresss false, and either addedNodes or + removedNodes is not empty; or

        2. + +
        3. target's node document's + state-preserving atomic move in progresss true, and both addedNodes and + removedNodes are empty, and movedNodes + is not empty; or

        4. +
        +
      3. .
      4. Queue a mutation record of "childList" for target with - null, null, null, addedNodes, removedNodes, previousSibling, - and nextSibling. + null, null, null, addedNodes, removedNodes, movedNodes, + previousSibling, and nextSibling.

      @@ -3999,6 +4039,7 @@ interface MutationRecord { [SameObject] readonly attribute Node target; [SameObject] readonly attribute NodeList addedNodes; [SameObject] readonly attribute NodeList removedNodes; + [SameObject] readonly attribute NodeList movedNodes; readonly attribute Node? previousSibling; readonly attribute Node? nextSibling; readonly attribute DOMString? attributeName; @@ -4033,6 +4074,10 @@ interface MutationRecord {
      Return the nodes added and removed respectively. +
      record . {{MutationRecord/movedNodes}} +
      Return the nodes that were moved when a + state-preserving atomic move was in progress. +
      record . {{MutationRecord/previousSibling}}
      record . {{MutationRecord/nextSibling}}
      Return the previous and next sibling respectively @@ -4059,6 +4104,7 @@ interface MutationRecord {

      The type, target, addedNodes, removedNodes, +movedNodes, previousSibling, nextSibling, attributeName, @@ -5662,7 +5708,8 @@ these steps:

    2. Let oldDocument be node's node document.

    3. If node's parent is non-null, then remove - node. + node with the suppress observers flag set if document's + state-preserving atomic move in progress is true, and unset otherwise.

    4. If document is not oldDocument: @@ -6551,7 +6598,7 @@ null), and boolean synchronousCustomElements (default false):

      1. Queue a mutation record of "attributes" for element with attribute's local name, attribute's - namespace, oldValue, « », « », null, and null. + namespace, oldValue, « », « », « », null, and null.

      2. If element is custom, then enqueue a custom element callback reaction with element, callback name @@ -7603,7 +7650,7 @@ string called data. count to length minus offset.

      3. Queue a mutation record of "characterData" for node with - null, null, node's data, « », « », null, and null. + null, null, node's data, « », « », « », null, and null.

      4. Insert data into node's data after offset From 1c8f74f653cf5002a570d5ea08723d4af677cf5d Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:04:25 -0400 Subject: [PATCH 03/61] Remove mutation events flag references --- dom.bs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/dom.bs b/dom.bs index e35927db0..37e781b4f 100644 --- a/dom.bs +++ b/dom.bs @@ -5097,20 +5097,11 @@ method steps are:
      5. If perform state-preserving atomic move is true, then set this's node document's state-preserving atomic move in progress to true.

      6. -
      7. Let oldFlag be the value of this's node document's fire - mutation events flag.

      8. - -
      9. Set this's node document's fire mutation events flag to - false.

      10. -
      11. Let return node be the result of pre-inserting node into this before child.

      12. -
      13. Set this's node document's fire mutation events flag to - oldFlag.

      14. - -
      15. Set this's node document's state-preserving atomic move in - progress to false.

      16. +
      17. Set this's node document's + state-preserving atomic move in progress to false.

      18. Return return node.

      From bc1a4665916f8293a42b94fb392e9f3a2bf55bd4 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:06:23 -0400 Subject: [PATCH 04/61] Populate the `MutationRecord` --- dom.bs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dom.bs b/dom.bs index 37e781b4f..8ead55d05 100644 --- a/dom.bs +++ b/dom.bs @@ -3984,15 +3984,14 @@ term actually appears in HTML --> interestedObservers:
        -
      1. Let record be a new {{MutationRecord}} object with its {{MutationRecord/type}} set to type, {{MutationRecord/target}} set to target, {{MutationRecord/attributeName}} set to name, {{MutationRecord/attributeNamespace}} set to namespace, {{MutationRecord/oldValue}} set to mappedOldValue, {{MutationRecord/addedNodes}} set to addedNodes, - {{MutationRecord/removedNodes}} set to removedNodes, - {{MutationRecord/previousSibling}} set to previousSibling, and - {{MutationRecord/nextSibling}} set to nextSibling. + {{MutationRecord/removedNodes}} set to removedNodes, {{MutationRecord/movedNodes}} set + to movedNodes, {{MutationRecord/previousSibling}} set to previousSibling, + and {{MutationRecord/nextSibling}} set to nextSibling.

      2. Enqueue record to observer's record queue. From 4030e9abd907e4b26b69c26a90c3f3df8795d9c5 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:15:49 -0400 Subject: [PATCH 05/61] Fix punctuation --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 8ead55d05..ad5962f1a 100644 --- a/dom.bs +++ b/dom.bs @@ -4019,9 +4019,9 @@ and nextSibling, run these steps:

      3. target's node document's state-preserving atomic move in progresss true, and both addedNodes and removedNodes are empty, and movedNodes - is not empty; or

      4. + is not empty

      -
    5. . +
    6. Queue a mutation record of "childList" for target with null, null, null, addedNodes, removedNodes, movedNodes, From 8d41e6a968801b21fbe648f0eabfe66c7eb6fc21 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:18:37 -0400 Subject: [PATCH 06/61] Remove trailing whitespace --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index ad5962f1a..4f839a9e0 100644 --- a/dom.bs +++ b/dom.bs @@ -4010,7 +4010,7 @@ and nextSibling, run these steps:

      1. Assert: one of the following conditions is true:

        - +
        1. target's node document's state-preserving atomic move in progresss false, and either addedNodes or From 588e62d360a26763606fa8aac813d5d27832bb22 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 27 Aug 2024 10:00:32 -0400 Subject: [PATCH 07/61] `` -> `` plus fix punctuation error --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index 4f839a9e0..cac005790 100644 --- a/dom.bs +++ b/dom.bs @@ -2766,7 +2766,7 @@ before a child, with an optional suppress observers flag, run {{DocumentFragment}} node; otherwise « node ».

        2. Let state-preserving atomic move in progress be parent's - node document state-preserving atomic move in progress. + node document's state-preserving atomic move in progress.

        3. Let count be nodes's size. @@ -4013,11 +4013,11 @@ and nextSibling, run these steps:

          1. target's node document's - state-preserving atomic move in progresss false, and either addedNodes or + state-preserving atomic move in progress is false, and either addedNodes or removedNodes is not empty; or

          2. target's node document's - state-preserving atomic move in progresss true, and both addedNodes and + state-preserving atomic move in progresss true, and both addedNodes and removedNodes are empty, and movedNodes is not empty

          From 2b8cf634fa44315534807fe87a360af330559586 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 27 Aug 2024 10:10:50 -0400 Subject: [PATCH 08/61] Camel case --- dom.bs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dom.bs b/dom.bs index cac005790..38b7dac66 100644 --- a/dom.bs +++ b/dom.bs @@ -2765,7 +2765,7 @@ before a child, with an optional suppress observers flag, run
        4. Let nodes be node's children, if node is a {{DocumentFragment}} node; otherwise « node ». -

        5. Let state-preserving atomic move in progress be parent's +

        6. Let statePreservingAtomicMoveInProgress be parent's node document's state-preserving atomic move in progress.

        7. Let count be nodes's size. @@ -2776,7 +2776,7 @@ before a child, with an optional suppress observers flag, run

          If node is a {{DocumentFragment}} node:

            -
          1. Assert: state-preserving atomic move in progress is false. +

          2. Assert: statePreservingAtomicMoveInProgress is false.

          3. Remove its children with the suppress observers flag set. @@ -2860,15 +2860,15 @@ before a child, with an optional suppress observers flag, run

            1. -

              If state-preserving atomic move in progress, then - queue a tree mutation record for parent with « », « », nodes, - previousSibling, and child.

              +

              If statePreservingAtomicMoveInProgress, then queue a tree mutation record + for parent with « », « », nodes, previousSibling, and + child.

              This exposes nodes in the corresponding {{MutationRecord/movedNodes}}.

            2. -
            3. If state-preserving atomic move in progress, then +

            4. If statePreservingAtomicMoveInProgress, then queue a tree mutation record for parent with nodes, « », « », previousSibling, and child.

            From 7b742c7a24b9a3e2ff46839d0d049957de6d4f98 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 24 Sep 2024 15:07:02 -0700 Subject: [PATCH 09/61] Throw an exception on failure --- dom.bs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/dom.bs b/dom.bs index 38b7dac66..46117ab6d 100644 --- a/dom.bs +++ b/dom.bs @@ -5088,13 +5088,22 @@ return the result of pre-removing child from this. method steps are:
              -
            1. Let perform state-preserving atomic move be true if this is - connected, node is connected, this's node - document is fully active, and this's root is the same as - node's root.

            2. . +
            3. If any of the following conditions are false:

              -
            4. If perform state-preserving atomic move is true, then set this's node document's state-preserving atomic move in progress to true.

            5. + + +
            6. then throw "{{HierarchyRequestError!!exception}}" {{DOMException}}.

              + +
            7. Set this's node document's + state-preserving atomic move in progress to true.

            8. Let return node be the result of pre-inserting node into this before child.

            9. From 7039d3b34d0a2c33e8a3970912b2254eb56483b3 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 30 Sep 2024 00:26:58 -0400 Subject: [PATCH 10/61] Introduce move primitive + moving steps hook/extension --- dom.bs | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 130 insertions(+), 5 deletions(-) diff --git a/dom.bs b/dom.bs index 46117ab6d..86e4bbebb 100644 --- a/dom.bs +++ b/dom.bs @@ -2688,6 +2688,24 @@ boolean open (default false):
            +

            To pre-move a node into a +parent before a child, run these steps: + +

              + +
            1. Ensure pre-insertion validity of node into parent before + child. + +

            2. Let referenceChild be child. + +

            3. If referenceChild is node, then set referenceChild to + node's next sibling. + +

            4. Move node into parent before referenceChild. + +

            5. Return node. +

            +

            Specifications may define insertion steps for all or some nodes. The algorithm is passed insertedNode, as indicated in the insert algorithm @@ -2902,6 +2920,114 @@ before a child, with an optional suppress observers flag, run

          +

          Specifications may define moving steps for all or some nodes. The algorithm is +passed a node movedNode, and a node-or-null oldParent as indicated in the move algorithm below. + +

          To move a node into a parent before +a child, with an optional suppress observers flag, run these steps: + +

            +
          1. Let statePreservingAtomicMoveInProgress be node's + node document's state-preserving atomic move in progress. + +

          2. Let oldParent be node's parent. + +

          3. Assert: parent is non-null. + +

          4. +

            If child is non-null, then: + +

              +
            1. For each live range whose start node is parent and + start offset is greater than child's index, increase + its start offset by count. + +

            2. For each live range whose end node is parent and + end offset is greater than child's index, increase + its end offset by count. +

            + +
          5. Let previousSibling be child's previous sibling or + parent's last child if child is null. + +

          6. Remove node with the suppress observers flag set if + document's state-preserving atomic move in progress is true, and unset otherwise. + +

          7. If child is null, then append node to + parent's children. + +

          8. Otherwise, insert node into parent's + children before child's index. + +

          9. If parent is a shadow host whose shadow root's + slot assignment is "named" and node is a + slottable, then assign a slot for node. + +

          10. If parent's root is a shadow root, and + parent is a slot whose assigned nodes is the empty list, + then run signal a slot change for parent. + +

          11. Run assign slottables for a tree with node's root. + +

          12. +

            For each shadow-including inclusive descendant inclusiveDescendant of + node, in shadow-including tree order: + +

              +
            1. +

              If inclusiveDescendant is node, then run the moving steps with + inclusiveDescendant and oldParent. Otherwise, run the moving steps + with inclusiveDescendant and null. + +

              Because the move algorithm is a separate primitive from + insert and remove, it does not invoke the traditional + insertion steps or removing steps for inclusiveDescendant. +

            2. + +
            3. +

              If inclusiveDescendant is custom, then + enqueue a custom element callback reaction with inclusiveDescendant, callback + name "connectedCallback", and an empty argument list. + +

              TODO(Noam): Do the right custom element callback stuff here.

              +
            4. + +
            5. +

              Otherwise, try to upgrade + inclusiveDescendant. + +

              If this successfully upgrades inclusiveDescendant, its + connectedCallback will be enqueued automatically during the + upgrade an element algorithm. +

            6. +
            +
          13. + +
          14. +

            If suppress observers flag is unset, then: + +

              +
            1. +

              If statePreservingAtomicMoveInProgress, then queue a tree mutation record + for parent with « », « », nodes, previousSibling, and + child.

              + +

              This exposes nodes in the corresponding + {{MutationRecord/movedNodes}}.

              +
            2. + +
            3. If statePreservingAtomicMoveInProgress, then + queue a tree mutation record for parent with nodes, « », « », + previousSibling, and child.

            4. +
            +
          15. + +
          16. Run the children changed steps for parent. +

          + +

          To append a node to a parent, pre-insert node into parent before null. @@ -3919,7 +4045,7 @@ method steps are: -state-preserving atomic move in progress +state-preserving atomic move in progress

          To queue a mutation record of type for target with name, namespace, oldValue, addedNodes, @@ -5095,9 +5221,8 @@ method steps are:

        8. node is connected;

        9. -
        10. this's node document is fully active; or

        11. - -
        12. this's root is the same as node's root,

        13. +
        14. this's shadow-including root is the same as node's + shadow-including root,

        15. then throw "{{HierarchyRequestError!!exception}}" {{DOMException}}.

          @@ -5105,7 +5230,7 @@ method steps are:
        16. Set this's node document's state-preserving atomic move in progress to true.

        17. -
        18. Let return node be the result of pre-inserting node into +

        19. Let return node be the result of pre-moving node into this before child.

        20. Set this's node document's From b17f357fe121466dfe8e9f456fe243a3f31a57ab Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:34:32 -0400 Subject: [PATCH 11/61] Remove changes to insertion primitive --- dom.bs | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/dom.bs b/dom.bs index 86e4bbebb..3ed72ce2a 100644 --- a/dom.bs +++ b/dom.bs @@ -2783,9 +2783,6 @@ before a child, with an optional suppress observers flag, run

        21. Let nodes be node's children, if node is a {{DocumentFragment}} node; otherwise « node ». -

        22. Let statePreservingAtomicMoveInProgress be parent's - node document's state-preserving atomic move in progress. -

        23. Let count be nodes's size.

        24. If count is 0, then return. @@ -2794,8 +2791,6 @@ before a child, with an optional suppress observers flag, run

          If node is a {{DocumentFragment}} node:

            -
          1. Assert: statePreservingAtomicMoveInProgress is false. -

          2. Remove its children with the suppress observers flag set. @@ -2873,24 +2868,8 @@ before a child, with an optional suppress observers flag, run

          -
        25. -

          If suppress observers flag is unset, then: - -

            -
          1. -

            If statePreservingAtomicMoveInProgress, then queue a tree mutation record - for parent with « », « », nodes, previousSibling, and - child.

            - -

            This exposes nodes in the corresponding - {{MutationRecord/movedNodes}}.

            -
          2. - -
          3. If statePreservingAtomicMoveInProgress, then - queue a tree mutation record for parent with nodes, « », « », - previousSibling, and child.

          4. -
          -
        26. +
        27. If suppress observers flag is unset, then queue a tree mutation record for + parent with nodes, « », previousSibling, and child.

        28. Run the children changed steps for parent. From ef2f986e1d40fb4c39ebc20759c19887d366c5d2 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:43:14 -0400 Subject: [PATCH 12/61] Revert document flag and mutation record changes --- dom.bs | 80 ++++++++++++++-------------------------------------------- 1 file changed, 19 insertions(+), 61 deletions(-) diff --git a/dom.bs b/dom.bs index 3ed72ce2a..8cd55a02f 100644 --- a/dom.bs +++ b/dom.bs @@ -2795,8 +2795,8 @@ before a child, with an optional suppress observers flag, run set.

        29. -

          Queue a tree mutation record for node with « », nodes, « », - null, and null. +

          Queue a tree mutation record for node with « », nodes, null, + and null.

          This step intentionally does not pay attention to the suppress observers flag. @@ -2908,9 +2908,6 @@ ignore>oldParent as indicated in the move algorithm below. a child, with an optional suppress observers flag, run these steps:

            -
          1. Let statePreservingAtomicMoveInProgress be node's - node document's state-preserving atomic move in progress. -

          2. Let oldParent be node's parent.

          3. Assert: parent is non-null. @@ -2931,8 +2928,7 @@ a child, with an optional suppress observers flag, run these s

          4. Let previousSibling be child's previous sibling or parent's last child if child is null. -

          5. Remove node with the suppress observers flag set if - document's state-preserving atomic move in progress is true, and unset otherwise. +

          6. Remove node with the suppress observers flag set.

          7. If child is null, then append node to parent's children. @@ -2988,17 +2984,10 @@ a child, with an optional suppress observers flag, run these s

            If suppress observers flag is unset, then:

              -
            1. -

              If statePreservingAtomicMoveInProgress, then queue a tree mutation record - for parent with « », « », nodes, previousSibling, and - child.

              - -

              This exposes nodes in the corresponding - {{MutationRecord/movedNodes}}.

              -
            2. +
            3. Queue a tree mutation record for parent with « », nodes, + previousSibling, and child.

            4. -
            5. If statePreservingAtomicMoveInProgress, then - queue a tree mutation record for parent with nodes, « », « », +

            6. Queue a tree mutation record for parent with nodes, « », previousSibling, and child.

          8. @@ -3091,7 +3080,7 @@ within a parent, run these steps: with the suppress observers flag set.
          9. Queue a tree mutation record for parent with nodes, - removedNodes, « », previousSibling, and referenceChild. + removedNodes, previousSibling, and referenceChild.

          10. Return child.

          @@ -3118,7 +3107,7 @@ within a parent, run these steps:
        30. If either addedNodes or removedNodes is not empty, then queue a tree mutation record for parent with addedNodes, - removedNodes, « », null, and null. + removedNodes, null, and null.

        This algorithm does not make any checks with regards to the @@ -3234,7 +3223,7 @@ optional suppress observers flag, run these steps: registered observer list.

      2. If suppress observers flag is unset, then queue a tree mutation record for - parent with « », « node », « », oldPreviousSibling, and + parent with « », « node », oldPreviousSibling, and oldNextSibling.

      3. Run the children changed steps for parent. @@ -4022,14 +4011,9 @@ method steps are:

        Queuing a mutation record

        - -state-preserving atomic move in progress -

        To queue a mutation record of type for target with name, namespace, oldValue, addedNodes, -removedNodes, movedNodes, previousSibling, and -nextSibling, run these steps: +removedNodes, previousSibling, and nextSibling, run these steps:

        1. Let interestedObservers be an empty map. @@ -4094,9 +4078,9 @@ term actually appears in HTML --> {{MutationRecord/attributeName}} set to name, {{MutationRecord/attributeNamespace}} set to namespace, {{MutationRecord/oldValue}} set to mappedOldValue, {{MutationRecord/addedNodes}} set to addedNodes, - {{MutationRecord/removedNodes}} set to removedNodes, {{MutationRecord/movedNodes}} set - to movedNodes, {{MutationRecord/previousSibling}} set to previousSibling, - and {{MutationRecord/nextSibling}} set to nextSibling. + {{MutationRecord/removedNodes}} set to removedNodes, + {{MutationRecord/previousSibling}} set to previousSibling, and + {{MutationRecord/nextSibling}} set to nextSibling.

        2. Enqueue record to observer's record queue. @@ -4109,28 +4093,15 @@ term actually appears in HTML -->

        To queue a tree mutation record for target with -addedNodes, removedNodes, movedNodes, previousSibling, -and nextSibling, run these steps: +addedNodes, removedNodes, previousSibling, and +nextSibling, run these steps:

          -
        1. -

          Assert: one of the following conditions is true:

          - -
            -
          1. target's node document's - state-preserving atomic move in progress is false, and either addedNodes or - removedNodes is not empty; or

          2. - -
          3. target's node document's - state-preserving atomic move in progresss true, and both addedNodes and - removedNodes are empty, and movedNodes - is not empty

          4. -
          -
        2. +
        3. Assert: either addedNodes or removedNodes is not empty.

        4. Queue a mutation record of "childList" for target with - null, null, null, addedNodes, removedNodes, movedNodes, - previousSibling, and nextSibling. + null, null, null, addedNodes, removedNodes, previousSibling, and + nextSibling.

        @@ -4143,7 +4114,6 @@ interface MutationRecord { [SameObject] readonly attribute Node target; [SameObject] readonly attribute NodeList addedNodes; [SameObject] readonly attribute NodeList removedNodes; - [SameObject] readonly attribute NodeList movedNodes; readonly attribute Node? previousSibling; readonly attribute Node? nextSibling; readonly attribute DOMString? attributeName; @@ -4178,10 +4148,6 @@ interface MutationRecord {
        Return the nodes added and removed respectively. -
        record . {{MutationRecord/movedNodes}} -
        Return the nodes that were moved when a - state-preserving atomic move was in progress. -
        record . {{MutationRecord/previousSibling}}
        record . {{MutationRecord/nextSibling}}
        Return the previous and next sibling respectively @@ -4208,7 +4174,6 @@ interface MutationRecord {

        The type, target, addedNodes, removedNodes, -movedNodes, previousSibling, nextSibling, attributeName, @@ -5206,15 +5171,9 @@ method steps are:

      4. then throw "{{HierarchyRequestError!!exception}}" {{DOMException}}.

        -
      5. Set this's node document's - state-preserving atomic move in progress to true.

      6. -
      7. Let return node be the result of pre-moving node into this before child.

      8. -
      9. Set this's node document's - state-preserving atomic move in progress to false.

      10. -
      11. Return return node.

      @@ -5811,8 +5770,7 @@ these steps:
    7. Let oldDocument be node's node document.

    8. If node's parent is non-null, then remove - node with the suppress observers flag set if document's - state-preserving atomic move in progress is true, and unset otherwise. + node.

    9. If document is not oldDocument: From 0a813821033b0d72ae370a7e3e31787e471fab86 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:44:11 -0400 Subject: [PATCH 13/61] Fix mutation record callsites --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 8cd55a02f..04e56bad0 100644 --- a/dom.bs +++ b/dom.bs @@ -6659,7 +6659,7 @@ null), and boolean synchronousCustomElements (default false):

      1. Queue a mutation record of "attributes" for element with attribute's local name, attribute's - namespace, oldValue, « », « », « », null, and null. + namespace, oldValue, « », « », null, and null.

      2. If element is custom, then enqueue a custom element callback reaction with element, callback name @@ -7711,7 +7711,7 @@ string called data. count to length minus offset.

      3. Queue a mutation record of "characterData" for node with - null, null, node's data, « », « », « », null, and null. + null, null, node's data, « », « », null, and null.

      4. Insert data into node's data after offset From 7fda2661f37abd554c8c580c5a857b1925fcd7a5 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:45:04 -0400 Subject: [PATCH 14/61] Fix wrapping --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 04e56bad0..7efbee01f 100644 --- a/dom.bs +++ b/dom.bs @@ -2795,8 +2795,8 @@ before a child, with an optional suppress observers flag, run set.
      5. -

        Queue a tree mutation record for node with « », nodes, null, - and null. +

        Queue a tree mutation record for node with « », nodes, null, and + null.

        This step intentionally does not pay attention to the suppress observers flag. From 11010731a7eb0ce9f1f1d36faab65f6ae63de1f4 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:48:36 -0400 Subject: [PATCH 15/61] Remove suppress observers flag --- dom.bs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/dom.bs b/dom.bs index 7efbee01f..045197de9 100644 --- a/dom.bs +++ b/dom.bs @@ -2905,7 +2905,7 @@ passed a node movedNode, and a node- ignore>oldParent as indicated in the move algorithm below.

        To move a node into a parent before -a child, with an optional suppress observers flag, run these steps: +a child, run these steps:

        1. Let oldParent be node's parent. @@ -2980,17 +2980,11 @@ a child, with an optional suppress observers flag, run these s

      6. -
      7. -

        If suppress observers flag is unset, then: - -

          -
        1. Queue a tree mutation record for parent with « », nodes, - previousSibling, and child.

        2. +
        3. Queue a tree mutation record for parent with « », nodes, + previousSibling, and child.

        4. -
        5. Queue a tree mutation record for parent with nodes, « », - previousSibling, and child.

        6. -
        -
      8. +
      9. Queue a tree mutation record for parent with nodes, « », + previousSibling, and child.

      10. Run the children changed steps for parent.

      From b43c8fc0e62963badde58fc5ce50c8fa1f66a2fd Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:59:20 -0400 Subject: [PATCH 16/61] Custom element integration --- dom.bs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dom.bs b/dom.bs index 045197de9..343a53706 100644 --- a/dom.bs +++ b/dom.bs @@ -2961,13 +2961,9 @@ a child, run these steps: insertion steps or removing steps for inclusiveDescendant.
    10. -
    11. -

      If inclusiveDescendant is custom, then - enqueue a custom element callback reaction with inclusiveDescendant, callback - name "connectedCallback", and an empty argument list. - -

      TODO(Noam): Do the right custom element callback stuff here.

      -
    12. +

      If inclusiveDescendant is custom, then + enqueue a custom element callback reaction with inclusiveDescendant, callback + name "connectedMoveCallback", and an empty argument list.

    13. Otherwise, try to upgrade From ba0638d138fb02a9f77799de1c5d420e2c3378e5 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 11:22:11 -0400 Subject: [PATCH 17/61] Update live ranges and NodeIterators properly; do not call the remove primitive --- dom.bs | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/dom.bs b/dom.bs index 343a53706..bf6c9e5b8 100644 --- a/dom.bs +++ b/dom.bs @@ -2912,6 +2912,36 @@ a child, run these steps:

    14. Assert: parent is non-null. +

    15. Let index be node's index. + + +

    16. For each live range whose start node is an + inclusive descendant of node, set its start to + (parent, index). + +

    17. For each live range whose end node is an inclusive descendant + of node, set its end to (parent, index). + +

    18. For each live range whose start node is parent and + start offset is greater than index, decrease its + start offset by 1. + +

    19. For each live range whose end node is parent and + end offset is greater than index, decrease its + end offset by 1. + +

    20. For each {{NodeIterator}} object iterator whose + root's node document is node's + node document, run the NodeIterator pre-removing steps given + node and iterator. + +

    21. Let oldPreviousSibling be node's previous sibling. + +

    22. Let oldNextSibling be node's next sibling. + +

    23. Remove node from its parent's children. + +

    24. If child is non-null, then: @@ -2928,8 +2958,6 @@ a child, run these steps:

    25. Let previousSibling be child's previous sibling or parent's last child if child is null. -

    26. Remove node with the suppress observers flag set. -

    27. If child is null, then append node to parent's children. @@ -2977,12 +3005,17 @@ a child, run these steps:

    28. Queue a tree mutation record for parent with « », nodes, - previousSibling, and child.

    29. + oldPreviousSibling, and oldNextSibling.

    30. Queue a tree mutation record for parent with nodes, « », previousSibling, and child.

    31. -
    32. Run the children changed steps for parent. +

    33. +

      Run the children changed steps for parent.

      + +

      TODO(domfarolino): Before merging, do a full audit on children changed steps, and + write tests.

      +
    From 53c9142c9dfba2cb72535c3123c5a7ada30ddec3 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 11:23:58 -0400 Subject: [PATCH 18/61] Correct removal bookkeeping --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index bf6c9e5b8..bcfd9481a 100644 --- a/dom.bs +++ b/dom.bs @@ -2908,13 +2908,13 @@ ignore>oldParent as indicated in the move algorithm below. a child, run these steps:
      +
    1. Let oldParent be node's parent. -

    2. Assert: parent is non-null. +

    3. Assert: oldParent is non-null.

    4. Let index be node's index. -

    5. For each live range whose start node is an inclusive descendant of node, set its start to (parent, index). @@ -2939,7 +2939,7 @@ a child, run these steps:

    6. Let oldNextSibling be node's next sibling. -

    7. Remove node from its parent's children. +

    8. Remove node from oldParent's children.

    9. From 25d501eab420b2e321a5222ccb966910ff6c916c Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 14:30:43 -0400 Subject: [PATCH 19/61] Moving steps prose --- dom.bs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index bcfd9481a..12adac061 100644 --- a/dom.bs +++ b/dom.bs @@ -2902,7 +2902,12 @@ before a child, with an optional suppress observers flag, run

      Specifications may define moving steps for all or some nodes. The algorithm is passed a node movedNode, and a node-or-null oldParent as indicated in the move algorithm below. +ignore>oldParent as indicated in the move algorithm below. Like the insertion steps, these steps must not modify the +node tree that insertedNode participates in, create +browsing contexts, fire events, or otherwise execute +JavaScript. These steps may queue tasks to do these things asynchronously, however. +

      To move a node into a parent before a child, run these steps: From a94082745677b0e193b98852106f9facaa616a23 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 16:23:00 -0400 Subject: [PATCH 20/61] Tighten up pre-move checks --- dom.bs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 12adac061..ccc767e60 100644 --- a/dom.bs +++ b/dom.bs @@ -2688,12 +2688,30 @@ boolean open (default false):

    +

    To ensure pre-move validity +of a node into a parent before a child, run these steps: + +

      +
    1. Assert: node is either an {{Element}} or {{CharacterData}}.

    2. + +
    3. If parent is not an {{Element}} node, then throw a + "{{HierarchyRequestError!!exception}}" {{DOMException}}. + +

    4. If node is a host-including inclusive ancestor of parent, then + throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. + +

    5. If child is non-null and its parent is not parent, + then throw a "{{NotFoundError!!exception}}" {{DOMException}}. +

    + +

    The ensure pre-move validity steps are a similar, but slightly stricter version +of the ensure pre-insertion validity steps.

    +

    To pre-move a node into a parent before a child, run these steps:

      - -
    1. Ensure pre-insertion validity of node into parent before +

    2. Ensure pre-move validity of node into parent before child.

    3. Let referenceChild be child. From 8ded562056c849b7142c5906e468211e3f0a402e Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 16:29:14 -0400 Subject: [PATCH 21/61] Assert -> throw condition --- dom.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index ccc767e60..6e09fb093 100644 --- a/dom.bs +++ b/dom.bs @@ -2692,7 +2692,8 @@ boolean open (default false): of a node into a parent before a child, run these steps:

        -
      1. Assert: node is either an {{Element}} or {{CharacterData}}.

      2. +
      3. If node is not an {{Element}} or a {{CharacterData}} node, then + throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

      4. If parent is not an {{Element}} node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. From dbbde9e28713a45617a32e494bac88de8624d125 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 16:42:13 -0400 Subject: [PATCH 22/61] Move conditions into pre-move validity --- dom.bs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/dom.bs b/dom.bs index 6e09fb093..0fe37822a 100644 --- a/dom.bs +++ b/dom.bs @@ -2691,7 +2691,13 @@ boolean open (default false):

        To ensure pre-move validity of a node into a parent before a child, run these steps: -

          +
        1. If either parent or node are not connected, then + throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

        2. + +
        3. If parent's shadow-including root is not the same as + node's shadow-including root, then throw a + "{{HierarchyRequestError!!exception}}" {{DOMException}}.

        4. +
        5. If node is not an {{Element}} or a {{CharacterData}} node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

        6. @@ -5205,21 +5211,8 @@ return the result of pre-removing child from this. method steps are:
            -
          1. If any of the following conditions are false:

            - - - -
          2. then throw "{{HierarchyRequestError!!exception}}" {{DOMException}}.

            -
          3. Let return node be the result of pre-moving node into - this before child.

          4. + this before child, rethrowing any exceptions.

          5. Return return node.

          From e28936a190a6e89d8225d3f89d8cbd4ffe8a2fde Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 16:43:18 -0400 Subject: [PATCH 23/61] Fix `` --- dom.bs | 1 + 1 file changed, 1 insertion(+) diff --git a/dom.bs b/dom.bs index 0fe37822a..5f27e21af 100644 --- a/dom.bs +++ b/dom.bs @@ -2691,6 +2691,7 @@ boolean open (default false):

          To ensure pre-move validity of a node into a parent before a child, run these steps: +

          1. If either parent or node are not connected, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

          2. From 60076c92166c22517b8afd01deee74623686ec21 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 21:03:45 -0400 Subject: [PATCH 24/61] Ordering and format --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index 5f27e21af..2a1bef991 100644 --- a/dom.bs +++ b/dom.bs @@ -2699,15 +2699,15 @@ of a node into a parent before a child, run the node's shadow-including root, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

            -
          3. If node is not an {{Element}} or a {{CharacterData}} node, then - throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

          4. -
          5. If parent is not an {{Element}} node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

          6. If node is a host-including inclusive ancestor of parent, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. +

          7. If node is not an {{Element}} or a {{CharacterData}} node, then + throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

          8. +
          9. If child is non-null and its parent is not parent, then throw a "{{NotFoundError!!exception}}" {{DOMException}}.

          From b8ac7bda224e9f00595fa75e9368324140523c72 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 7 Nov 2024 12:03:51 -0500 Subject: [PATCH 25/61] Fix live range updating logic --- dom.bs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/dom.bs b/dom.bs index 2a1bef991..bc9675c58 100644 --- a/dom.bs +++ b/dom.bs @@ -2946,16 +2946,17 @@ a child, run these steps:
        7. Let index be node's index. -

        8. For each live range whose start node is an - inclusive descendant of node, set its start to - (parent, index). - -

        9. For each live range whose end node is an inclusive descendant - of node, set its end to (parent, index). - -

        10. For each live range whose start node is parent and - start offset is greater than index, decrease its - start offset by 1. +

        11. +

          For each live range whose start node is parent and + start offset is greater than index, decrease its + start offset by 1.

          + +

          Note that unlike the traditional removal case, we do not + need to update live range state when their start node or + end node is an inclusive descendant of the node. This is + because said nodes do not get removed from their tree, so ranges associated with + them stay intact.

          +
        12. For each live range whose end node is parent and end offset is greater than index, decrease its @@ -3040,13 +3041,6 @@ a child, run these steps:

        13. Queue a tree mutation record for parent with nodes, « », previousSibling, and child.

        14. - -
        15. -

          Run the children changed steps for parent.

          - -

          TODO(domfarolino): Before merging, do a full audit on children changed steps, and - write tests.

          -
        From ff5f3dd200a7e5c9ed68ae40b5fc7c45be7eccbe Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 7 Nov 2024 12:08:44 -0500 Subject: [PATCH 26/61] Document `move` primitive in Range note --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index bc9675c58..5650797f3 100644 --- a/dom.bs +++ b/dom.bs @@ -8329,8 +8329,8 @@ interface Range : AbstractRange { live ranges.

        Algorithms that modify a tree (in particular the insert, -remove, replace data, and split algorithms) modify -live ranges associated with that tree. +remove, move, replace data, and split +algorithms) modify live ranges associated with that tree.

        The root of a live range is the root of its start node. From 707f3f62b9d646f29e15d4695142cff135c9f593 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 11 Nov 2024 10:33:46 -0500 Subject: [PATCH 27/61] Enable moves in a connected `ShadowRoot` `DocumentFragment` node --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 5650797f3..0be900fb8 100644 --- a/dom.bs +++ b/dom.bs @@ -2699,8 +2699,8 @@ of a node into a parent before a child, run the node's shadow-including root, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

      5. -
      6. If parent is not an {{Element}} node, then throw a - "{{HierarchyRequestError!!exception}}" {{DOMException}}. +

      7. If parent is not an {{Element}} or {{DocumentFragment}} node, then + throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

      8. If node is a host-including inclusive ancestor of parent, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. From 863f481ddd88768c055441e60f79cb0cd825d5d4 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 13 Nov 2024 09:44:45 -0500 Subject: [PATCH 28/61] Do not explicitly rethrow --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 0be900fb8..5ad2c9003 100644 --- a/dom.bs +++ b/dom.bs @@ -5207,7 +5207,7 @@ method steps are:

        1. Let return node be the result of pre-moving node into - this before child, rethrowing any exceptions.

        2. + this before child.

        3. Return return node.

        From c8822cdd45461e6b987199c168e8031458b34fb4 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 19 Nov 2024 13:00:13 -0500 Subject: [PATCH 29/61] Do not do special range handling --- dom.bs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/dom.bs b/dom.bs index 5ad2c9003..6a5bb5fa8 100644 --- a/dom.bs +++ b/dom.bs @@ -2946,17 +2946,16 @@ a child, run these steps:
      9. Let index be node's index. -

      10. -

        For each live range whose start node is parent and - start offset is greater than index, decrease its - start offset by 1.

        - -

        Note that unlike the traditional removal case, we do not - need to update live range state when their start node or - end node is an inclusive descendant of the node. This is - because said nodes do not get removed from their tree, so ranges associated with - them stay intact.

        -
      11. +
      12. For each live range whose start node is an + inclusive descendant of node, set its start to + (parent, index). + +

      13. For each live range whose end node is an inclusive descendant + of node, set its end to (parent, index). + +

      14. For each live range whose start node is parent and + start offset is greater than index, decrease its + start offset by 1.

      15. For each live range whose end node is parent and end offset is greater than index, decrease its From f2ad3dfceabea07ad220c9c0783b0bfc1179cc0f Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 20 Nov 2024 10:20:13 -0500 Subject: [PATCH 30/61] Support both connected->connected and disconnected->disconnected --- dom.bs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 6a5bb5fa8..4ea869cc1 100644 --- a/dom.bs +++ b/dom.bs @@ -2692,8 +2692,20 @@ boolean open (default false): of a node into a parent before a child, run these steps:

          -
        1. If either parent or node are not connected, then - throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

        2. +
        3. +

          If any of the following conditions are true

          + + + +

          then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. + +

          Moving a node around in a DOM tree requires both it and its eventual parent + to both be connected, or both be disconnected. Otherwise, state preservation cannot be + guaranteed during the move operation.

          +
        4. If parent's shadow-including root is not the same as node's shadow-including root, then throw a From 6fe0a6e86b56e7c4b1d742de0cccd046fc9078e2 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 20 Nov 2024 10:23:08 -0500 Subject: [PATCH 31/61] Whitespace and formatting --- dom.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 4ea869cc1..681fdddfe 100644 --- a/dom.bs +++ b/dom.bs @@ -2694,9 +2694,10 @@ of a node into a parent before a child, run the

          1. If any of the following conditions are true

            - + From e2e756698cd675280fd755a58c8aae1ebd367905 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 13:52:38 -0500 Subject: [PATCH 32/61] Factor our live range pre-removal steps --- dom.bs | 59 +++++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/dom.bs b/dom.bs index 681fdddfe..c8db28940 100644 --- a/dom.bs +++ b/dom.bs @@ -2957,22 +2957,7 @@ a child, run these steps:
          2. Assert: oldParent is non-null. -

          3. Let index be node's index. - -

          4. For each live range whose start node is an - inclusive descendant of node, set its start to - (parent, index). - -

          5. For each live range whose end node is an inclusive descendant - of node, set its end to (parent, index). - -

          6. For each live range whose start node is parent and - start offset is greater than index, decrease its - start offset by 1. - -

          7. For each live range whose end node is parent and - end offset is greater than index, decrease its - end offset by 1. +

          8. Run the live range pre-removing steps, given node.

          9. For each {{NodeIterator}} object iterator whose root's node document is node's @@ -3202,22 +3187,7 @@ optional suppress observers flag, run these steps:

          10. Assert: parent is non-null. -

          11. Let index be node's index. - -

          12. For each live range whose start node is an - inclusive descendant of node, set its start to - (parent, index). - -

          13. For each live range whose end node is an inclusive descendant - of node, set its end to (parent, index). - -

          14. For each live range whose start node is parent and - start offset is greater than index, decrease its - start offset by 1. - -

          15. For each live range whose end node is parent and - end offset is greater than index, decrease its - end offset by 1. +

          16. Run the live range pre-removing steps, given node.

          17. For each {{NodeIterator}} object iterator whose root's node document is node's @@ -8408,6 +8378,31 @@ but not its end node, or vice versa. +

            The live range pre-removing steps given a node node, are as follows: + +

              +
            1. Let parent be node's parent. + +

            2. Assert: parent is not null. + +

            3. Let index be node's index. + +

            4. For each live range whose start node is an + inclusive descendant of node, set its start to + (parent, index). + +

            5. For each live range whose end node is an inclusive descendant + of node, set its end to (parent, index). + +

            6. For each live range whose start node is parent and + start offset is greater than index, decrease its + start offset by 1. + +

            7. For each live range whose end node is parent and + end offset is greater than index, decrease its + end offset by 1. +

            +
            From 2a623d53b02bd4bdd0fbead008e15196171225df Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 14:09:12 -0500 Subject: [PATCH 33/61] newParent, newPreviousSibling, and count --- dom.bs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/dom.bs b/dom.bs index c8db28940..e7c49f958 100644 --- a/dom.bs +++ b/dom.bs @@ -2948,8 +2948,8 @@ data-x="concept-insertion-steps-ext">insertion steps, these steps must no JavaScript. These steps may queue tasks to do these things asynchronously, however. -

            To move a node into a parent before -a child, run these steps: +

            To move a node into a newParent +before a child, run these steps:

              @@ -2975,31 +2975,31 @@ a child, run these steps:

              If child is non-null, then:

                -
              1. For each live range whose start node is parent and +

              2. For each live range whose start node is newParent and start offset is greater than child's index, increase - its start offset by count. + its start offset by 1. -

              3. For each live range whose end node is parent and +

              4. For each live range whose end node is newParent and end offset is greater than child's index, increase - its end offset by count. + its end offset by 1.

              -
            1. Let previousSibling be child's previous sibling or - parent's last child if child is null. +

            2. Let newPreviousSibling be child's previous sibling if + child is non-null, and newParent's last child otherwise.

            3. If child is null, then append node to - parent's children. + newParent's children. -

            4. Otherwise, insert node into parent's +

            5. Otherwise, insert node into newParent's children before child's index. -

            6. If parent is a shadow host whose shadow root's +

            7. If newParent is a shadow host whose shadow root's slot assignment is "named" and node is a slottable, then assign a slot for node. -

            8. If parent's root is a shadow root, and - parent is a slot whose assigned nodes is the empty list, - then run signal a slot change for parent. +

            9. If newParent's root is a shadow root, and + newParent is a slot whose assigned nodes is the empty list, + then run signal a slot change for newParent.

            10. Run assign slottables for a tree with node's root. @@ -3033,11 +3033,11 @@ a child, run these steps:

          18. -
          19. Queue a tree mutation record for parent with « », nodes, +

          20. Queue a tree mutation record for oldParent with « », « node », oldPreviousSibling, and oldNextSibling.

          21. -
          22. Queue a tree mutation record for parent with nodes, « », - previousSibling, and child.

          23. +
          24. Queue a tree mutation record for newParent with « node », « », + newPreviousSibling, and child.

          From a820a746037d2e009cf78869b9277a22b4badce4 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 14:34:38 -0500 Subject: [PATCH 34/61] Only queue connectedMoveCallback if connected Initially, we could unconditionally queue the connectedMoveCallback, because `moveBefore()` only worked when the origin and destination were both connected. After https://github.com/whatwg/dom/pull/1307/commits/2bbc8346167310cc3e7f8d2ea65e5151c9cc219f, we support the disconnected->disconnected case, which means we have to explicitly gate this step on being connected. --- dom.bs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index e7c49f958..851bc8864 100644 --- a/dom.bs +++ b/dom.bs @@ -3018,9 +3018,10 @@ before a child, run these steps: insertion steps or removing steps for inclusiveDescendant.
        5. -

          If inclusiveDescendant is custom, then - enqueue a custom element callback reaction with inclusiveDescendant, callback - name "connectedMoveCallback", and an empty argument list. +

          If inclusiveDescendant is custom and newParent is + connected, then enqueue a custom element callback reaction with + inclusiveDescendant, callback name "connectedMoveCallback", and an empty + argument list.

        6. Otherwise, try to upgrade From f23c4982e6eba4788a969af586382b690091d347 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 14:48:32 -0500 Subject: [PATCH 35/61] Revert random editorial change --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 851bc8864..20a5c6574 100644 --- a/dom.bs +++ b/dom.bs @@ -4131,8 +4131,8 @@ method steps are:

        7. Assert: either addedNodes or removedNodes is not empty.

        8. Queue a mutation record of "childList" for target with - null, null, null, addedNodes, removedNodes, previousSibling, and - nextSibling. + null, null, null, addedNodes, removedNodes, previousSibling, + and nextSibling.

        From 21d0da39805c668635df4b00ed7395d7963009ab Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 14:50:39 -0500 Subject: [PATCH 36/61] Remove newline --- dom.bs | 1 - 1 file changed, 1 deletion(-) diff --git a/dom.bs b/dom.bs index 20a5c6574..52ea12736 100644 --- a/dom.bs +++ b/dom.bs @@ -4272,7 +4272,6 @@ interface Node : EventTarget { [CEReactions] Node appendChild(Node node); [CEReactions] Node replaceChild(Node node, Node child); [CEReactions] Node removeChild(Node child); - [CEReactions] Node moveBefore(Node node, Node? child); }; From 12259fb23293d5a356ea8509d837285bc898ae58 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 15:28:06 -0500 Subject: [PATCH 37/61] Remove manual custom element upgrade --- dom.bs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/dom.bs b/dom.bs index 52ea12736..ea5a502a5 100644 --- a/dom.bs +++ b/dom.bs @@ -3018,19 +3018,10 @@ before a child, run these steps: insertion steps or removing steps for inclusiveDescendant.
      16. -

        If inclusiveDescendant is custom and newParent is +

      17. If inclusiveDescendant is custom and newParent is connected, then enqueue a custom element callback reaction with inclusiveDescendant, callback name "connectedMoveCallback", and an empty argument list. - -

      18. -

        Otherwise, try to upgrade - inclusiveDescendant. - -

        If this successfully upgrades inclusiveDescendant, its - connectedCallback will be enqueued automatically during the - upgrade an element algorithm. -

    4. From 16178bbe09bbe79182d932057bfdbd57171f826e Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 9 Dec 2024 17:34:30 -0500 Subject: [PATCH 38/61] Compare node documents instead of shadow-including roots See https://github.com/whatwg/dom/pull/1307#discussion_r1876856324 for rationale. --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index ea5a502a5..f47a12781 100644 --- a/dom.bs +++ b/dom.bs @@ -2708,9 +2708,9 @@ of a node into a parent before a child, run the guaranteed during the move operation.

      -
    5. If parent's shadow-including root is not the same as - node's shadow-including root, then throw a - "{{HierarchyRequestError!!exception}}" {{DOMException}}.

    6. +
    7. If parent's node document is not the same as node's + node document, then throw a "{{HierarchyRequestError!!exception}}" + {{DOMException}}.

    8. If parent is not an {{Element}} or {{DocumentFragment}} node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. From cb0c91cf2f0172eeb965d7623de34f45db1c4321 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 10 Dec 2024 10:29:18 -0500 Subject: [PATCH 39/61] Align pre-move and pre-insertion conditions --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index f47a12781..3b6273cc1 100644 --- a/dom.bs +++ b/dom.bs @@ -2712,8 +2712,8 @@ of a node into a parent before a child, run the node document, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

    9. -
    10. If parent is not an {{Element}} or {{DocumentFragment}} node, then - throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. +

    11. If parent is not a {{Document}}, {{DocumentFragment}}, or {{Element}} + node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

    12. If node is a host-including inclusive ancestor of parent, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. From ca88e231a79016cda4a3639356d45d3136e80bbf Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 10 Dec 2024 14:15:16 -0500 Subject: [PATCH 40/61] Add document-is-parent pre-move conditions --- dom.bs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 3b6273cc1..d236369ec 100644 --- a/dom.bs +++ b/dom.bs @@ -2718,11 +2718,20 @@ of a node into a parent before a child, run the

    13. If node is a host-including inclusive ancestor of parent, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. +

    14. If child is non-null and its parent is not parent, + then throw a "{{NotFoundError!!exception}}" {{DOMException}}. +

    15. If node is not an {{Element}} or a {{CharacterData}} node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

    16. -
    17. If child is non-null and its parent is not parent, - then throw a "{{NotFoundError!!exception}}" {{DOMException}}. +

    18. If node is a {{Text}} node and parent is a + document, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. + +

    19. If parent is a {{Document}}, node is an {{Element}} + node, and either parent has an element child, + child is a doctype, or child is non-null and a doctype is + following child then throw a "{{HierarchyRequestError!!exception}}" + {{DOMException}}.

    The ensure pre-move validity steps are a similar, but slightly stricter version From 358cc4301ecddcd831da8fd1ea3eccbaaa135ab2 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 09:06:31 -0500 Subject: [PATCH 41/61] Remove unnecessary checks now that we have root checks --- dom.bs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/dom.bs b/dom.bs index d236369ec..b5e35d4cf 100644 --- a/dom.bs +++ b/dom.bs @@ -2693,25 +2693,14 @@ of a node into a parent before a child, run the

    1. -

      If any of the following conditions are true

      +

      If parent's shadow-including root is not the same as node's + shadow-including root, then throw a "{{HierarchyRequestError!!exception}}" + {{DOMException}}.

      - - -

      then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. - -

      Moving a node around in a DOM tree requires both it and its eventual parent - to both be connected, or both be disconnected. Otherwise, state preservation cannot be - guaranteed during the move operation.

      +

      This has the side effect of ensuring that a move is only performed if + parent's connected status matches node's connected status.

    2. -
    3. If parent's node document is not the same as node's - node document, then throw a "{{HierarchyRequestError!!exception}}" - {{DOMException}}.

    4. -
    5. If parent is not a {{Document}}, {{DocumentFragment}}, or {{Element}} node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. From 90d4f4514aaa60c303266bce3b603ed3511666ca Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 09:14:13 -0500 Subject: [PATCH 42/61] Live range rename --- dom.bs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dom.bs b/dom.bs index b5e35d4cf..abdad223d 100644 --- a/dom.bs +++ b/dom.bs @@ -2955,11 +2955,11 @@ before a child, run these steps:

    6. Assert: oldParent is non-null. -

    7. Run the live range pre-removing steps, given node. +

    8. Run the live range pre-remove steps, given node.

    9. For each {{NodeIterator}} object iterator whose root's node document is node's - node document, run the NodeIterator pre-removing steps given + node document, run the NodeIterator pre-remove steps given node and iterator.

    10. Let oldPreviousSibling be node's previous sibling. @@ -3177,7 +3177,7 @@ optional suppress observers flag, run these steps:

    11. Assert: parent is non-null. -

    12. Run the live range pre-removing steps, given node. +

    13. Run the live range pre-remove steps, given node.

    14. For each {{NodeIterator}} object iterator whose root's node document is node's @@ -5171,7 +5171,7 @@ method steps are to return the result of replacing child with within this.

      The removeChild(child) method steps are to -return the result of pre-removing child from this. +return the result of pre-remove child from this.

      The moveBefore(node, child) method steps are: @@ -8367,7 +8367,7 @@ but not its end node, or vice versa. -

      The live range pre-removing steps given a node node, are as follows: +

      The live range pre-remove steps given a node node, are as follows:

      1. Let parent be node's parent. From 2eb22d325d5b34b3a9f4e0d14b2361bcffb6e112 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 09:14:50 -0500 Subject: [PATCH 43/61] Empty arguments --- dom.bs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index abdad223d..2b1fd43bb 100644 --- a/dom.bs +++ b/dom.bs @@ -3018,8 +3018,7 @@ before a child, run these steps:

      2. If inclusiveDescendant is custom and newParent is connected, then enqueue a custom element callback reaction with - inclusiveDescendant, callback name "connectedMoveCallback", and an empty - argument list. + inclusiveDescendant, callback name "connectedMoveCallback", and « ».

    15. From 641d6a6b90fdd2dc5994dbae1cfe166962126a94 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 09:51:58 -0500 Subject: [PATCH 44/61] Update dom.bs Co-authored-by: Anne van Kesteren --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 2b1fd43bb..8f54c5c81 100644 --- a/dom.bs +++ b/dom.bs @@ -2716,7 +2716,7 @@ of a node into a parent before a child, run the
    16. If node is a {{Text}} node and parent is a document, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. -

    17. If parent is a {{Document}}, node is an {{Element}} +

    18. If parent is a document, node is an {{Element}} node, and either parent has an element child, child is a doctype, or child is non-null and a doctype is following child then throw a "{{HierarchyRequestError!!exception}}" From 26bd858b5657a51d51eab1bdd51960f7cc1641a7 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 10:37:05 -0500 Subject: [PATCH 45/61] Update dom.bs Co-authored-by: Anne van Kesteren From 5fb8d3a0c1ab99de3a4bffec5e1bb6bb72e17f85 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 10:39:39 -0500 Subject: [PATCH 46/61] Remove run these steps --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 8f54c5c81..304034c68 100644 --- a/dom.bs +++ b/dom.bs @@ -2689,7 +2689,7 @@ boolean open (default false):

    To ensure pre-move validity -of a node into a parent before a child, run these steps: +of a node into a parent before a child:

    1. @@ -2727,7 +2727,7 @@ of a node into a parent before a child, run the of the ensure pre-insertion validity steps.

      To pre-move a node into a -parent before a child, run these steps: +parent before a child:

      1. Ensure pre-move validity of node into parent before From 71736d943e9b574d8d9561527e4a54d2426c724c Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 11:01:44 -0500 Subject: [PATCH 47/61] Move to ParentNode, simplify pre-move conditions, add web developer box --- dom.bs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dom.bs b/dom.bs index 304034c68..a926ec634 100644 --- a/dom.bs +++ b/dom.bs @@ -2701,9 +2701,6 @@ of a node into a parent before a child: parent's connected status matches node's connected status.

      2. -
      3. If parent is not a {{Document}}, {{DocumentFragment}}, or {{Element}} - node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. -

      4. If node is a host-including inclusive ancestor of parent, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. @@ -3320,6 +3317,7 @@ interface mixin ParentNode { [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes); + [CEReactions] Node moveBefore(Node node, Node? child); Element? querySelector(DOMString selectors); [NewObject] NodeList querySelectorAll(DOMString selectors); @@ -3368,6 +3366,16 @@ Element includes ParentNode; the node tree are violated. +

        node . moveBefore(movedNode, child) +
        +

        Moves, without first removing, movedNode into node after child + if child is non-null; otherwise after the last child of node. This + methods preserves state associated with movedNode so that it persists after the move. + +

        Throws a "{{HierarchyRequestError!!exception}}" {{DOMException}} if the constraints of + the node tree are violated. + +

        node . querySelector(selectors)

        Returns the first element that is a descendant of node that matches selectors. @@ -4260,7 +4268,6 @@ interface Node : EventTarget { [CEReactions] Node appendChild(Node node); [CEReactions] Node replaceChild(Node node, Node child); [CEReactions] Node removeChild(Node child); - [CEReactions] Node moveBefore(Node node, Node? child); }; dictionary GetRootNodeOptions { From f321247ed26b1a341caadd0a19e0c8f249432857 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 13 Dec 2024 09:17:55 +0100 Subject: [PATCH 48/61] nits --- dom.bs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/dom.bs b/dom.bs index a926ec634..4b584c1a6 100644 --- a/dom.bs +++ b/dom.bs @@ -2688,8 +2688,8 @@ boolean open (default false):

      -

      To ensure pre-move validity -of a node into a parent before a child: +

      To ensure pre-move validity of a node node into a +node parent before a node child:

      1. @@ -2698,7 +2698,7 @@ of a node into a parent before a child: {{DOMException}}.

        This has the side effect of ensuring that a move is only performed if - parent's connected status matches node's connected status.

        + parent's connected is node's connected.

      2. If node is a host-including inclusive ancestor of parent, then @@ -2721,10 +2721,10 @@ of a node into a parent before a child:

      The ensure pre-move validity steps are a similar, but slightly stricter version -of the ensure pre-insertion validity steps.

      +of the ensure pre-insert validity steps.

      -

      To pre-move a node into a -parent before a child: +

      To pre-move a node node into a node +parent before a node child:

      1. Ensure pre-move validity of node into parent before @@ -2943,8 +2943,8 @@ data-x="concept-insertion-steps-ext">insertion steps, these steps must no JavaScript. These steps may queue tasks to do these things asynchronously, however. -

        To move a node into a newParent -before a child, run these steps: +

        To move a node node into a node +newParent before a node child:

          @@ -2967,7 +2967,7 @@ before a child, run these steps:
        1. -

          If child is non-null, then: +

          If child is non-null:

          1. For each live range whose start node is newParent and @@ -3317,6 +3317,7 @@ interface mixin ParentNode { [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes); + [CEReactions] Node moveBefore(Node node, Node? child); Element? querySelector(DOMString selectors); @@ -3429,6 +3430,16 @@ are:

          2. Replace all with node within this.

          +

          The moveBefore(node, child) +method steps are: + +

            +
          1. Let result be the result of pre-moving node into this + before child.

          2. + +
          3. Return result.

          4. +
          +

          The querySelector(selectors) method steps are to return the first result of running scope-match a selectors string selectors against this, if the result is not an empty list; otherwise null. @@ -5179,16 +5190,6 @@ within this.

          The removeChild(child) method steps are to return the result of pre-remove child from this. -

          The moveBefore(node, child) -method steps are: - -

            -
          1. Let return node be the result of pre-moving node into - this before child.

          2. - -
          3. Return return node.

          4. -
          -

          The @@ -8373,7 +8374,8 @@ but not its end node, or vice versa. -

          The live range pre-remove steps given a node node, are as follows: +

          The live range pre-remove steps given a node node, are as +follows:

          1. Let parent be node's parent. From 53ce47259eb8b10080edb32abb65d5c8185ed354 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 13 Dec 2024 09:32:44 +0100 Subject: [PATCH 49/61] nit --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 4b584c1a6..93119a9c4 100644 --- a/dom.bs +++ b/dom.bs @@ -5188,7 +5188,7 @@ method steps are to return the result of replacing child with within this.

            The removeChild(child) method steps are to -return the result of pre-remove child from this. +return the result of pre-remove child from this.


            From 4822fd76ea52d1eee9530b8a5687c73659b6df92 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 13 Dec 2024 09:38:26 +0100 Subject: [PATCH 50/61] actually, pre-removing here is better --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 93119a9c4..757cb494d 100644 --- a/dom.bs +++ b/dom.bs @@ -5188,7 +5188,7 @@ method steps are to return the result of replacing child with within this.

            The removeChild(child) method steps are to -return the result of pre-remove child from this. +return the result of pre-removing child from this.


            From 1d49fc5a1b888c08f021e57ea74dd1a309efb02c Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 16 Dec 2024 12:51:07 -0500 Subject: [PATCH 51/61] Make moveBefore() return undefined --- dom.bs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/dom.bs b/dom.bs index 757cb494d..7bcfb8896 100644 --- a/dom.bs +++ b/dom.bs @@ -2723,23 +2723,6 @@ boolean open (default false):

            The ensure pre-move validity steps are a similar, but slightly stricter version of the ensure pre-insert validity steps.

            -

            To pre-move a node node into a node -parent before a node child: - -

              -
            1. Ensure pre-move validity of node into parent before - child. - -

            2. Let referenceChild be child. - -

            3. If referenceChild is node, then set referenceChild to - node's next sibling. - -

            4. Move node into parent before referenceChild. - -

            5. Return node. -

            -

            Specifications may define insertion steps for all or some nodes. The algorithm is passed insertedNode, as indicated in the insert algorithm @@ -3318,7 +3301,7 @@ interface mixin ParentNode { [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes); - [CEReactions] Node moveBefore(Node node, Node? child); + [CEReactions] undefined moveBefore(Node node, Node? child); Element? querySelector(DOMString selectors); [NewObject] NodeList querySelectorAll(DOMString selectors); @@ -3434,10 +3417,14 @@ are: method steps are:

              -
            1. Let result be the result of pre-moving node into this - before child.

            2. +
            3. Ensure pre-move validity of node into thisbefore child. + +

            4. Let referenceChild be child. + +

            5. If referenceChild is node, then set referenceChild to + node's next sibling. -

            6. Return result.

            7. +
            8. Move node into this before referenceChild.

            The querySelector(selectors) method From 937f22e58adb6ef182a3def061e11aa1a1e9c474 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 17 Dec 2024 10:38:19 -0500 Subject: [PATCH 52/61] Fold more into the move algorithm --- dom.bs | 64 +++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/dom.bs b/dom.bs index 7bcfb8896..e37dfb0cf 100644 --- a/dom.bs +++ b/dom.bs @@ -2688,41 +2688,6 @@ boolean open (default false):

          -

          To ensure pre-move validity of a node node into a -node parent before a node child: - -

            -
          1. -

            If parent's shadow-including root is not the same as node's - shadow-including root, then throw a "{{HierarchyRequestError!!exception}}" - {{DOMException}}.

            - -

            This has the side effect of ensuring that a move is only performed if - parent's connected is node's connected.

            -
          2. - -
          3. If node is a host-including inclusive ancestor of parent, then - throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. - -

          4. If child is non-null and its parent is not parent, - then throw a "{{NotFoundError!!exception}}" {{DOMException}}. - -

          5. If node is not an {{Element}} or a {{CharacterData}} node, then - throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

          6. - -
          7. If node is a {{Text}} node and parent is a - document, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. - -

          8. If parent is a document, node is an {{Element}} - node, and either parent has an element child, - child is a doctype, or child is non-null and a doctype is - following child then throw a "{{HierarchyRequestError!!exception}}" - {{DOMException}}. -

          - -

          The ensure pre-move validity steps are a similar, but slightly stricter version -of the ensure pre-insert validity steps.

          -

          Specifications may define insertion steps for all or some nodes. The algorithm is passed insertedNode, as indicated in the insert algorithm @@ -2930,6 +2895,33 @@ JavaScript. These steps may queue tasks to do these things asynchronously, howev newParent before a node child:

            + +
          1. +

            If this's shadow-including root is not the same as node's + shadow-including root, then throw a "{{HierarchyRequestError!!exception}}" + {{DOMException}}.

            + +

            This has the side effect of ensuring that a move is only performed if this's + connected is node's connected.

            +
          2. + +
          3. If node is a host-including inclusive ancestor of this, then + throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. + +

          4. If child is non-null and its parent is not this, then + throw a "{{NotFoundError!!exception}}" {{DOMException}}. + +

          5. If node is not an {{Element}} or a {{CharacterData}} node, then + throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

          6. + +
          7. If node is a {{Text}} node and this is a document, + then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. + +

          8. If this is a document, node is an {{Element}} node, + and either this has an element child, child is a + doctype, or child is non-null and a doctype is following + child then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. +

          9. Let oldParent be node's parent. @@ -3417,8 +3409,6 @@ are: method steps are:

              -
            1. Ensure pre-move validity of node into thisbefore child. -

            2. Let referenceChild be child.

            3. If referenceChild is node, then set referenceChild to From 1e183c66354ddf0d0679c65f0fb7ae9f2cf39edc Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 17 Dec 2024 10:44:24 -0500 Subject: [PATCH 53/61] Document for reference, and this->newParent --- dom.bs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/dom.bs b/dom.bs index e37dfb0cf..b17a9818b 100644 --- a/dom.bs +++ b/dom.bs @@ -2897,30 +2897,31 @@ JavaScript. These steps may queue tasks to do these things asynchronously, howev

              1. -

                If this's shadow-including root is not the same as node's - shadow-including root, then throw a "{{HierarchyRequestError!!exception}}" - {{DOMException}}.

                +

                If newParent's shadow-including root is not the same as + node's shadow-including root, then throw a + "{{HierarchyRequestError!!exception}}" {{DOMException}}.

                -

                This has the side effect of ensuring that a move is only performed if this's - connected is node's connected.

                +

                This has the side effect of ensuring that a move is only performed if + newParent's connected is node's connected.

              2. -
              3. If node is a host-including inclusive ancestor of this, then - throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. +

              4. If node is a host-including inclusive ancestor of newParent, + then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. -

              5. If child is non-null and its parent is not this, then - throw a "{{NotFoundError!!exception}}" {{DOMException}}. +

              6. If child is non-null and its parent is not newParent, + then throw a "{{NotFoundError!!exception}}" {{DOMException}}.

              7. If node is not an {{Element}} or a {{CharacterData}} node, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}.

              8. -
              9. If node is a {{Text}} node and this is a document, - then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. +

              10. If node is a {{Text}} node and newParent is a + document, then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. -

              11. If this is a document, node is an {{Element}} node, - and either this has an element child, child is a - doctype, or child is non-null and a doctype is following - child then throw a "{{HierarchyRequestError!!exception}}" {{DOMException}}. +

              12. If newParent is a document, node is an {{Element}} + node, and either newParent has an element + child, child is a doctype, or child is non-null and a + doctype is following child then throw a + "{{HierarchyRequestError!!exception}}" {{DOMException}}.

              13. Let oldParent be node's parent. From 5ae3cde315885bac6cd89a4bd787e40ce3caf847 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 17 Dec 2024 11:47:51 -0500 Subject: [PATCH 54/61] Update moving steps link to be consistent with other extension hooks, and to what HTML expects --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index b17a9818b..7dc5b787b 100644 --- a/dom.bs +++ b/dom.bs @@ -2882,7 +2882,7 @@ before a child, with an optional suppress observers flag, run

                Specifications may define moving steps for all or some nodes. The algorithm is +id=concept-node-move-ext>moving steps for all or some nodes. The algorithm is passed a node movedNode, and a node-or-null oldParent as indicated in the move algorithm below. Like the insertion steps, these steps must not modify the From a454656ebda8e34b98bb22b76bc2cee21f75a843 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Fri, 20 Dec 2024 09:46:46 -0500 Subject: [PATCH 55/61] Fire slotchange events on the removal and insertion during moveBefore --- dom.bs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dom.bs b/dom.bs index 7dc5b787b..1460ca997 100644 --- a/dom.bs +++ b/dom.bs @@ -2941,6 +2941,13 @@ JavaScript. These steps may queue tasks to do these things asynchronously, howev

              14. Remove node from oldParent's children. +

              15. If node is assigned, then run assign slottables for + node's assigned slot. + +

              16. If oldParent's root is a shadow root, and + oldParent is a slot whose assigned nodes is the empty list, then + run signal a slot change for oldParent. +

              17. If child is non-null: From 71a3c385e063f77afb3f137b465299b6ece03d53 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 14 Jan 2025 13:18:54 -0500 Subject: [PATCH 56/61] Remove incorrect `data-x` and `span` --- dom.bs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dom.bs b/dom.bs index 1460ca997..2f2c1431f 100644 --- a/dom.bs +++ b/dom.bs @@ -2884,11 +2884,11 @@ before a child, with an optional suppress observers flag, run

                Specifications may define moving steps for all or some nodes. The algorithm is passed a node movedNode, and a node-or-null oldParent as indicated in the move algorithm below. Like the insertion steps, these steps must not modify the -node tree that insertedNode participates in, create -browsing contexts, fire events, or otherwise execute -JavaScript. These steps may queue tasks to do these things asynchronously, however. +ignore>oldParent as indicated in the move algorithm below. Like the insertion +steps, these steps must not modify the node tree that insertedNode +participates in, create browsing contexts, fire +events, or otherwise execute JavaScript. These steps may queue tasks to do these things +asynchronously, however.

                To move a node node into a node From 53409b962ff05f88b51a9c3a6c9dcea1b6a76f25 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 14 Jan 2025 14:34:02 -0500 Subject: [PATCH 57/61] Wrapping --- dom.bs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dom.bs b/dom.bs index 2f2c1431f..1e0fd7611 100644 --- a/dom.bs +++ b/dom.bs @@ -2881,14 +2881,14 @@ before a child, with an optional suppress observers flag, run

              -

              Specifications may define moving steps for all or some nodes. The algorithm is -passed a node movedNode, and a node-or-null oldParent as indicated in the move algorithm below. Like the insertion -steps, these steps must not modify the node tree that insertedNode -participates in, create browsing contexts, fire -events, or otherwise execute JavaScript. These steps may queue tasks to do these things -asynchronously, however. +

              Specifications may define +moving steps for all or some nodes. The +algorithm is passed a node movedNode, and a node-or-null +oldParent as indicated in the move algorithm below. Like the +insertion steps, these steps must not modify the node tree that +insertedNode participates in, create browsing contexts, +fire events, or otherwise execute JavaScript. These steps may queue tasks +to do these things asynchronously, however.

              To move a node node into a node From 1f60b93df5f3ac5d18cac365367d30c71be9d6f9 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 25 Feb 2025 11:57:59 -0500 Subject: [PATCH 58/61] Add missing slot assignment steps --- dom.bs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dom.bs b/dom.bs index 1e0fd7611..9dc8e3722 100644 --- a/dom.bs +++ b/dom.bs @@ -2948,6 +2948,15 @@ to do these things asynchronously, however. oldParent is a slot whose assigned nodes is the empty list, then run signal a slot change for oldParent. +

            4. +

              If node has an inclusive descendant that is a slot: + +

                +
              1. Run assign slottables for a tree with oldParent's root. + +

              2. Run assign slottables for a tree with node. +

              +
            5. If child is non-null: From 01b7634d90251907a4cc7abb6501afedce1879a2 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 25 Feb 2025 12:04:08 -0500 Subject: [PATCH 59/61] Add missing li, even though it is missing from the place where I copied this step --- dom.bs | 1 + 1 file changed, 1 insertion(+) diff --git a/dom.bs b/dom.bs index 9dc8e3722..2d40b9c34 100644 --- a/dom.bs +++ b/dom.bs @@ -2956,6 +2956,7 @@ to do these things asynchronously, however.

            6. Run assign slottables for a tree with node.

            +
          10. From 9270da79b76b484fed37728d55b22a108065f761 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 25 Feb 2025 12:11:41 -0500 Subject: [PATCH 60/61] Fix open paragraph after amend --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 2d40b9c34..d7ec77ca9 100644 --- a/dom.bs +++ b/dom.bs @@ -3015,7 +3015,7 @@ to do these things asynchronously, however.
          11. Queue a tree mutation record for oldParent with « », « node », oldPreviousSibling, and oldNextSibling.

          12. -
          13. Queue a tree mutation record for newParent with « node », « », +
          14. Queue a tree mutation record for newParent with « node », « », newPreviousSibling, and child.

          From bfbcfd98af954bb6ca6529115c1eb1f974c1b78e Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 27 Feb 2025 11:29:52 -0500 Subject: [PATCH 61/61] Address Anne review --- dom.bs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dom.bs b/dom.bs index d7ec77ca9..09595a608 100644 --- a/dom.bs +++ b/dom.bs @@ -2886,13 +2886,13 @@ before a child, with an optional suppress observers flag, run algorithm is passed a node movedNode, and a node-or-null oldParent as indicated in the move algorithm below. Like the insertion steps, these steps must not modify the node tree that -insertedNode participates in, create browsing contexts, +movedNode participates in, create browsing contexts, fire events, or otherwise execute JavaScript. These steps may queue tasks to do these things asynchronously, however.

          To move a node node into a node -newParent before a node child: +newParent before a node-or-null child:

            @@ -2945,8 +2945,8 @@ to do these things asynchronously, however. node's assigned slot.
          1. If oldParent's root is a shadow root, and - oldParent is a slot whose assigned nodes is the empty list, then - run signal a slot change for oldParent. + oldParent is a slot whose assigned nodes + is empty, then run signal a slot change for oldParent.

          2. If node has an inclusive descendant that is a slot: @@ -2956,7 +2956,6 @@ to do these things asynchronously, however.

          3. Run assign slottables for a tree with node.

          -
        2. @@ -2986,8 +2985,8 @@ to do these things asynchronously, however. slottable, then assign a slot for node.
        3. If newParent's root is a shadow root, and - newParent is a slot whose assigned nodes is the empty list, - then run signal a slot change for newParent. + newParent is a slot whose assigned nodes + is empty, then run signal a slot change for newParent.

        4. Run assign slottables for a tree with node's root. @@ -3364,10 +3363,11 @@ Element includes ParentNode;

          Moves, without first removing, movedNode into node after child if child is non-null; otherwise after the last child of node. This - methods preserves state associated with movedNode so that it persists after the move. + method preserves state associated with movedNode.

          Throws a "{{HierarchyRequestError!!exception}}" {{DOMException}} if the constraints of - the node tree are violated. + the node tree are violated, or the state associated with the moved node cannot be + preserved.

          node . querySelector(selectors)