aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-20 18:48:05 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-20 18:48:05 +0100
commita1b027140bde18a6d47ad863c92bbbf189243d8b (patch)
tree3f1e99e486df5a0b470e6f07144a3fbb96fbc9db /lib
parent7342f552bffb87acc184a959b28559fae03c9782 (diff)
downloadchawan-a1b027140bde18a6d47ad863c92bbbf189243d8b.tar.gz
javascript: fix finalizers with non-RootRef derived objects
We were calling the wrong getTypePtr. Also, fix some manual tests.
Diffstat (limited to 'lib')
-rw-r--r--lib/monoucha0/monoucha/eprint.nim3
-rw-r--r--lib/monoucha0/monoucha/javascript.nim4
-rw-r--r--lib/monoucha0/test/manual.nim11
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 = """