From 6a48f6df25f56cde49ce78ed0b70c0308a1ab95a Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Tue, 2 Dec 2025 07:01:14 +0800 Subject: [PATCH] Element.hasAttributes --- src/browser/tests/element/attributes.html | 36 +++++++++++++++++++++++ src/browser/webapi/Element.zig | 6 ++++ src/browser/webapi/element/Attribute.zig | 3 ++ 3 files changed, 45 insertions(+) diff --git a/src/browser/tests/element/attributes.html b/src/browser/tests/element/attributes.html index 5fb92883..e33af9ed 100644 --- a/src/browser/tests/element/attributes.html +++ b/src/browser/tests/element/attributes.html @@ -129,3 +129,39 @@ testing.expectEqual(false, el1.hasAttribute('toggle-test')); } + + diff --git a/src/browser/webapi/Element.zig b/src/browser/webapi/Element.zig index 8836770a..12c4b686 100644 --- a/src/browser/webapi/Element.zig +++ b/src/browser/webapi/Element.zig @@ -288,6 +288,11 @@ pub fn hasAttribute(self: *const Element, name: []const u8, page: *Page) !bool { return value != null; } +pub fn hasAttributes(self: *const Element) bool { + const attributes = self._attributes orelse return false; + return attributes.isEmpty() == false; +} + pub fn getAttributeNode(self: *Element, name: []const u8, page: *Page) !?*Attribute { const attributes = self._attributes orelse return null; return attributes.getAttribute(name, self, page); @@ -952,6 +957,7 @@ pub const JsApi = struct { pub const style = bridge.accessor(Element.getStyle, null, .{}); pub const attributes = bridge.accessor(Element.getAttributeNamedNodeMap, null, .{}); pub const hasAttribute = bridge.function(Element.hasAttribute, .{}); + pub const hasAttributes = bridge.function(Element.hasAttributes, .{}); pub const getAttribute = bridge.function(Element.getAttribute, .{}); pub const getAttributeNode = bridge.function(Element.getAttributeNode, .{}); pub const setAttribute = bridge.function(Element.setAttribute, .{}); diff --git a/src/browser/webapi/element/Attribute.zig b/src/browser/webapi/element/Attribute.zig index 46e5705e..b4b9a4ee 100644 --- a/src/browser/webapi/element/Attribute.zig +++ b/src/browser/webapi/element/Attribute.zig @@ -120,6 +120,9 @@ pub const JsApi = struct { pub const List = struct { _list: std.DoublyLinkedList = .{}, + pub fn isEmpty(self: *const List) bool { + return self._list.first == null; + } pub fn get(self: *const List, name: []const u8, page: *Page) !?[]const u8 { const entry = (try self.getEntry(name, page)) orelse return null; return entry._value.str();