about summary refs log tree commit diff stats
path: root/src/html/event.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-03 13:43:44 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-03 13:46:08 +0100
commit79ef0154ad52add78aeb5a0ee7dacba284a2d779 (patch)
treeabfc8ad6bebe406b83c5f1efdd510a08799295c7 /src/html/event.nim
parent22d4736b2fe355e1f8e93cc1f1448f8fa06b60c8 (diff)
downloadchawan-79ef0154ad52add78aeb5a0ee7dacba284a2d779.tar.gz
event: remove ctx from CustomEvent
Instead, make finalizers optionally pass their runtime for resource
deallocation.
Diffstat (limited to 'src/html/event.nim')
-rw-r--r--src/html/event.nim22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/html/event.nim b/src/html/event.nim
index 6234f166..47195b82 100644
--- a/src/html/event.nim
+++ b/src/html/event.nim
@@ -38,7 +38,6 @@ type
     isTrusted {.jsufget.}: bool
 
   CustomEvent* = ref object of Event
-    ctx: JSContext #TODO get rid of this
     detail {.jsget.}: JSValue
 
   EventTarget* = ref object of RootObj
@@ -74,8 +73,7 @@ type
     detail: JSValue
 
 # Event
-proc innerEventCreationSteps(event: Event, ctx: JSContext,
-    eventInitDict: EventInit) =
+proc innerEventCreationSteps(event: Event, eventInitDict: EventInit) =
   event.flags = {FLAG_INITIALIZED}
   #TODO this is probably incorrect?
   # I think it measures the time since the first fork. not sure though
@@ -86,10 +84,10 @@ proc innerEventCreationSteps(event: Event, ctx: JSContext,
     event.flags.incl(FLAG_COMPOSED)
 
 #TODO eventInitDict type
-proc newEvent(ctx: JSContext, ctype: string, eventInitDict = EventInit()):
+proc newEvent(ctype: string, eventInitDict = EventInit()):
     JSResult[Event] {.jsctor.} =
   let event = Event()
-  event.innerEventCreationSteps(ctx, eventInitDict)
+  event.innerEventCreationSteps(eventInitDict)
   event.ctype = ctype
   return ok(event)
 
@@ -156,23 +154,21 @@ func composed(this: Event): bool {.jsfget.} =
   return FLAG_COMPOSED in this.flags
 
 # CustomEvent
-proc newCustomEvent(ctx: JSContext, ctype: string,
-    eventInitDict = CustomEventInit()): JSResult[CustomEvent] {.jsctor.} =
+proc newCustomEvent(ctype: string, eventInitDict = CustomEventInit()):
+    JSResult[CustomEvent] {.jsctor.} =
   let event = CustomEvent()
-  event.innerEventCreationSteps(ctx, eventInitDict)
+  event.innerEventCreationSteps(eventInitDict)
   event.detail = eventInitDict.detail
-  event.ctx = ctx
   event.ctype = ctype
   return ok(event)
 
-proc finalize(this: CustomEvent) {.jsfin.} =
-  JS_FreeValue(this.ctx, this.detail)
+proc finalize(rt: JSRuntime, this: CustomEvent) {.jsfin.} =
+  JS_FreeValueRT(rt, this.detail)
 
-proc initCustomEvent(ctx: JSContext, this: CustomEvent, ctype: string,
+proc initCustomEvent(this: CustomEvent, ctype: string,
     bubbles, cancelable: bool, detail: JSValue) {.jsfunc.} =
   if FLAG_DISPATCH notin this.flags:
     this.initialize(ctype, bubbles, cancelable)
-    this.ctx = ctx
     this.detail = detail
 
 # EventTarget