mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
Check if event target has listener before adding it
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -37,6 +37,13 @@ pub const EventTarget = struct {
|
||||
// TODO: hanle EventListenerOptions
|
||||
// see #https://github.com/lightpanda-io/jsruntime-lib/issues/114
|
||||
) !void {
|
||||
|
||||
// check if event target has already this listener
|
||||
const lst = try parser.eventTargetHasListener(self, eventType, cbk.id());
|
||||
if (lst != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: when can we free this allocation?
|
||||
const cbk_ptr = try alloc.create(Callback);
|
||||
cbk_ptr.* = cbk;
|
||||
@@ -85,6 +92,14 @@ pub fn testExecFn(
|
||||
};
|
||||
try checkCases(js_env, &basic);
|
||||
|
||||
var basic_twice = [_]Case{
|
||||
.{ .src = "nb = 0", .ex = "0" },
|
||||
.{ .src = "content.addEventListener('basic', cbk)", .ex = "undefined" },
|
||||
.{ .src = "content.dispatchEvent(new Event('basic'))", .ex = "true" },
|
||||
.{ .src = "nb", .ex = "1" },
|
||||
};
|
||||
try checkCases(js_env, &basic_twice);
|
||||
|
||||
var basic_child = [_]Case{
|
||||
.{ .src = "nb = 0; evt = undefined; phase = undefined; cur = undefined", .ex = "undefined" },
|
||||
.{ .src = "para.dispatchEvent(new Event('basic'))", .ex = "true" },
|
||||
|
||||
Reference in New Issue
Block a user