Re: [whatwg/dom] TreeWalker's nextNode() method can result in an infinite loop because the value of node never changes if it doesn't have a child (#667)

These are the steps proposed with 124d06d8f77a640d3cb501380563c1bcf38dc7c9 (differences from spec marked bold):

1. Let node be the context object’s current.
2. Let result be FILTER_ACCEPT.
3. While true:
    1. While result is not FILTER_REJECT and node has a child:
        1. Set node to its first child.
        2. Set result to the result of filtering node within the context object.
        3. If result is FILTER_ACCEPT, then set the context object’s current to node and return node.
    2. Let sibling be null.
    3. Let temporary be node.
    4. While temporary is non-null:
        1. If temporary is the context object’s root, then return null.
        2. Set sibling to temporary’s next sibling.
        3. If sibling is non-null, then __set node to sibling and__ break.
        4. Set temporary to temporary’s parent.
    6. Set result to the result of filtering node within the context object.
    7. If result is FILTER_ACCEPT, then set the context object’s current to node and return node.

And these are mozilla's steps (differences from spec marked bold):

1. Let node be the context object’s current.
2. Let result be FILTER_ACCEPT.
3. While true:
    1. While result is not FILTER_REJECT and node has a child:
        1. Set node to its first child.
        2. Set result to the result of filtering node within the context object.
        3. If result is FILTER_ACCEPT, then set the context object’s current to node and return node.
    2. Let sibling be null.
    3. Let temporary be node.
    4. While temporary is non-null:
        1. If temporary is the context object’s root, then __break__.
        2. Set sibling to temporary’s next sibling.
        3. If sibling is non-null, then break.
        4. Set temporary to temporary’s parent.
    5.  __If sibling is null, then break.__
    6.  __Set node to sibling__
    6. Set result to the result of filtering node within the context object.
    7. If result is FILTER_ACCEPT, then set the context object’s current to node and return node.
4.  __return null__

The cases where `temporary` and `sibling` are `null` are handled slightly differently, but both algorithms should produce identical results.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/667#issuecomment-480926881

Received on Monday, 8 April 2019 17:28:43 UTC