about summary refs log tree commit diff stats
path: root/src/server/buffer.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-21 14:42:50 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-21 14:43:14 +0200
commit6216aa6733b72fa631546fc6afa591305e45fcf4 (patch)
tree0c4e1fc11c706464dd62058ecf51a47fab6a565b /src/server/buffer.nim
parent1369135f9719ebe7a58c75fd73ecbfec92ef7e24 (diff)
downloadchawan-6216aa6733b72fa631546fc6afa591305e45fcf4.tar.gz
buffer: replace dispatchEvent procs with that in dom
Diffstat (limited to 'src/server/buffer.nim')
-rw-r--r--src/server/buffer.nim37
1 files changed, 4 insertions, 33 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 153ebbb6..3864d9c6 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -989,44 +989,15 @@ proc clone*(buffer: Buffer; newurl: URL): int {.proxy.} =
 
 proc dispatchDOMContentLoadedEvent(buffer: Buffer) =
   let window = buffer.window
-  let ctx = window.jsctx
-  let document = buffer.document
-  let adcl = window.toAtom(satDOMContentLoaded)
-  let event = newEvent(adcl, document)
-  var called = false
-  var els = document.eventListeners
-  for el in els:
-    if el.removed:
-      continue
-    if el.ctype == adcl:
-      let e = ctx.invoke(el, event)
-      if JS_IsException(e):
-        ctx.writeException(buffer.estream)
-      JS_FreeValue(ctx, e)
-      called = true
-      if efStopImmediatePropagation in event.flags:
-        break
+  let event = newEvent(window.toAtom(satDOMContentLoaded), buffer.document)
+  let (called, _) = window.dispatchEvent(event, buffer.document)
   if called:
     buffer.do_reshape()
 
 proc dispatchLoadEvent(buffer: Buffer) =
   let window = buffer.window
-  let ctx = window.jsctx
-  let aload = window.toAtom(satLoad)
-  let event = newEvent(aload, window)
-  var called = false
-  var els = window.eventListeners
-  for el in els:
-    if el.removed:
-      continue
-    if el.ctype == aload:
-      let e = ctx.invoke(el, event)
-      if JS_IsException(e):
-        ctx.writeException(buffer.estream)
-      JS_FreeValue(ctx, e)
-      called = true
-      if efStopImmediatePropagation in event.flags:
-        break
+  let event = newEvent(window.toAtom(satLoad), window)
+  let (called, _) = window.dispatchEvent(event, window)
   if called:
     buffer.do_reshape()