This commit is contained in:
Karl Seguin
2025-07-08 18:28:21 +08:00
parent 7b46fe9cc8
commit b74863873b
3 changed files with 26 additions and 17 deletions

View File

@@ -227,7 +227,12 @@ const Observer = struct {
event_node: parser.EventNode, event_node: parser.EventNode,
fn appliesTo(self: *const Observer, target: *parser.Node, event_type: MutationEventType, event: *parser.MutationEvent,) !bool { fn appliesTo(
self: *const Observer,
target: *parser.Node,
event_type: MutationEventType,
event: *parser.MutationEvent,
) !bool {
if (event_type == .DOMAttrModified and self.options.attributeFilter.len > 0) { if (event_type == .DOMAttrModified and self.options.attributeFilter.len > 0) {
const attribute_name = try parser.mutationEventAttributeName(event); const attribute_name = try parser.mutationEventAttributeName(event);
for (self.options.attributeFilter) |needle| blk: { for (self.options.attributeFilter) |needle| blk: {
@@ -366,7 +371,8 @@ test "Browser.DOM.MutationObserver" {
\\ document.firstElementChild.setAttribute("foo", "bar"); \\ document.firstElementChild.setAttribute("foo", "bar");
\\ // ignored b/c it's about another target. \\ // ignored b/c it's about another target.
\\ document.firstElementChild.firstChild.setAttribute("foo", "bar"); \\ document.firstElementChild.firstChild.setAttribute("foo", "bar");
,null ,
null,
}, },
.{ "nb", "1" }, .{ "nb", "1" },
.{ "mrs[0].type", "attributes" }, .{ "mrs[0].type", "attributes" },
@@ -386,7 +392,8 @@ test "Browser.DOM.MutationObserver" {
\\ nb2++; \\ nb2++;
\\ }).observe(node, { characterData: true, characterDataOldValue: true }); \\ }).observe(node, { characterData: true, characterDataOldValue: true });
\\ node.data = "foo"; \\ node.data = "foo";
, null ,
null,
}, },
.{ "nb2", "1" }, .{ "nb2", "1" },
.{ "mrs2[0].type", "characterData" }, .{ "mrs2[0].type", "characterData" },
@@ -405,7 +412,8 @@ test "Browser.DOM.MutationObserver" {
\\ node.innerText = 'a'; \\ node.innerText = 'a';
\\ }).observe(document, { subtree:true,childList:true }); \\ }).observe(document, { subtree:true,childList:true });
\\ node.innerText = "2"; \\ node.innerText = "2";
, null ,
null,
}, },
.{ "node.innerText", "a" }, .{ "node.innerText", "a" },
}, .{}); }, .{});
@@ -418,7 +426,8 @@ test "Browser.DOM.MutationObserver" {
\\ attrWatch++; \\ attrWatch++;
\\ }).observe(document, { attributeFilter: ["name"], subtree: true }); \\ }).observe(document, { attributeFilter: ["name"], subtree: true });
\\ node.setAttribute("id", "1"); \\ node.setAttribute("id", "1");
, null ,
null,
}, },
.{ "attrWatch", "0" }, .{ "attrWatch", "0" },
.{ "node.setAttribute('name', 'other');", null }, .{ "node.setAttribute('name', 'other');", null },