From af8b947b53ed5dd84fa4ac6076f25773ecc2e034 Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Thu, 10 Apr 2025 14:41:35 +0200 Subject: [PATCH 1/5] describeNode --- src/cdp/domains/dom.zig | 33 +++++++++++++++++++++++++++++++++ vendor/zig-js-runtime | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/cdp/domains/dom.zig b/src/cdp/domains/dom.zig index 80e6b96b..fe594fe0 100644 --- a/src/cdp/domains/dom.zig +++ b/src/cdp/domains/dom.zig @@ -30,6 +30,7 @@ pub fn processMessage(cmd: anytype) !void { getSearchResults, discardSearchResults, resolveNode, + describeNode, }, cmd.input.action) orelse return error.UnknownMethod; switch (action) { @@ -39,6 +40,7 @@ pub fn processMessage(cmd: anytype) !void { .getSearchResults => return getSearchResults(cmd), .discardSearchResults => return discardSearchResults(cmd), .resolveNode => return resolveNode(cmd), + .describeNode => return describeNode(cmd), } } @@ -148,6 +150,37 @@ fn resolveNode(cmd: anytype) !void { } }, .{}); } +fn describeNode(cmd: anytype) !void { + const params = (try cmd.params(struct { + nodeId: ?Node.Id = null, + backendNodeId: ?Node.Id = null, + objectId: ?[]const u8 = null, + depth: ?u32 = null, + pierce: ?bool = null, + })) orelse return error.InvalidParams; + if (params.backendNodeId != null or params.depth != null or params.pierce != null) { + return error.NotYetImplementedParams; + } + + const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded; + + if (params.nodeId != null) { + const node = bc.node_registry.lookup_by_id.get(params.nodeId.?) orelse return error.NodeNotFound; + return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{}) }, .{}); + } else if (params.objectId != null) { + const jsValue = try bc.session.inspector.getValueByObjectId(cmd.arena, params.objectId.?); + const entry = jsValue.externalEntry().?; + const sub_type = entry.sub_type.?; + + if (!std.mem.eql(u8, sub_type[0..std.mem.len(sub_type)], "node")) { + return error.ObjectIdIsNotANode; + } + const node = try bc.node_registry.register(@ptrCast(entry.ptr)); + return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{}) }, .{}); + } + return error.MissingParams; +} + const testing = @import("../testing.zig"); test "cdp.dom: getSearchResults unknown search id" { diff --git a/vendor/zig-js-runtime b/vendor/zig-js-runtime index 9b87782f..696cc726 160000 --- a/vendor/zig-js-runtime +++ b/vendor/zig-js-runtime @@ -1 +1 @@ -Subproject commit 9b87782f1edc0a3c4541f771d4ff443820fa38ac +Subproject commit 696cc72682c07e7ef3280dc142577fa5d3530fc6 From 1ce7bcffffa093486b69f64555565c1d67da164c Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Thu, 10 Apr 2025 15:11:19 +0200 Subject: [PATCH 2/5] write node using the correct 4 letters --- src/cdp/domains/dom.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cdp/domains/dom.zig b/src/cdp/domains/dom.zig index fe594fe0..d95a6e8a 100644 --- a/src/cdp/domains/dom.zig +++ b/src/cdp/domains/dom.zig @@ -166,7 +166,7 @@ fn describeNode(cmd: anytype) !void { if (params.nodeId != null) { const node = bc.node_registry.lookup_by_id.get(params.nodeId.?) orelse return error.NodeNotFound; - return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{}) }, .{}); + return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{}); } else if (params.objectId != null) { const jsValue = try bc.session.inspector.getValueByObjectId(cmd.arena, params.objectId.?); const entry = jsValue.externalEntry().?; @@ -176,7 +176,7 @@ fn describeNode(cmd: anytype) !void { return error.ObjectIdIsNotANode; } const node = try bc.node_registry.register(@ptrCast(entry.ptr)); - return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{}) }, .{}); + return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{}); } return error.MissingParams; } From 0c7d0ddff1526836a116d144a1ded777aa983c06 Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Fri, 11 Apr 2025 10:33:01 +0200 Subject: [PATCH 3/5] Give node the subtype "node" --- src/dom/attribute.zig | 1 + src/dom/cdata_section.zig | 1 + src/dom/character_data.zig | 1 + src/dom/comment.zig | 1 + src/dom/document.zig | 1 + src/dom/document_fragment.zig | 1 + src/dom/document_type.zig | 1 + src/dom/element.zig | 1 + src/dom/html_collection.zig | 2 + src/dom/node.zig | 1 + src/dom/text.zig | 1 + src/html/document.zig | 1 - src/html/elements.zig | 70 +++++++++++++++++++++++++++++++++++ src/html/history.zig | 1 + src/html/location.zig | 1 + src/html/navigator.zig | 1 + src/html/window.zig | 1 + vendor/zig-js-runtime | 2 +- 18 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/dom/attribute.zig b/src/dom/attribute.zig index d85f87a0..d3f5704b 100644 --- a/src/dom/attribute.zig +++ b/src/dom/attribute.zig @@ -32,6 +32,7 @@ pub const Attr = struct { pub const Self = parser.Attribute; pub const prototype = *Node; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn get_namespaceURI(self: *parser.Attribute) !?[]const u8 { return try parser.nodeGetNamespace(parser.attributeToNode(self)); diff --git a/src/dom/cdata_section.zig b/src/dom/cdata_section.zig index c8ff6107..8cd9140f 100644 --- a/src/dom/cdata_section.zig +++ b/src/dom/cdata_section.zig @@ -27,4 +27,5 @@ pub const CDATASection = struct { pub const Self = parser.CDATASection; pub const prototype = *Text; pub const mem_guarantied = true; + pub const sub_type = "node"; }; diff --git a/src/dom/character_data.zig b/src/dom/character_data.zig index 372395c2..ed53d949 100644 --- a/src/dom/character_data.zig +++ b/src/dom/character_data.zig @@ -43,6 +43,7 @@ pub const CharacterData = struct { pub const Self = parser.CharacterData; pub const prototype = *Node; pub const mem_guarantied = true; + pub const sub_type = "node"; // JS funcs // -------- diff --git a/src/dom/comment.zig b/src/dom/comment.zig index fe4111bc..b9dd7471 100644 --- a/src/dom/comment.zig +++ b/src/dom/comment.zig @@ -32,6 +32,7 @@ pub const Comment = struct { pub const Self = parser.Comment; pub const prototype = *CharacterData; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn constructor(userctx: UserContext, data: ?[]const u8) !*parser.Comment { return parser.documentCreateComment( diff --git a/src/dom/document.zig b/src/dom/document.zig index 0b8d0cd8..2c164cfe 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -46,6 +46,7 @@ pub const Document = struct { pub const Self = parser.Document; pub const prototype = *Node; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn constructor(userctx: UserContext) !*parser.DocumentHTML { const doc = try parser.documentCreateDocument( diff --git a/src/dom/document_fragment.zig b/src/dom/document_fragment.zig index 574e8eb1..ff69eedd 100644 --- a/src/dom/document_fragment.zig +++ b/src/dom/document_fragment.zig @@ -33,6 +33,7 @@ pub const DocumentFragment = struct { pub const Self = parser.DocumentFragment; pub const prototype = *Node; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn constructor(userctx: UserContext) !*parser.DocumentFragment { return parser.documentCreateDocumentFragment( diff --git a/src/dom/document_type.zig b/src/dom/document_type.zig index cd40a732..509a9961 100644 --- a/src/dom/document_type.zig +++ b/src/dom/document_type.zig @@ -27,6 +27,7 @@ pub const DocumentType = struct { pub const Self = parser.DocumentType; pub const prototype = *Node; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn get_name(self: *parser.DocumentType) ![]const u8 { return try parser.documentTypeGetName(self); diff --git a/src/dom/element.zig b/src/dom/element.zig index 0453a283..ddff8d9e 100644 --- a/src/dom/element.zig +++ b/src/dom/element.zig @@ -43,6 +43,7 @@ pub const Element = struct { pub const Self = parser.Element; pub const prototype = *Node; pub const mem_guarantied = true; + pub const sub_type = "node"; pub const DOMRect = struct { x: f64, diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index 298d6b72..e5f7c469 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -280,6 +280,7 @@ pub fn HTMLCollectionByAnchors( pub const HTMLCollectionIterator = struct { pub const mem_guarantied = true; + pub const sub_type = "node"; coll: *HTMLCollection, index: u32 = 0, @@ -312,6 +313,7 @@ pub const HTMLCollectionIterator = struct { // But we wanted a dynamically comparison here, according to the match tagname. pub const HTMLCollection = struct { pub const mem_guarantied = true; + pub const sub_type = "node"; matcher: Matcher, walker: Walker, diff --git a/src/dom/node.zig b/src/dom/node.zig index 3e0a7561..44d69189 100644 --- a/src/dom/node.zig +++ b/src/dom/node.zig @@ -67,6 +67,7 @@ pub const Node = struct { pub const Self = parser.Node; pub const prototype = *EventTarget; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn toInterface(node: *parser.Node) !Union { return switch (try parser.nodeType(node)) { diff --git a/src/dom/text.zig b/src/dom/text.zig index a2d3f9cf..d1622349 100644 --- a/src/dom/text.zig +++ b/src/dom/text.zig @@ -38,6 +38,7 @@ pub const Text = struct { pub const Self = parser.Text; pub const prototype = *CharacterData; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn constructor(userctx: UserContext, data: ?[]const u8) !*parser.Text { return parser.documentCreateTextNode( diff --git a/src/html/document.zig b/src/html/document.zig index 11d16c3e..e908b461 100644 --- a/src/html/document.zig +++ b/src/html/document.zig @@ -38,7 +38,6 @@ pub const HTMLDocument = struct { pub const Self = parser.DocumentHTML; pub const prototype = *Document; pub const mem_guarantied = true; - pub const sub_type = "node"; // JS funcs diff --git a/src/html/elements.zig b/src/html/elements.zig index d0ff13a4..7b00f0e9 100644 --- a/src/html/elements.zig +++ b/src/html/elements.zig @@ -107,12 +107,14 @@ pub const Union = generate.Union(Interfaces); const CSSProperties = struct { pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLElement = struct { pub const Self = parser.ElementHTML; pub const prototype = *Element; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn get_style(_: *parser.ElementHTML) CSSProperties { return .{}; @@ -149,6 +151,7 @@ pub const HTMLMediaElement = struct { pub const Self = parser.MediaElement; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; // HTML elements @@ -158,6 +161,7 @@ pub const HTMLUnknownElement = struct { pub const Self = parser.Unknown; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; // https://html.spec.whatwg.org/#the-a-element @@ -165,6 +169,7 @@ pub const HTMLAnchorElement = struct { pub const Self = parser.Anchor; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn get_target(self: *parser.Anchor) ![]const u8 { return try parser.anchorGetTarget(self); @@ -446,276 +451,323 @@ pub const HTMLAppletElement = struct { pub const Self = parser.Applet; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLAreaElement = struct { pub const Self = parser.Area; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLAudioElement = struct { pub const Self = parser.Audio; pub const prototype = *HTMLMediaElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLBRElement = struct { pub const Self = parser.BR; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLBaseElement = struct { pub const Self = parser.Base; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLBodyElement = struct { pub const Self = parser.Body; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLButtonElement = struct { pub const Self = parser.Button; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLCanvasElement = struct { pub const Self = parser.Canvas; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLDListElement = struct { pub const Self = parser.DList; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLDataElement = struct { pub const Self = parser.Data; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLDataListElement = struct { pub const Self = parser.DataList; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLDialogElement = struct { pub const Self = parser.Dialog; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLDirectoryElement = struct { pub const Self = parser.Directory; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLDivElement = struct { pub const Self = parser.Div; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLEmbedElement = struct { pub const Self = parser.Embed; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLFieldSetElement = struct { pub const Self = parser.FieldSet; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLFontElement = struct { pub const Self = parser.Font; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLFormElement = struct { pub const Self = parser.Form; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLFrameElement = struct { pub const Self = parser.Frame; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLFrameSetElement = struct { pub const Self = parser.FrameSet; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLHRElement = struct { pub const Self = parser.HR; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLHeadElement = struct { pub const Self = parser.Head; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLHeadingElement = struct { pub const Self = parser.Heading; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLHtmlElement = struct { pub const Self = parser.Html; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; + pub const sub_type = "node"; }; pub const HTMLIFrameElement = struct { pub const Self = parser.IFrame; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLImageElement = struct { pub const Self = parser.Image; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLInputElement = struct { pub const Self = parser.Input; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLLIElement = struct { pub const Self = parser.LI; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLLabelElement = struct { pub const Self = parser.Label; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLLegendElement = struct { pub const Self = parser.Legend; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLLinkElement = struct { pub const Self = parser.Link; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLMapElement = struct { pub const Self = parser.Map; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLMetaElement = struct { pub const Self = parser.Meta; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLMeterElement = struct { pub const Self = parser.Meter; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLModElement = struct { pub const Self = parser.Mod; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLOListElement = struct { pub const Self = parser.OList; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLObjectElement = struct { pub const Self = parser.Object; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLOptGroupElement = struct { pub const Self = parser.OptGroup; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLOptionElement = struct { pub const Self = parser.Option; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLOutputElement = struct { pub const Self = parser.Output; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLParagraphElement = struct { pub const Self = parser.Paragraph; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLParamElement = struct { pub const Self = parser.Param; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLPictureElement = struct { pub const Self = parser.Picture; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLPreElement = struct { pub const Self = parser.Pre; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLProgressElement = struct { pub const Self = parser.Progress; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLQuoteElement = struct { pub const Self = parser.Quote; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; // https://html.spec.whatwg.org/#the-script-element @@ -723,6 +775,7 @@ pub const HTMLScriptElement = struct { pub const Self = parser.Script; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; pub fn get_src(self: *parser.Script) !?[]const u8 { return try parser.elementGetAttribute( @@ -838,102 +891,119 @@ pub const HTMLSelectElement = struct { pub const Self = parser.Select; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLSourceElement = struct { pub const Self = parser.Source; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLSpanElement = struct { pub const Self = parser.Span; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLStyleElement = struct { pub const Self = parser.Style; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTableElement = struct { pub const Self = parser.Table; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTableCaptionElement = struct { pub const Self = parser.TableCaption; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTableCellElement = struct { pub const Self = parser.TableCell; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTableColElement = struct { pub const Self = parser.TableCol; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTableRowElement = struct { pub const Self = parser.TableRow; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTableSectionElement = struct { pub const Self = parser.TableSection; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTemplateElement = struct { pub const Self = parser.Template; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTextAreaElement = struct { pub const Self = parser.TextArea; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTimeElement = struct { pub const Self = parser.Time; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTitleElement = struct { pub const Self = parser.Title; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLTrackElement = struct { pub const Self = parser.Track; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLUListElement = struct { pub const Self = parser.UList; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub const HTMLVideoElement = struct { pub const Self = parser.Video; pub const prototype = *HTMLElement; pub const mem_guarantied = true; + pub const sub_type = "node"; }; pub fn toInterface(comptime T: type, e: *parser.Element) !T { diff --git a/src/html/history.zig b/src/html/history.zig index f3e96dc0..962a51ea 100644 --- a/src/html/history.zig +++ b/src/html/history.zig @@ -27,6 +27,7 @@ const checkCases = jsruntime.test_utils.checkCases; // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-history-interface pub const History = struct { pub const mem_guarantied = true; + pub const sub_type = "node"; const ScrollRestorationMode = enum { auto, diff --git a/src/html/location.zig b/src/html/location.zig index 95a62dae..cc3df049 100644 --- a/src/html/location.zig +++ b/src/html/location.zig @@ -29,6 +29,7 @@ const checkCases = jsruntime.test_utils.checkCases; // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-location-interface pub const Location = struct { pub const mem_guarantied = true; + pub const sub_type = "node"; url: ?URL = null, diff --git a/src/html/navigator.zig b/src/html/navigator.zig index aebb7b19..2a65ce42 100644 --- a/src/html/navigator.zig +++ b/src/html/navigator.zig @@ -27,6 +27,7 @@ const checkCases = jsruntime.test_utils.checkCases; // https://html.spec.whatwg.org/multipage/system-state.html#navigator pub const Navigator = struct { pub const mem_guarantied = true; + pub const sub_type = "node"; agent: []const u8 = "Lightpanda/1.0", version: []const u8 = "1.0", diff --git a/src/html/window.zig b/src/html/window.zig index 36b580ba..358cd631 100644 --- a/src/html/window.zig +++ b/src/html/window.zig @@ -37,6 +37,7 @@ const storage = @import("../storage/storage.zig"); pub const Window = struct { pub const prototype = *EventTarget; pub const mem_guarantied = true; + pub const sub_type = "node"; pub const global_type = true; // Extend libdom event target for pure zig struct. diff --git a/vendor/zig-js-runtime b/vendor/zig-js-runtime index 696cc726..b59ab4ec 160000 --- a/vendor/zig-js-runtime +++ b/vendor/zig-js-runtime @@ -1 +1 @@ -Subproject commit 696cc72682c07e7ef3280dc142577fa5d3530fc6 +Subproject commit b59ab4ec7b8ef6d73f8535fff04d3e99de46f09e From f13c1d89fa341a5f35dfe149df53d74d67b9e7ce Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Fri, 11 Apr 2025 10:34:02 +0200 Subject: [PATCH 4/5] remove duplicate subtype --- src/html/elements.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/src/html/elements.zig b/src/html/elements.zig index 7b00f0e9..d17c2f62 100644 --- a/src/html/elements.zig +++ b/src/html/elements.zig @@ -613,7 +613,6 @@ pub const HTMLHtmlElement = struct { pub const prototype = *HTMLElement; pub const mem_guarantied = true; pub const sub_type = "node"; - pub const sub_type = "node"; }; pub const HTMLIFrameElement = struct { From 1734cb8579db2eef83c550797fcdd90623f08997 Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Fri, 11 Apr 2025 13:00:15 +0200 Subject: [PATCH 5/5] set defaults and unblock unittests --- src/cdp/domains/dom.zig | 15 +++++++-------- src/cdp/testing.zig | 22 ++++++++++++++++++++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/cdp/domains/dom.zig b/src/cdp/domains/dom.zig index d95a6e8a..d7b14feb 100644 --- a/src/cdp/domains/dom.zig +++ b/src/cdp/domains/dom.zig @@ -155,10 +155,10 @@ fn describeNode(cmd: anytype) !void { nodeId: ?Node.Id = null, backendNodeId: ?Node.Id = null, objectId: ?[]const u8 = null, - depth: ?u32 = null, - pierce: ?bool = null, + depth: u32 = 1, + pierce: bool = false, })) orelse return error.InvalidParams; - if (params.backendNodeId != null or params.depth != null or params.pierce != null) { + if (params.backendNodeId != null or params.depth != 1 or params.pierce) { return error.NotYetImplementedParams; } @@ -169,12 +169,11 @@ fn describeNode(cmd: anytype) !void { return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{}); } else if (params.objectId != null) { const jsValue = try bc.session.inspector.getValueByObjectId(cmd.arena, params.objectId.?); - const entry = jsValue.externalEntry().?; - const sub_type = entry.sub_type.?; - if (!std.mem.eql(u8, sub_type[0..std.mem.len(sub_type)], "node")) { - return error.ObjectIdIsNotANode; - } + const entry = jsValue.externalEntry() orelse return error.ObjectIdIsNotANode; + const sub_type = entry.sub_type orelse return error.ObjectIdIsNotANode; + if (!std.mem.eql(u8, sub_type[0..std.mem.len(sub_type)], "node")) return error.ObjectIdIsNotANode; + const node = try bc.node_registry.register(@ptrCast(entry.ptr)); return cmd.sendResult(.{ .node = bc.nodeWriter(node, .{}) }, .{}); } diff --git a/src/cdp/testing.zig b/src/cdp/testing.zig index c2c833e3..82dc6041 100644 --- a/src/cdp/testing.zig +++ b/src/cdp/testing.zig @@ -107,10 +107,22 @@ const Session = struct { } }; +const Value = struct { + pub fn externalEntry(self: Value) ?*ExternalEntry { + _ = self; + return allocator.create(ExternalEntry) catch unreachable; + } +}; +const ExternalEntry = struct { + ptr: *anyopaque, + sub_type: [*c]const u8 = null, +}; + const Env = struct { - pub fn findOrAddValue(self: *Env, value: anytype) !@TypeOf(value) { // ? + pub fn findOrAddValue(self: *Env, value: anytype) !Value { _ = self; - return value; + _ = value; + return .{}; } }; @@ -122,6 +134,12 @@ const Inspector = struct { _ = groupName; return RemoteObject{}; } + pub fn getValueByObjectId(self: Inspector, alloc: std.mem.Allocator, object_id: []const u8) !Value { + _ = self; + _ = alloc; + _ = object_id; + return .{}; + } }; const RemoteObject = struct {