Skip to content

Commit 282a9bb

Browse files
committed
return *Document instead of tagged union in parseFromString
Did a detour to XML PR and realized this is simpler.
1 parent 060afcd commit 282a9bb

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/browser/webapi/DOMParser.zig

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const Parser = @import("../parser/Parser.zig");
2525

2626
const HTMLDocument = @import("HTMLDocument.zig");
2727
const XMLDocument = @import("XMLDocument.zig");
28+
const Document = @import("Document.zig");
2829
const ProcessingInstruction = @import("../webapi/cdata/ProcessingInstruction.zig");
2930

3031
const DOMParser = @This();
@@ -33,26 +34,21 @@ pub fn init() DOMParser {
3334
return .{};
3435
}
3536

36-
pub const HTMLDocumentOrXMLDocument = union(enum) {
37-
html_document: *HTMLDocument,
38-
xml_document: *XMLDocument,
39-
};
40-
4137
pub fn parseFromString(
4238
_: *const DOMParser,
4339
html: []const u8,
4440
mime_type: []const u8,
4541
page: *Page,
46-
) !HTMLDocumentOrXMLDocument {
47-
const maybe_target_mime = std.meta.stringToEnum(enum {
42+
) !*Document {
43+
const target_mime = std.meta.stringToEnum(enum {
4844
@"text/html",
4945
@"text/xml",
5046
@"application/xml",
5147
@"application/xhtml+xml",
5248
@"image/svg+xml",
53-
}, mime_type);
49+
}, mime_type) orelse return error.NotSupported;
5450

55-
if (maybe_target_mime) |target_mime| switch (target_mime) {
51+
return switch (target_mime) {
5652
.@"text/html" => {
5753
// Create a new HTMLDocument
5854
const doc = try page._factory.document(HTMLDocument{
@@ -72,7 +68,7 @@ pub fn parseFromString(
7268
return pe.err;
7369
}
7470

75-
return .{ .html_document = doc };
71+
return doc.asDocument();
7672
},
7773
else => {
7874
// Create a new XMLDocument.
@@ -100,11 +96,9 @@ pub fn parseFromString(
10096
_ = doc_node.removeChild(first_child, page) catch unreachable;
10197
}
10298

103-
return .{ .xml_document = doc };
99+
return doc.asDocument();
104100
},
105101
};
106-
107-
return error.NotSupported;
108102
}
109103

110104
pub const JsApi = struct {

0 commit comments

Comments
 (0)