mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-12-01 08:06:00 -10:00
The inspector's DocumentWalker had several issues when trying to retrieve children for a given node, especially if the starting node was filtered out by the filter function of the walker. If the starting node was provided by options.center or options.start and if this starting node was filtered out by the walker's filter then the walker would fallback to the first valid parent of this node. eg with parent1 > parent2 > [valid-node, invalid-node, valid-node] When asking for the children of parent2, if the walker started on "invalid-node", then the walker would instead use parent2 and in turn we would retrieve the children of parent 1 To fix that we can either tell the walker wether it should fallback to a sibling of the starting node or to a parent, or make sure that the nodes provided to the walker are valid. A second issue was with the utility methods _readForward and _readBackward. They both use the next/previousSibling() methods of a walker in order to collect all the valid siblings of the walker's current node. But they were always including the current node of the walker in their return array. And there is no guarantee that the walker's currentNode is actually valid for it's filter. eg with a walker containing [invalid-node-1, invalid-node-2, valid-node]. Let's say the walker is currently on valid-node and we call previousSibling The walker will do 3 steps: - this.walker.previousSibling() > returns invalid-node-2, fails filtering - this.walker.previousSibling() > returns invalid-node-1, fails filtering - this.walker.previousSibling() > returns null, stop looping and return null But at this stage the internal walker still points to the last visited node (invalid-node-1). So if _readForward/Backward blindly add the current node of the walker, we might be returning invalid nodes. MozReview-Commit-ID: 72Be7DP5ky6