about summary refs log tree commit diff stats
path: root/src/js/javascript.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-09-16 03:46:13 +0200
committerbptato <nincsnevem662@gmail.com>2022-09-16 03:48:36 +0200
commit23caa878a3854dd0118792e1c051b5412ec345cc (patch)
tree0294ecb329765ed7f8960182224f397c46407580 /src/js/javascript.nim
parent3f96681261692feedadfb8c488f3908dd80bb01c (diff)
downloadchawan-23caa878a3854dd0118792e1c051b5412ec345cc.tar.gz
Rename jsget/jsset to jsfget/jsfset for functions
The original idea was to use the same pragmas as object members, but
unfortunately this doesn't seem to work consistently after all.
Diffstat (limited to 'src/js/javascript.nim')
-rw-r--r--src/js/javascript.nim10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index 4ed14212..798b2180 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -309,7 +309,9 @@ func newJSClass*(ctx: JSContext, cdef: JSClassDefConst, cctor: JSCFunction, func
 
 proc callFunction*(fun: JSObject): JSObject =
   result.ctx = fun.ctx
+  let global = JS_GetGlobalObject(fun.ctx)
   result.val = JS_Call(fun.ctx, fun.val, JS_UNDEFINED, 0, nil)
+  JS_FreeValue(fun.ctx, global)
 
 proc callFunction*(fun: JSObject, this: JSObject): JSObject =
   result.ctx = fun.ctx
@@ -1089,7 +1091,7 @@ macro jsctor*(fun: typed) =
     gen.registerFunction()
     result = newStmtList(fun)
 
-macro jsget*(fun: typed) =
+macro jsfget*(fun: typed) =
   var gen = setupGenerator(fun)
   gen.newName = "js_get_" & gen.funcParams[0][0] & '_' & gen.funcName
   gen.thisType = $gen.funcParams[0][1]
@@ -1106,7 +1108,7 @@ macro jsget*(fun: typed) =
   gen.registerFunction()
   result = newStmtList(fun, jsProc)
 
-macro jsset*(fun: typed) =
+macro jsfset*(fun: typed) =
   var gen = setupGenerator(fun)
   gen.newName = "js_set_" & gen.funcParams[0][0] & '_' & gen.funcName
   gen.thisType = $gen.funcParams[0][1]
@@ -1151,8 +1153,8 @@ macro jsfunc*(fun: typed) =
   gen.registerFunction()
   result = newStmtList(fun, jsProc)
 
-#WARNING footgun ahead: for some reason, these must be declared *after* their
-# macro counterparts, or they override the macros.
+# Having the same names for these and the macros leads to weird bugs, so the
+# macros get an additional f.
 template jsget*() {.pragma.}
 template jsset*() {.pragma.}