mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-19 02:18:10 +00:00
dom: add NamedNodeMap implementation
and create Attr type
This commit is contained in:
@@ -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" },
|
||||
|
||||
Reference in New Issue
Block a user