about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-21 19:17:10 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-21 19:17:10 +0200
commit470aeef2d72614cb8f904d8ef19583312410d981 (patch)
tree20cebeb73b89000d4ee43b1d95c98d271ae84483 /src/config
parent31b359224632fd4e3c2aac667483ed249121efaa (diff)
downloadchawan-470aeef2d72614cb8f904d8ef19583312410d981.tar.gz
js: fix some incorrect defineProperty usage
It consumes a value, so we must dup those that we pass.
Diffstat (limited to 'src/config')
-rw-r--r--src/config/config.nim5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/config/config.nim b/src/config/config.nim
index 63bc50ab..1ac0393e 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -773,16 +773,17 @@ proc initCommands*(config: Config): Err[string] =
     if k in config.cmd.map:
       # already in map; skip
       continue
-    var objIt = obj
+    var objIt = JS_DupValue(ctx, obj)
     let name = k.afterLast('.')
     if name.len < k.len:
       for ss in k.substr(0, k.high - name.len - 1).split('.'):
         var prop = JS_GetPropertyStr(ctx, objIt, cstring(ss))
         if JS_IsUndefined(prop):
           prop = JS_NewObject(ctx)
-          ctx.definePropertyE(objIt, ss, prop)
+          ctx.definePropertyE(objIt, ss, JS_DupValue(ctx, prop))
         if JS_IsException(prop):
           return err(ctx.getExceptionMsg())
+        JS_FreeValue(ctx, objIt)
         objIt = prop
     if cmd == "":
       config.cmd.map[k] = JS_UNDEFINED