about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim2
-rw-r--r--src/html/event.nim5
2 files changed, 3 insertions, 4 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 2cee89ac..d2682efc 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -2460,6 +2460,8 @@ proc dispatchEvent0(window: Window; event: Event; currentTarget: EventTarget;
   event.currentTarget = currentTarget
   var els = currentTarget.eventListeners # copy intentionally
   for el in els:
+    if JS_IsUndefined(el.callback):
+      continue # removed, presumably by a previous handler
     if el.ctype == event.ctype:
       let e = ctx.invoke(el, event)
       called = true
diff --git a/src/html/event.nim b/src/html/event.nim
index 3d2a3e3a..d396f3ba 100644
--- a/src/html/event.nim
+++ b/src/html/event.nim
@@ -52,14 +52,12 @@ type
 
   EventListener* = ref object
     ctype*: CAtom
+    # if callback is undefined, the listener has been removed
     callback*: EventListenerCallback
     capture: bool
     passive: Option[bool]
     once: bool
     #TODO AbortSignal
-    #TODO do we really need `removed'? maybe we could just check if
-    # callback is undefined.
-    removed*: bool
 
 jsDestructor(Event)
 jsDestructor(CustomEvent)
@@ -233,7 +231,6 @@ proc addAnEventListener(ctx: JSContext; target: EventTarget;
 
 proc removeAnEventListener(eventTarget: EventTarget; ctx: JSContext; i: int) =
   let listener = eventTarget.eventListeners[i]
-  listener.removed = true
   JS_FreeValue(ctx, listener.callback)
   listener.callback = JS_UNDEFINED
   eventTarget.eventListeners.delete(i)