diff options
author | bptato <nincsnevem662@gmail.com> | 2025-02-20 18:48:05 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-02-20 18:48:05 +0100 |
commit | a1b027140bde18a6d47ad863c92bbbf189243d8b (patch) | |
tree | 3f1e99e486df5a0b470e6f07144a3fbb96fbc9db | |
parent | 7342f552bffb87acc184a959b28559fae03c9782 (diff) | |
download | chawan-a1b027140bde18a6d47ad863c92bbbf189243d8b.tar.gz |
javascript: fix finalizers with non-RootRef derived objects
We were calling the wrong getTypePtr. Also, fix some manual tests.
-rw-r--r-- | lib/monoucha0/monoucha/eprint.nim | 3 | ||||
-rw-r--r-- | lib/monoucha0/monoucha/javascript.nim | 4 | ||||
-rw-r--r-- | lib/monoucha0/test/manual.nim | 11 |
3 files changed, 11 insertions, 7 deletions
diff --git a/lib/monoucha0/monoucha/eprint.nim b/lib/monoucha0/monoucha/eprint.nim index 73c207e8..c7935d6a 100644 --- a/lib/monoucha0/monoucha/eprint.nim +++ b/lib/monoucha0/monoucha/eprint.nim @@ -24,6 +24,9 @@ else: func eprint*(s: varargs[string, `$`]) = eprint0(s) +proc c_fprintf*(f: File, frmt: cstring): cint {. + importc: "fprintf", header: "<stdio.h>", varargs, discardable.} + func elog*(s: varargs[string, `$`]) = {.cast(noSideEffect), cast(tags: []), cast(raises: []).}: var f: File = nil diff --git a/lib/monoucha0/monoucha/javascript.nim b/lib/monoucha0/monoucha/javascript.nim index 1f921d5d..90588ddf 100644 --- a/lib/monoucha0/monoucha/javascript.nim +++ b/lib/monoucha0/monoucha/javascript.nim @@ -1280,13 +1280,13 @@ template jsDestructor*[U](T: typedesc[ref U]) = static: jsDtors.incl($T) proc `=destroy`(obj: var U) = - nim_finalize_for_js(addr obj, getTypePtr(obj)) + nim_finalize_for_js(addr obj, getTypePtr(T)) template jsDestructor*(T: typedesc[object]) = static: jsDtors.incl($T) proc `=destroy`(obj: var T) = - nim_finalize_for_js(addr obj, getTypePtr(obj)) + nim_finalize_for_js(addr obj, getTypePtr(T)) proc bindConstructor(stmts: NimNode; info: var RegistryInfo): NimNode = if info.ctorFun != nil: diff --git a/lib/monoucha0/test/manual.nim b/lib/monoucha0/test/manual.nim index 2aa8c684..607cf6b7 100644 --- a/lib/monoucha0/test/manual.nim +++ b/lib/monoucha0/test/manual.nim @@ -47,7 +47,10 @@ ReferenceError: abcd is not defined ctx.free() rt.free() -type Earth = ref object +type + Planet = ref object of RootObj + Earth = ref object of Planet + Moon = ref object of Planet proc jsAssert(earth: Earth; pred: bool) {.jsfunc: "assert".} = assert pred @@ -84,10 +87,6 @@ test "Global objects": rt.free() test "Inheritance": - type - Planet = ref object of RootObj - Earth = ref object of Planet - Moon = ref object of Planet jsDestructor(Moon) jsDestructor(Planet) let rt = newJSRuntime() @@ -276,6 +275,8 @@ proc finalize(file: JSFile) {.jsfin.} = test "jsfin: object finalizers": let rt = newJSRuntime() let ctx = rt.newJSContext() + GC_fullCollect() # ensure refc runs + unrefd = 0 # ignore previous unrefs ctx.registerType(Window, asglobal = true) ctx.registerType(JSFile, name = "File") const code = """ |