support object listener on removeEventListener also

This commit is contained in:
Karl Seguin
2025-05-26 19:19:39 +08:00
parent cff8857a36
commit 99b7508c7a

View File

@@ -114,7 +114,7 @@ pub const EventTarget = struct {
pub fn _removeEventListener( pub fn _removeEventListener(
self: *parser.EventTarget, self: *parser.EventTarget,
typ: []const u8, typ: []const u8,
cbk: Env.Function, listener: EventHandler.Listener,
opts_: ?RemoveEventListenerOpts, opts_: ?RemoveEventListenerOpts,
) !void { ) !void {
var capture = false; var capture = false;
@@ -125,6 +125,8 @@ pub const EventTarget = struct {
}; };
} }
const cbk = (try listener.callback(self)) orelse return;
// check if event target has already this listener // check if event target has already this listener
const lst = try parser.eventTargetHasListener( const lst = try parser.eventTargetHasListener(
self, self,
@@ -266,5 +268,9 @@ test "Browser.DOM.EventTarget" {
.{ "content.addEventListener('he', obj1);", null }, .{ "content.addEventListener('he', obj1);", null },
.{ "content.dispatchEvent(new Event('he'));", null }, .{ "content.dispatchEvent(new Event('he'));", null },
.{ "obj1.calls", "1" }, .{ "obj1.calls", "1" },
.{ "content.removeEventListener('he', obj1);", null },
.{ "content.dispatchEvent(new Event('he'));", null },
.{ "obj1.calls", "1" },
}, .{}); }, .{});
} }