dom: add NamedNodeMap implementation

and create Attr type
This commit is contained in:
Pierre Tachoire
2023-12-02 10:54:12 +01:00
parent dcb095d9df
commit ad5c6236a7
7 changed files with 244 additions and 0 deletions

View File

@@ -10,12 +10,16 @@ const Node = @import("node.zig").Node;
const HTMLElem = @import("../html/elements.zig");
pub const Union = @import("../html/elements.zig").Union;
const DOMException = @import("exceptions.zig").DOMException;
// WEB IDL https://dom.spec.whatwg.org/#element
pub const Element = struct {
pub const Self = parser.Element;
pub const prototype = *Node;
pub const mem_guarantied = true;
pub const Exception = DOMException;
pub fn toInterface(e: *parser.Element) !Union {
return try HTMLElem.toInterface(Union, e);
}
@@ -27,6 +31,10 @@ pub const Element = struct {
return try parser.elementLocalName(self);
}
pub fn get_attributes(self: *parser.Element) !*parser.NamedNodeMap {
return try parser.nodeGetAttributes(parser.elementToNode(self));
}
pub fn _hasAttributes(self: *parser.Element) !bool {
return try parser.nodeHasAttributes(parser.elementToNode(self));
}
@@ -89,6 +97,8 @@ pub fn testExecFn(
var attribute = [_]Case{
.{ .src = "let a = document.getElementById('content')", .ex = "undefined" },
.{ .src = "a.hasAttributes()", .ex = "true" },
.{ .src = "a.attributes.length", .ex = "1" },
.{ .src = "a.getAttribute('id')", .ex = "content" },
.{ .src = "a.hasAttribute('foo')", .ex = "false" },