Merge pull request #850 from lightpanda-io/set_attribute_value

Attribute.set_value uses element, if possible
This commit is contained in:
Karl Seguin
2025-07-08 08:14:52 +08:00
committed by GitHub
2 changed files with 10 additions and 2 deletions

View File

@@ -15,7 +15,6 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const parser = @import("../netsurf.zig");
const Node = @import("node.zig").Node;
@@ -47,7 +46,14 @@ pub const Attr = struct {
}
pub fn set_value(self: *parser.Attribute, v: []const u8) !?[]const u8 {
if (try parser.attributeGetOwnerElement(self)) |el| {
// if possible, go through the element, as that triggers a
// DOMAttrModified event (which MutationObserver cares about)
const name = try parser.attributeGetName(self);
try parser.elementSetAttribute(el, name, v);
} else {
try parser.attributeSetValue(self, v);
}
return v;
}

View File

@@ -134,5 +134,7 @@ test "Browser.DOM.NamedNodeMap" {
.{ "a['id'].name", "id" },
.{ "a['id'].value", "content" },
.{ "a['other']", "undefined" },
.{ "a[0].value = 'abc123'", null },
.{ "a[0].value", "abc123" },
}, .{});
}