From 575ca0000c865003cf989a34f6b65b0dafa8d6f3 Mon Sep 17 00:00:00 2001 From: Francis Bouvier Date: Sat, 11 Jul 2026 13:52:09 +0200 Subject: [PATCH] webapi: invoke MutationObserver callbacks with the observer as this Fixes WPT /dom/nodes/MutationObserver-callback-arguments.html: per the DOM spec ("invoke callback with a list of MutationRecord objects and mo, and mo as callback this value"), the mutation callback's this value must be the MutationObserver itself. We invoked it with the default receiver (undefined -> globalThis), so `this === mo` failed. deliverRecords now uses tryCallWithThis with the observer as receiver. Coverage: /dom/nodes/MutationObserver-callback-arguments.html 0/1 -> 1/1 (fully green). Co-Authored-By: Claude Fable 5 --- src/browser/webapi/MutationObserver.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/browser/webapi/MutationObserver.zig b/src/browser/webapi/MutationObserver.zig index 719f09567..3c20732d0 100644 --- a/src/browser/webapi/MutationObserver.zig +++ b/src/browser/webapi/MutationObserver.zig @@ -350,7 +350,8 @@ pub fn deliverRecords(self: *MutationObserver, frame: *Frame) !void { defer ls.deinit(); var caught: js.TryCatch.Caught = undefined; - ls.toLocal(self._callback).tryCall(void, .{ records, self }, &caught) catch |err| { + // Per spec, the callback is invoked with the observer as its this value. + ls.toLocal(self._callback).tryCallWithThis(void, self, .{ records, self }, &caught) catch |err| { log.err(.frame, "MutObserver.deliverRecords", .{ .err = err, .caught = caught }); return err; };