From 304681bd21db9df11dbf32dc3fffc96664483a97 Mon Sep 17 00:00:00 2001 From: Halil Durak Date: Fri, 16 Jan 2026 18:13:43 +0300 Subject: [PATCH] add simplified `setAttributeNS` and `getAttributeNS` This ignores namespaces for now, we have to come up with a solution if it becomes a necessity. --- src/browser/webapi/Element.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/browser/webapi/Element.zig b/src/browser/webapi/Element.zig index 828f726b..a33d6cc5 100644 --- a/src/browser/webapi/Element.zig +++ b/src/browser/webapi/Element.zig @@ -467,6 +467,11 @@ pub fn getAttribute(self: *const Element, name: []const u8, page: *Page) !?[]con return attributes.get(name, page); } +/// For simplicity, the namespace is currently ignored and only the local name is used. +pub fn getAttributeNS(self: *const Element, _: ?[]const u8, local_name: []const u8, page: *Page) !?[]const u8 { + return self.getAttribute(local_name, page); +} + pub fn getAttributeSafe(self: *const Element, name: []const u8) ?[]const u8 { const attributes = self._attributes orelse return null; return attributes.getSafe(name); @@ -499,6 +504,14 @@ pub fn setAttribute(self: *Element, name: []const u8, value: []const u8, page: * _ = try attributes.put(name, value, self, page); } +pub fn setAttributeNS(self: *Element, _: ?[]const u8, qualified_name: []const u8, value: []const u8, page: *Page) !void { + const local_name = if (std.mem.indexOfScalarPos(u8, qualified_name, 0, ':')) |idx| + qualified_name[idx + 1 ..] + else + qualified_name; + return self.setAttribute(local_name, value, page); +} + pub fn setAttributeSafe(self: *Element, name: []const u8, value: []const u8, page: *Page) !void { const attributes = try self.getOrCreateAttributeList(page); _ = try attributes.putSafe(name, value, self, page); @@ -1371,8 +1384,10 @@ pub const JsApi = struct { pub const hasAttribute = bridge.function(Element.hasAttribute, .{}); pub const hasAttributes = bridge.function(Element.hasAttributes, .{}); pub const getAttribute = bridge.function(Element.getAttribute, .{}); + pub const getAttributeNS = bridge.function(Element.getAttributeNS, .{}); pub const getAttributeNode = bridge.function(Element.getAttributeNode, .{}); pub const setAttribute = bridge.function(Element.setAttribute, .{ .dom_exception = true }); + pub const setAttributeNS = bridge.function(Element.setAttributeNS, .{ .dom_exception = true }); pub const setAttributeNode = bridge.function(Element.setAttributeNode, .{}); pub const removeAttribute = bridge.function(Element.removeAttribute, .{}); pub const toggleAttribute = bridge.function(Element.toggleAttribute, .{ .dom_exception = true });