Skip to content

Commit 04e59c6

Browse files
authored
Merge pull request #850 from lightpanda-io/set_attribute_value
Attribute.set_value uses element, if possible
2 parents 835042b + b3fe3d0 commit 04e59c6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/browser/dom/attribute.zig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//
1616
// You should have received a copy of the GNU Affero General Public License
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
18-
1918
const parser = @import("../netsurf.zig");
2019

2120
const Node = @import("node.zig").Node;
@@ -47,7 +46,14 @@ pub const Attr = struct {
4746
}
4847

4948
pub fn set_value(self: *parser.Attribute, v: []const u8) !?[]const u8 {
50-
try parser.attributeSetValue(self, v);
49+
if (try parser.attributeGetOwnerElement(self)) |el| {
50+
// if possible, go through the element, as that triggers a
51+
// DOMAttrModified event (which MutationObserver cares about)
52+
const name = try parser.attributeGetName(self);
53+
try parser.elementSetAttribute(el, name, v);
54+
} else {
55+
try parser.attributeSetValue(self, v);
56+
}
5157
return v;
5258
}
5359

src/browser/dom/namednodemap.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,7 @@ test "Browser.DOM.NamedNodeMap" {
134134
.{ "a['id'].name", "id" },
135135
.{ "a['id'].value", "content" },
136136
.{ "a['other']", "undefined" },
137+
.{ "a[0].value = 'abc123'", null },
138+
.{ "a[0].value", "abc123" },
137139
}, .{});
138140
}

0 commit comments

Comments
 (0)