dom: implement HTMLCollection

We can't simply use the libdom dom_document_get_elements_by_tag_name
because it follows an old version of the specifications and returns a
NodeList.
Since
190700b7c1
the spec changed in favor of returning an HTMLCollection.

So I'm trying to re-implement the HTMLCollection in zig.
This commit is contained in:
Pierre Tachoire
2023-10-25 10:36:30 +02:00
parent 2e40837f0d
commit 062a1a4010
3 changed files with 152 additions and 9 deletions

View File

@@ -765,6 +765,18 @@ pub inline fn documentGetElementsByTagName(doc: *Document, tagname: []const u8)
return nlist.?;
}
// documentGetDocumentElement returns the root document element.
pub inline fn documentGetDocumentElement(doc: *Document) *Element {
var elem: ?*Element = undefined;
_ = documentVtable(doc).dom_document_get_document_element.?(doc, &elem);
return elem.?;
}
pub inline fn documentGetDocumentNode(doc: *Document) *Node {
const res = documentGetDocumentElement(doc);
return @as(*Node, @ptrCast(res));
}
pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Element {
var elem: ?*Element = undefined;
_ = documentVtable(doc).dom_document_create_element.?(doc, stringFromData(tag_name), &elem);