cdp: add comments on setChildNodes event

Co-authored-by: Karl Seguin <karlseguin@users.noreply.github.com>
This commit is contained in:
Pierre Tachoire
2025-05-05 08:48:04 +02:00
committed by GitHub
parent f884627927
commit 2402443dcc

View File

@@ -113,9 +113,14 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
if (plen == 0) return; if (plen == 0) return;
var i: usize = plen; var i: usize = plen;
// We're going to iterate in reverse order from how we added them.
// This ensures that we're emitting the tree of nodes top-down.
while (i > 0) { while (i > 0) {
i -= 1; i -= 1;
const node = parents.items[i]; const node = parents.items[i];
// Although our above loop won't add an already-sent node to `parents`
// this can still be true because two nodes can share the same parent node
// so we might have just sent the node a previous iteration of this loop
if (node.set_child_nodes_event) continue; if (node.set_child_nodes_event) continue;
node.set_child_nodes_event = true; node.set_child_nodes_event = true;