Lazily load nodes

Node registry now only tracks the node id (which we need to be consistent) and
the underlying parser.Node. All other data is loaded on-demand (i.e. when we
serialize the node). This allows us to serialize node values as they appear
when they are serialized, as opposed to when they are registered.
This commit is contained in:
Karl Seguin
2025-04-04 11:24:34 +08:00
parent 68d1be3b94
commit 4d075818f6
3 changed files with 154 additions and 132 deletions

View File

@@ -51,7 +51,7 @@ fn getDocument(cmd: anytype) !void {
const doc = page.doc orelse return error.DocumentNotLoaded;
const node = try bc.node_registry.register(parser.documentToNode(doc));
return cmd.sendResult(.{ .root = node.writer(.{}) }, .{});
return cmd.sendResult(bc.nodeWriter(node, .{}), .{});
}
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-performSearch
@@ -148,7 +148,7 @@ test "cdp.dom: search flow" {
.method = "DOM.getSearchResults",
.params = .{ .searchId = "0", .fromIndex = 0, .toIndex = 2 },
});
try ctx.expectSentResult(.{ .nodeIds = &.{ 0, 2 } }, .{ .id = 13 });
try ctx.expectSentResult(.{ .nodeIds = &.{ 0, 1 } }, .{ .id = 13 });
// different fromIndex
try ctx.processMessage(.{
@@ -156,7 +156,7 @@ test "cdp.dom: search flow" {
.method = "DOM.getSearchResults",
.params = .{ .searchId = "0", .fromIndex = 1, .toIndex = 2 },
});
try ctx.expectSentResult(.{ .nodeIds = &.{2} }, .{ .id = 14 });
try ctx.expectSentResult(.{ .nodeIds = &.{1} }, .{ .id = 14 });
// different toIndex
try ctx.processMessage(.{