diff --git a/src/dom/document.zig b/src/dom/document.zig index b5e57a10..831ad81d 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -36,6 +36,11 @@ pub const Document = struct { return Element.toInterface(e); } + pub fn _createElementNS(self: *parser.Document, ns: []const u8, tag_name: []const u8) ElementUnion { + const e = parser.documentCreateElementNS(self, ns, tag_name); + return Element.toInterface(e); + } + // We can't simply use libdom dom_document_get_elements_by_tag_name here. // Indeed, netsurf implemented a previous dom spec when // getElementsByTagName returned a NodeList. @@ -51,6 +56,16 @@ pub const Document = struct { .match = tag_name, }; } + + // TODO implement the filter by namespace + pub fn _getElementsByTagNameNS(self: *parser.Document, namespace: []const u8, localname: []const u8) HTMLCollection { + _ = namespace; + const root = parser.documentGetDocumentNode(self); + return HTMLCollection{ + .root = root, + .match = localname, + }; + } }; // Tests @@ -88,6 +103,14 @@ pub fn testExecFn( }; try checkCases(js_env, &getElementsByTagName); + var getElementsByTagNameNS = [_]Case{ + .{ .src = "let a = document.getElementsByTagNameNS('', 'p')", .ex = "undefined" }, + .{ .src = "a.length", .ex = "2" }, + .{ .src = "let b = document.getElementsByTagNameNS(null, 'p')", .ex = "undefined" }, + .{ .src = "b.length", .ex = "2" }, + }; + try checkCases(js_env, &getElementsByTagNameNS); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { diff --git a/src/netsurf.zig b/src/netsurf.zig index 992b8e46..f9126450 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -752,6 +752,12 @@ pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Eleme return elem.?; } +pub inline fn documentCreateElementNS(doc: *Document, ns: []const u8, tag_name: []const u8) *Element { + var elem: ?*Element = undefined; + _ = documentVtable(doc).dom_document_create_element_ns.?(doc, stringFromData(ns), stringFromData(tag_name), &elem); + return elem.?; +} + // DocumentHTML pub const DocumentHTML = c.dom_html_document;