about summary refs log tree commit diff stats
path: root/src/local/client.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-25 02:01:30 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-25 02:01:30 +0200
commit790e937795746563246808abaf4b0b25f4a5d0fe (patch)
tree80e9b360c4ebe601c64488c787860e33ccb1671a /src/local/client.nim
parentda3f78eb9333b7076591ca4088b7f26afc7852ef (diff)
downloadchawan-790e937795746563246808abaf4b0b25f4a5d0fe.tar.gz
client: write errors to browser console in evalAction
Diffstat (limited to 'src/local/client.nim')
-rw-r--r--src/local/client.nim13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/local/client.nim b/src/local/client.nim
index 9d9bb2e6..815d1efb 100644
--- a/src/local/client.nim
+++ b/src/local/client.nim
@@ -182,15 +182,22 @@ proc handlePagerEvents(client: Client) =
     client.pager.handleEvents(container)
 
 proc evalAction(client: Client, action: string, arg0: int32) =
-  let ret = client.evalJS(action, "<command>")
+  var ret = client.evalJS(action, "<command>")
   let ctx = client.jsctx
   if JS_IsFunction(ctx, ret):
     if arg0 != 0:
       var arg0 = toJS(ctx, arg0)
-      JS_FreeValue(ctx, JS_Call(ctx, ret, JS_UNDEFINED, 1, addr arg0))
+      let ret2 = JS_Call(ctx, ret, JS_UNDEFINED, 1, addr arg0)
+      JS_FreeValue(ctx, arg0)
+      JS_FreeValue(ctx, ret)
+      ret = ret2
       JS_FreeValue(ctx, arg0)
     else: # no precnum
-      JS_FreeValue(ctx, JS_Call(ctx, ret, JS_UNDEFINED, 0, nil))
+      let ret2 = JS_Call(ctx, ret, JS_UNDEFINED, 0, nil)
+      JS_FreeValue(ctx, ret)
+      ret = ret2
+  if JS_IsException(ret):
+    client.jsctx.writeException(client.console.err)
   JS_FreeValue(ctx, ret)
 
 # The maximum number we are willing to accept.