mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
dom: add element.HasAttributes
This commit is contained in:
@@ -27,6 +27,10 @@ pub const Element = struct {
|
||||
return try parser.elementLocalName(self);
|
||||
}
|
||||
|
||||
pub fn _hasAttributes(self: *parser.Element) !bool {
|
||||
return try parser.nodeHasAttributes(parser.elementToNode(self));
|
||||
}
|
||||
|
||||
pub fn _getAttribute(self: *parser.Element, qname: []const u8) !?[]const u8 {
|
||||
return try parser.elementGetAttribute(self, qname);
|
||||
}
|
||||
@@ -84,6 +88,7 @@ pub fn testExecFn(
|
||||
) !void {
|
||||
var attribute = [_]Case{
|
||||
.{ .src = "let a = document.getElementById('content')", .ex = "undefined" },
|
||||
.{ .src = "a.hasAttributes()", .ex = "true" },
|
||||
.{ .src = "a.getAttribute('id')", .ex = "content" },
|
||||
|
||||
.{ .src = "a.hasAttribute('foo')", .ex = "false" },
|
||||
|
||||
@@ -630,6 +630,13 @@ pub fn nodeReplaceChild(node: *Node, new_child: *Node, old_child: *Node) !*Node
|
||||
return res.?;
|
||||
}
|
||||
|
||||
pub fn nodeHasAttributes(node: *Node) !bool {
|
||||
var res: bool = undefined;
|
||||
const err = nodeVtable(node).dom_node_has_attributes.?(node, &res);
|
||||
try DOMErr(err);
|
||||
return res;
|
||||
}
|
||||
|
||||
// nodeToElement is an helper to convert a node to an element.
|
||||
pub inline fn nodeToElement(node: *Node) *Element {
|
||||
return @as(*Element, @ptrCast(node));
|
||||
|
||||
Reference in New Issue
Block a user