From a64d920f11360c297f8343d959e03ae9f34beb99 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 20 Nov 2023 15:24:23 +0100 Subject: [PATCH] dom: add document.doctype getter --- src/dom/document.zig | 6 ++++++ src/netsurf.zig | 6 ++++++ tests/wpt/dom/nodes/Document-doctype.html | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/wpt/dom/nodes/Document-doctype.html diff --git a/src/dom/document.zig b/src/dom/document.zig index b889169b..8a3ce44e 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -12,6 +12,8 @@ const HTMLCollection = @import("html_collection.zig").HTMLCollection; const Element = @import("element.zig").Element; const ElementUnion = @import("element.zig").Union; +const DocumentType = @import("document_type.zig").DocumentType; + // WEB IDL https://dom.spec.whatwg.org/#document pub const Document = struct { pub const Self = parser.Document; @@ -25,6 +27,10 @@ pub const Document = struct { // JS funcs // -------- + // + pub fn get_doctype(self: *parser.Document) ?*parser.DocumentType { + return parser.documentGetDoctype(self); + } pub fn _getElementById(self: *parser.Document, id: []const u8) ?ElementUnion { const e = parser.documentGetElementById(self, id) orelse return null; diff --git a/src/netsurf.zig b/src/netsurf.zig index cbdb1b81..d0fd671d 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -783,6 +783,12 @@ pub inline fn documentCreateElementNS(doc: *Document, ns: []const u8, tag_name: return elem.?; } +pub inline fn documentGetDoctype(doc: *Document) ?*DocumentType { + var dt: ?*DocumentType = undefined; + _ = documentVtable(doc).dom_document_get_doctype.?(doc, &dt); + return dt; +} + // DocumentHTML pub const DocumentHTML = c.dom_html_document; diff --git a/tests/wpt/dom/nodes/Document-doctype.html b/tests/wpt/dom/nodes/Document-doctype.html new file mode 100644 index 00000000..75bfd850 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-doctype.html @@ -0,0 +1,21 @@ + + + +Document.doctype + + + +
+