From 0d30952bf048f110e3a0fb8442cde6216ac82afe Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 19 Aug 2024 16:08:41 +0200 Subject: [PATCH 01/55] Initial atomic move skeleton --- dom.bs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/dom.bs b/dom.bs index 0b7a6bd2..58287665 100644 --- a/dom.bs +++ b/dom.bs @@ -4118,6 +4118,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 { @@ -5005,6 +5007,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 3073a9c52321e3ab49b8cc04b362553a791e5b94 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:03:24 -0400 Subject: [PATCH 02/55] Most of the `MutationObserver` integration --- dom.bs | 79 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/dom.bs b/dom.bs index 58287665..1ab769f7 100644 --- a/dom.bs +++ b/dom.bs @@ -2756,6 +2756,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. @@ -2764,12 +2767,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. @@ -2841,8 +2846,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. @@ -2956,7 +2977,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. @@ -2983,7 +3004,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 @@ -3099,7 +3120,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. @@ -3888,9 +3909,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. @@ -3950,6 +3976,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}} @@ -3970,15 +3997,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.

      @@ -3991,6 +4031,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; @@ -4025,6 +4066,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 @@ -4051,6 +4096,7 @@ interface MutationRecord {

      The type, target, addedNodes, removedNodes, +movedNodes, previousSibling, nextSibling, attributeName, @@ -5626,7 +5672,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: @@ -6516,7 +6563,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 @@ -7561,7 +7608,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 667050064068f8e8d07444035c399a1467197161 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:04:25 -0400 Subject: [PATCH 03/55] Remove mutation events flag references --- dom.bs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/dom.bs b/dom.bs index 1ab769f7..6672319f 100644 --- a/dom.bs +++ b/dom.bs @@ -5065,20 +5065,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 85d32befe50fc733a3860fc73a24b8a33dd5cd7f Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:06:23 -0400 Subject: [PATCH 04/55] Populate the `MutationRecord` --- dom.bs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dom.bs b/dom.bs index 6672319f..ba24b45a 100644 --- a/dom.bs +++ b/dom.bs @@ -3976,15 +3976,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 945189c247f95b338d3fd8d7def09fc47ebc2489 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:15:49 -0400 Subject: [PATCH 05/55] Fix punctuation --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index ba24b45a..8061df42 100644 --- a/dom.bs +++ b/dom.bs @@ -4011,9 +4011,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 8ecd282ee242f599d5275ff8b4b2b24905221385 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 26 Aug 2024 14:18:37 -0400 Subject: [PATCH 06/55] Remove trailing whitespace --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 8061df42..8b21555c 100644 --- a/dom.bs +++ b/dom.bs @@ -4002,7 +4002,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 b798d9a67b59879c0dfb7eca09109ffc10a07e7b Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 27 Aug 2024 10:00:32 -0400 Subject: [PATCH 07/55] `` -> `` plus fix punctuation error --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index 8b21555c..f0eaf495 100644 --- a/dom.bs +++ b/dom.bs @@ -2757,7 +2757,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. @@ -4005,11 +4005,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 e5bb88030b680dc0597004b7586799480a1166b4 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 27 Aug 2024 10:10:50 -0400 Subject: [PATCH 08/55] Camel case --- dom.bs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dom.bs b/dom.bs index f0eaf495..ea467672 100644 --- a/dom.bs +++ b/dom.bs @@ -2756,7 +2756,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. @@ -2767,7 +2767,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. @@ -2851,15 +2851,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 70e15315de035df4ff395fa64f3c4df69eaef013 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 24 Sep 2024 15:07:02 -0700 Subject: [PATCH 09/55] Throw an exception on failure --- dom.bs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/dom.bs b/dom.bs index ea467672..7d48e716 100644 --- a/dom.bs +++ b/dom.bs @@ -5056,13 +5056,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 512ab18db258fb9036b49291d39f40e5cfd48a1e Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 30 Sep 2024 00:26:58 -0400 Subject: [PATCH 10/55] 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 7d48e716..3c568ec2 100644 --- a/dom.bs +++ b/dom.bs @@ -2679,6 +2679,24 @@ 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 + 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 @@ -2893,6 +2911,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. @@ -3911,7 +4037,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, @@ -5063,9 +5189,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}}.

          @@ -5073,7 +5198,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 2afc546e6c307957eb283d08ab3d7e2d4601f09a Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:34:32 -0400 Subject: [PATCH 11/55] Remove changes to insertion primitive --- dom.bs | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/dom.bs b/dom.bs index 3c568ec2..4f62c45c 100644 --- a/dom.bs +++ b/dom.bs @@ -2774,9 +2774,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. @@ -2785,8 +2782,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. @@ -2864,24 +2859,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 086207815272d802595a56876807d2791e3745e6 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:43:14 -0400 Subject: [PATCH 12/55] 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 4f62c45c..cc4277cd 100644 --- a/dom.bs +++ b/dom.bs @@ -2786,8 +2786,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. @@ -2899,9 +2899,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. @@ -2922,8 +2919,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. @@ -2979,17 +2975,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. @@ -3082,7 +3071,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.

          @@ -3109,7 +3098,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 @@ -3225,7 +3214,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. @@ -4014,14 +4003,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. @@ -4086,9 +4070,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. @@ -4101,28 +4085,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.

        @@ -4135,7 +4106,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; @@ -4170,10 +4140,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 @@ -4200,7 +4166,6 @@ interface MutationRecord {

        The type, target, addedNodes, removedNodes, -movedNodes, previousSibling, nextSibling, attributeName, @@ -5174,15 +5139,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.

      @@ -5775,8 +5734,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 c59a7e588d19bccdb0d34cdae8bb3d943ea8fa5b Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:44:11 -0400 Subject: [PATCH 13/55] Fix mutation record callsites --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index cc4277cd..b93b68ad 100644 --- a/dom.bs +++ b/dom.bs @@ -6624,7 +6624,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 @@ -7669,7 +7669,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 30fc53c95f1e6f1b3b36640f1882932a3ae28577 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:45:04 -0400 Subject: [PATCH 14/55] Fix wrapping --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index b93b68ad..bae4622a 100644 --- a/dom.bs +++ b/dom.bs @@ -2786,8 +2786,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 c53fba85dd0407b2577d2e6b0e033adb7ae83e30 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:48:36 -0400 Subject: [PATCH 15/55] Remove suppress observers flag --- dom.bs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/dom.bs b/dom.bs index bae4622a..a676b2ae 100644 --- a/dom.bs +++ b/dom.bs @@ -2896,7 +2896,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. @@ -2971,17 +2971,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 47e97f0b8191bd85e299c47792bd57604530397a Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 10:59:20 -0400 Subject: [PATCH 16/55] Custom element integration --- dom.bs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/dom.bs b/dom.bs index a676b2ae..0113f8e8 100644 --- a/dom.bs +++ b/dom.bs @@ -2952,13 +2952,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 75f5c75330e5339dbf16e85abe8504b38ff49471 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 11:22:11 -0400 Subject: [PATCH 17/55] 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 0113f8e8..385e86ce 100644 --- a/dom.bs +++ b/dom.bs @@ -2903,6 +2903,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: @@ -2919,8 +2949,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. @@ -2968,12 +2996,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 5aa8a7087d3e59777d7c8e4cd914f22f085250c1 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 10 Oct 2024 11:23:58 -0400 Subject: [PATCH 18/55] Correct removal bookkeeping --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index 385e86ce..a6a77302 100644 --- a/dom.bs +++ b/dom.bs @@ -2899,13 +2899,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). @@ -2930,7 +2930,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 fe7c678ed18a5cd5b89e39c0ee9ad310d228cbe7 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 14:30:43 -0400 Subject: [PATCH 19/55] Moving steps prose --- dom.bs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index a6a77302..268cee5b 100644 --- a/dom.bs +++ b/dom.bs @@ -2893,7 +2893,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 cfe40ffc6ebeff830fbca7e27ea6370d5976a9a9 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 16:23:00 -0400 Subject: [PATCH 20/55] Tighten up pre-move checks --- dom.bs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 268cee5b..4be76a02 100644 --- a/dom.bs +++ b/dom.bs @@ -2679,12 +2679,30 @@ steps:

    +

    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 1d0f90e5eb20e2f6a84b036cdb380d85ae8d451d Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 16:29:14 -0400 Subject: [PATCH 21/55] Assert -> throw condition --- dom.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 4be76a02..4ea3af39 100644 --- a/dom.bs +++ b/dom.bs @@ -2683,7 +2683,8 @@ steps: 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 abb3c4abc3ce477b7de1b0c5527d63586bd41e3a Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 16:42:13 -0400 Subject: [PATCH 22/55] 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 4ea3af39..be6effee 100644 --- a/dom.bs +++ b/dom.bs @@ -2682,7 +2682,13 @@ steps:

        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. @@ -5173,21 +5179,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 73bdd6dc6f1d01625ac2ec0d9dd4c738a1c69264 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 16:43:18 -0400 Subject: [PATCH 23/55] Fix `` --- dom.bs | 1 + 1 file changed, 1 insertion(+) diff --git a/dom.bs b/dom.bs index be6effee..8b35e4e8 100644 --- a/dom.bs +++ b/dom.bs @@ -2682,6 +2682,7 @@ steps:

          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 3ae1115f8d08d1afa149315b2a27b342458a9cf4 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 15 Oct 2024 21:03:45 -0400 Subject: [PATCH 24/55] Ordering and format --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index 8b35e4e8..27b94649 100644 --- a/dom.bs +++ b/dom.bs @@ -2690,15 +2690,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 45d089c8bf51c57e6befb23c0e261c3bc5c8ab00 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 7 Nov 2024 12:03:51 -0500 Subject: [PATCH 25/55] Fix live range updating logic --- dom.bs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/dom.bs b/dom.bs index 27b94649..47929bce 100644 --- a/dom.bs +++ b/dom.bs @@ -2937,16 +2937,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 @@ -3031,13 +3032,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 62cf625dfe29c2305077741c593ee5d12dc7880c Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 7 Nov 2024 12:08:44 -0500 Subject: [PATCH 26/55] 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 47929bce..cb86f11b 100644 --- a/dom.bs +++ b/dom.bs @@ -8287,8 +8287,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 457c410b3ba50adca19b403452c89d7e2cc87b6f Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 11 Nov 2024 10:33:46 -0500 Subject: [PATCH 27/55] 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 cb86f11b..8fb2b2e3 100644 --- a/dom.bs +++ b/dom.bs @@ -2690,8 +2690,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 41b1742ea2ccca9617dddbae454c266e8ff0fe41 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 13 Nov 2024 09:44:45 -0500 Subject: [PATCH 28/55] Do not explicitly rethrow --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index 8fb2b2e3..2b501d17 100644 --- a/dom.bs +++ b/dom.bs @@ -5175,7 +5175,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 fedd42b88e02e7c644d40a9d60ea5c40f0f5b295 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 19 Nov 2024 13:00:13 -0500 Subject: [PATCH 29/55] 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 2b501d17..554487ba 100644 --- a/dom.bs +++ b/dom.bs @@ -2937,17 +2937,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 cb549cacd4e8890b59ab1967a5966cfce8e0ff43 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 20 Nov 2024 10:20:13 -0500 Subject: [PATCH 30/55] 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 554487ba..c41ecf63 100644 --- a/dom.bs +++ b/dom.bs @@ -2683,8 +2683,20 @@ steps: 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 2bc92133d5d3ff4f595c3518e97bd9fa86aea08b Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 20 Nov 2024 10:23:08 -0500 Subject: [PATCH 31/55] Whitespace and formatting --- dom.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index c41ecf63..5528c4a4 100644 --- a/dom.bs +++ b/dom.bs @@ -2685,9 +2685,10 @@ of a node into a parent before a child, run the

          1. If any of the following conditions are true

            - + From f1cf1260e7b3b4b4674f4f7c64f976b93a12270d Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 13:52:38 -0500 Subject: [PATCH 32/55] 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 5528c4a4..b04a8ae2 100644 --- a/dom.bs +++ b/dom.bs @@ -2948,22 +2948,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 @@ -3193,22 +3178,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 @@ -8366,6 +8336,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 a40701df857231968ce1d51d6663ab38eb1ffe76 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 14:09:12 -0500 Subject: [PATCH 33/55] newParent, newPreviousSibling, and count --- dom.bs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/dom.bs b/dom.bs index b04a8ae2..88d3a1b9 100644 --- a/dom.bs +++ b/dom.bs @@ -2939,8 +2939,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:

              @@ -2966,31 +2966,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. @@ -3024,11 +3024,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 7bcdeb2b47692e90acd12d6bed961f1f2f52984c Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 14:34:38 -0500 Subject: [PATCH 34/55] 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 88d3a1b9..680dbbbe 100644 --- a/dom.bs +++ b/dom.bs @@ -3009,9 +3009,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 22ff396cb0c1c12988e15517d157695a14541684 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 14:48:32 -0500 Subject: [PATCH 35/55] Revert random editorial change --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 680dbbbe..c061a404 100644 --- a/dom.bs +++ b/dom.bs @@ -4123,8 +4123,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 9478d7fcb542b85647c0a59cde750bde4219de94 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 14:50:39 -0500 Subject: [PATCH 36/55] Remove newline --- dom.bs | 1 - 1 file changed, 1 deletion(-) diff --git a/dom.bs b/dom.bs index c061a404..0d2f545b 100644 --- a/dom.bs +++ b/dom.bs @@ -4264,7 +4264,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 fd643dcae206a3fe9326aeee03e68d46de6e9bc6 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Wed, 27 Nov 2024 15:28:06 -0500 Subject: [PATCH 37/55] Remove manual custom element upgrade --- dom.bs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/dom.bs b/dom.bs index 0d2f545b..d4fb94c7 100644 --- a/dom.bs +++ b/dom.bs @@ -3009,19 +3009,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 3d0651d752848ee334196ff4660e9545d292cca6 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 9 Dec 2024 17:34:30 -0500 Subject: [PATCH 38/55] 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 d4fb94c7..414a73b0 100644 --- a/dom.bs +++ b/dom.bs @@ -2699,9 +2699,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 f5c1e8338ade927a3156319c73a72090f1794645 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 10 Dec 2024 10:29:18 -0500 Subject: [PATCH 39/55] 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 414a73b0..01a70e12 100644 --- a/dom.bs +++ b/dom.bs @@ -2703,8 +2703,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 bc64f9a7362559335e81d0079c72cf06f00e3e71 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 10 Dec 2024 14:15:16 -0500 Subject: [PATCH 40/55] 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 01a70e12..beb4ecd2 100644 --- a/dom.bs +++ b/dom.bs @@ -2709,11 +2709,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 d6436f458b5b381388a9ec0ecf2425dce5573b85 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 09:06:31 -0500 Subject: [PATCH 41/55] 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 beb4ecd2..72c2584e 100644 --- a/dom.bs +++ b/dom.bs @@ -2684,25 +2684,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 41e8864577b845ccda6de0a2c36257c0ed23bc66 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 09:14:13 -0500 Subject: [PATCH 42/55] Live range rename --- dom.bs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dom.bs b/dom.bs index 72c2584e..a1b42d50 100644 --- a/dom.bs +++ b/dom.bs @@ -2946,11 +2946,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. @@ -3168,7 +3168,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 @@ -5139,7 +5139,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: @@ -8325,7 +8325,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 7c781c5afe44770ca76d94744e69c1c4924c4214 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 09:14:50 -0500 Subject: [PATCH 43/55] Empty arguments --- dom.bs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index a1b42d50..5aaf5419 100644 --- a/dom.bs +++ b/dom.bs @@ -3009,8 +3009,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 b0a10e48f629625bf13c5658af3e98aaa1dbc12b Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 09:51:58 -0500 Subject: [PATCH 44/55] 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 5aaf5419..195a7689 100644 --- a/dom.bs +++ b/dom.bs @@ -2707,7 +2707,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 21ee3c11319d513c9355a53bc037e4f292fc889a Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 10:37:05 -0500 Subject: [PATCH 45/55] Update dom.bs Co-authored-by: Anne van Kesteren From 3c8ba6d6921af634d7bf24e01402781a9a16d75e Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 10:39:39 -0500 Subject: [PATCH 46/55] Remove run these steps --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 195a7689..c0ee6647 100644 --- a/dom.bs +++ b/dom.bs @@ -2680,7 +2680,7 @@ steps:

    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. @@ -2718,7 +2718,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 c6aaaceb4ddbab280d91368b0761d377f2e86fb1 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Thu, 12 Dec 2024 11:01:44 -0500 Subject: [PATCH 47/55] 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 c0ee6647..759c739a 100644 --- a/dom.bs +++ b/dom.bs @@ -2692,9 +2692,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}}. @@ -3311,6 +3308,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); @@ -3359,6 +3357,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. @@ -4252,7 +4260,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 227fd9d35c6c8e81653c0b8116f155f5e0e8b4ea Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 13 Dec 2024 09:17:55 +0100 Subject: [PATCH 48/55] nits --- dom.bs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/dom.bs b/dom.bs index 759c739a..fa36fedc 100644 --- a/dom.bs +++ b/dom.bs @@ -2679,8 +2679,8 @@ steps:

      -

      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. @@ -2689,7 +2689,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 @@ -2712,10 +2712,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 @@ -2934,8 +2934,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:

          @@ -2958,7 +2958,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 @@ -3308,6 +3308,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); @@ -3420,6 +3421,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. @@ -5147,16 +5158,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 @@ -8331,7 +8332,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 145d726adf8265d2cba0b2e118ea5f956ee76a7e Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 13 Dec 2024 09:32:44 +0100 Subject: [PATCH 49/55] nit --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index fa36fedc..573a8b3a 100644 --- a/dom.bs +++ b/dom.bs @@ -5156,7 +5156,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 4b54a0d97778b4c5bfe406cadce29d8cc3a281d8 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 13 Dec 2024 09:38:26 +0100 Subject: [PATCH 50/55] 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 573a8b3a..18d13e96 100644 --- a/dom.bs +++ b/dom.bs @@ -5156,7 +5156,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 90d83391dfef67c2f0393acb2668b9c39bb01aab Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 16 Dec 2024 12:51:07 -0500 Subject: [PATCH 51/55] Make moveBefore() return undefined --- dom.bs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/dom.bs b/dom.bs index 18d13e96..ab453d5a 100644 --- a/dom.bs +++ b/dom.bs @@ -2714,23 +2714,6 @@ steps:

            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 @@ -3309,7 +3292,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); @@ -3425,10 +3408,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. Return result.

            5. +
            6. Let referenceChild be child. + +

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

            8. Move node into this before referenceChild.

            The querySelector(selectors) method From 8e1d36d238ac9a77948d57769640fd760ae7c5fd Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 17 Dec 2024 10:38:19 -0500 Subject: [PATCH 52/55] 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 ab453d5a..40ac7b12 100644 --- a/dom.bs +++ b/dom.bs @@ -2679,41 +2679,6 @@ steps:

          -

          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 @@ -2921,6 +2886,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. @@ -3408,8 +3400,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 bb1a060ad3c5c22b1b20b26537c4d9f9148ad551 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 17 Dec 2024 10:44:24 -0500 Subject: [PATCH 53/55] 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 40ac7b12..c27704f3 100644 --- a/dom.bs +++ b/dom.bs @@ -2888,30 +2888,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 f3f2ab22b0cfc632e576dd513a1e58bba6c61d12 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 17 Dec 2024 11:47:51 -0500 Subject: [PATCH 54/55] 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 c27704f3..f6a1f029 100644 --- a/dom.bs +++ b/dom.bs @@ -2873,7 +2873,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 32a8a683e49c2772d08a622413500f69d0455f3a Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Fri, 20 Dec 2024 09:46:46 -0500 Subject: [PATCH 55/55] 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 f6a1f029..9838b5ca 100644 --- a/dom.bs +++ b/dom.bs @@ -2932,6 +2932,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: