enum as subtype
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled

This commit is contained in:
sjorsdonkers
2025-04-18 12:03:43 +02:00
committed by Sjors
parent 1cd3ebfc3f
commit 16a30fa3b7
14 changed files with 81 additions and 83 deletions

View File

@@ -27,7 +27,7 @@ const DOMException = @import("exceptions.zig").DOMException;
pub const Attr = struct {
pub const Self = parser.Attribute;
pub const prototype = *Node;
pub const subtype = "node";
pub const subtype = .node;
pub fn get_namespaceURI(self: *parser.Attribute) !?[]const u8 {
return try parser.nodeGetNamespace(parser.attributeToNode(self));

View File

@@ -26,5 +26,5 @@ const Text = @import("text.zig").Text;
pub const CDATASection = struct {
pub const Self = parser.CDATASection;
pub const prototype = *Text;
pub const subtype = "node";
pub const subtype = .node;
};

View File

@@ -38,7 +38,7 @@ pub const Interfaces = .{
pub const CharacterData = struct {
pub const Self = parser.CharacterData;
pub const prototype = *Node;
pub const subtype = "node";
pub const subtype = .node;
// JS funcs
// --------

View File

@@ -27,7 +27,7 @@ const SessionState = @import("../env.zig").SessionState;
pub const Comment = struct {
pub const Self = parser.Comment;
pub const prototype = *CharacterData;
pub const subtype = "node";
pub const subtype = .node;
pub fn constructor(data: ?[]const u8, state: *const SessionState) !*parser.Comment {
return parser.documentCreateComment(

View File

@@ -39,7 +39,7 @@ const DOMImplementation = @import("implementation.zig").DOMImplementation;
pub const Document = struct {
pub const Self = parser.Document;
pub const prototype = *Node;
pub const subtype = "node";
pub const subtype = .node;
pub fn constructor(state: *const SessionState) !*parser.DocumentHTML {
const doc = try parser.documentCreateDocument(

View File

@@ -27,7 +27,7 @@ const Node = @import("node.zig").Node;
pub const DocumentFragment = struct {
pub const Self = parser.DocumentFragment;
pub const prototype = *Node;
pub const subtype = "node";
pub const subtype = .node;
pub fn constructor(state: *const SessionState) !*parser.DocumentFragment {
return parser.documentCreateDocumentFragment(

View File

@@ -26,7 +26,7 @@ const Node = @import("node.zig").Node;
pub const DocumentType = struct {
pub const Self = parser.DocumentType;
pub const prototype = *Node;
pub const subtype = "node";
pub const subtype = .node;
pub fn get_name(self: *parser.DocumentType) ![]const u8 {
return try parser.documentTypeGetName(self);

View File

@@ -37,7 +37,7 @@ const DOMException = @import("exceptions.zig").DOMException;
pub const Element = struct {
pub const Self = parser.Element;
pub const prototype = *Node;
pub const subtype = "node";
pub const subtype = .node;
pub const DOMRect = struct {
x: f64,

View File

@@ -60,7 +60,7 @@ pub const Union = generate.Union(Interfaces);
pub const Node = struct {
pub const Self = parser.Node;
pub const prototype = *EventTarget;
pub const subtype = "node";
pub const subtype = .node;
pub fn toInterface(node: *parser.Node) !Union {
return switch (try parser.nodeType(node)) {

View File

@@ -28,7 +28,7 @@ pub const ProcessingInstruction = struct {
// TODO for libdom processing instruction inherit from node.
// But the spec says it must inherit from CDATA.
pub const prototype = *Node;
pub const subtype = "node";
pub const subtype = .node;
pub fn get_target(self: *parser.ProcessingInstruction) ![]const u8 {
// libdom stores the ProcessingInstruction target in the node's name.

View File

@@ -32,7 +32,7 @@ pub const Interfaces = .{
pub const Text = struct {
pub const Self = parser.Text;
pub const prototype = *CharacterData;
pub const subtype = "node";
pub const subtype = .node;
pub fn constructor(data: ?[]const u8, state: *const SessionState) !*parser.Text {
return parser.documentCreateTextNode(

View File

@@ -35,7 +35,7 @@ const Cookie = @import("../storage/cookie.zig").Cookie;
pub const HTMLDocument = struct {
pub const Self = parser.DocumentHTML;
pub const prototype = *Document;
pub const subtype = "node";
pub const subtype = .node;
// JS funcs
// --------

View File

@@ -107,7 +107,7 @@ const CSSProperties = struct {};
pub const HTMLElement = struct {
pub const Self = parser.ElementHTML;
pub const prototype = *Element;
pub const subtype = "node";
pub const subtype = .node;
pub fn get_style(_: *parser.ElementHTML) CSSProperties {
return .{};
@@ -143,7 +143,7 @@ pub const HTMLElement = struct {
pub const HTMLMediaElement = struct {
pub const Self = parser.MediaElement;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
// HTML elements
@@ -152,14 +152,14 @@ pub const HTMLMediaElement = struct {
pub const HTMLUnknownElement = struct {
pub const Self = parser.Unknown;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
// https://html.spec.whatwg.org/#the-a-element
pub const HTMLAnchorElement = struct {
pub const Self = parser.Anchor;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
pub fn get_target(self: *parser.Anchor) ![]const u8 {
return try parser.anchorGetTarget(self);
@@ -405,284 +405,284 @@ pub const HTMLAnchorElement = struct {
pub const HTMLAppletElement = struct {
pub const Self = parser.Applet;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLAreaElement = struct {
pub const Self = parser.Area;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLAudioElement = struct {
pub const Self = parser.Audio;
pub const prototype = *HTMLMediaElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLBRElement = struct {
pub const Self = parser.BR;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLBaseElement = struct {
pub const Self = parser.Base;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLBodyElement = struct {
pub const Self = parser.Body;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLButtonElement = struct {
pub const Self = parser.Button;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLCanvasElement = struct {
pub const Self = parser.Canvas;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLDListElement = struct {
pub const Self = parser.DList;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLDataElement = struct {
pub const Self = parser.Data;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLDataListElement = struct {
pub const Self = parser.DataList;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLDialogElement = struct {
pub const Self = parser.Dialog;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLDirectoryElement = struct {
pub const Self = parser.Directory;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLDivElement = struct {
pub const Self = parser.Div;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLEmbedElement = struct {
pub const Self = parser.Embed;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLFieldSetElement = struct {
pub const Self = parser.FieldSet;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLFontElement = struct {
pub const Self = parser.Font;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLFormElement = struct {
pub const Self = parser.Form;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLFrameElement = struct {
pub const Self = parser.Frame;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLFrameSetElement = struct {
pub const Self = parser.FrameSet;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLHRElement = struct {
pub const Self = parser.HR;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLHeadElement = struct {
pub const Self = parser.Head;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLHeadingElement = struct {
pub const Self = parser.Heading;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLHtmlElement = struct {
pub const Self = parser.Html;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLIFrameElement = struct {
pub const Self = parser.IFrame;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLImageElement = struct {
pub const Self = parser.Image;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLInputElement = struct {
pub const Self = parser.Input;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLLIElement = struct {
pub const Self = parser.LI;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLLabelElement = struct {
pub const Self = parser.Label;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLLegendElement = struct {
pub const Self = parser.Legend;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLLinkElement = struct {
pub const Self = parser.Link;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLMapElement = struct {
pub const Self = parser.Map;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLMetaElement = struct {
pub const Self = parser.Meta;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLMeterElement = struct {
pub const Self = parser.Meter;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLModElement = struct {
pub const Self = parser.Mod;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLOListElement = struct {
pub const Self = parser.OList;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLObjectElement = struct {
pub const Self = parser.Object;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLOptGroupElement = struct {
pub const Self = parser.OptGroup;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLOptionElement = struct {
pub const Self = parser.Option;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLOutputElement = struct {
pub const Self = parser.Output;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLParagraphElement = struct {
pub const Self = parser.Paragraph;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLParamElement = struct {
pub const Self = parser.Param;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLPictureElement = struct {
pub const Self = parser.Picture;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLPreElement = struct {
pub const Self = parser.Pre;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLProgressElement = struct {
pub const Self = parser.Progress;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLQuoteElement = struct {
pub const Self = parser.Quote;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
// https://html.spec.whatwg.org/#the-script-element
pub const HTMLScriptElement = struct {
pub const Self = parser.Script;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
pub fn get_src(self: *parser.Script) !?[]const u8 {
return try parser.elementGetAttribute(
@@ -797,103 +797,103 @@ pub const HTMLScriptElement = struct {
pub const HTMLSelectElement = struct {
pub const Self = parser.Select;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLSourceElement = struct {
pub const Self = parser.Source;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLSpanElement = struct {
pub const Self = parser.Span;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLStyleElement = struct {
pub const Self = parser.Style;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTableElement = struct {
pub const Self = parser.Table;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTableCaptionElement = struct {
pub const Self = parser.TableCaption;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTableCellElement = struct {
pub const Self = parser.TableCell;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTableColElement = struct {
pub const Self = parser.TableCol;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTableRowElement = struct {
pub const Self = parser.TableRow;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTableSectionElement = struct {
pub const Self = parser.TableSection;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTemplateElement = struct {
pub const Self = parser.Template;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTextAreaElement = struct {
pub const Self = parser.TextArea;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTimeElement = struct {
pub const Self = parser.Time;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTitleElement = struct {
pub const Self = parser.Title;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLTrackElement = struct {
pub const Self = parser.Track;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLUListElement = struct {
pub const Self = parser.UList;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub const HTMLVideoElement = struct {
pub const Self = parser.Video;
pub const prototype = *HTMLElement;
pub const subtype = "node";
pub const subtype = .node;
};
pub fn toInterface(comptime T: type, e: *parser.Element) !T {

View File

@@ -96,9 +96,7 @@ pub fn Env(comptime S: type, comptime types: anytype) type {
@compileError(std.fmt.comptimePrint("Prototype '{s}' for type '{s} must be a pointer", .{ @typeName(Struct.prototype), @typeName(Struct) }));
}
@setEvalBranchQuota(40_000); // The number of branches increases as we get more structs with the subtype field
const subtype: ?SubType =
if (@hasDecl(Struct, "subtype")) std.meta.stringToEnum(SubType, Struct.subtype) else null;
const subtype: ?SubType = if (@hasDecl(Struct, "subtype")) Struct.subtype else null;
const R = Receiver(@field(types, s.name));
fields[i] = .{