about summary refs log tree commit diff stats
path: root/src/display/client.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-31 02:14:34 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-31 02:14:34 +0100
commit80b45c0df3f5bbbedb9abfb02fdef608113958e1 (patch)
tree475cd89df09b4147b8ee6ce9a1ec28954eb6dc30 /src/display/client.nim
parent310254b09ee2dd3045648848ca9f60f9f1f7c769 (diff)
downloadchawan-80b45c0df3f5bbbedb9abfb02fdef608113958e1.tar.gz
Add promise support to JS
Diffstat (limited to 'src/display/client.nim')
-rw-r--r--src/display/client.nim10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/display/client.nim b/src/display/client.nim
index 928fd32d..0a1f131c 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -13,7 +13,6 @@ when defined(posix):
 import std/exitprocs
 
 import bindings/quickjs
-import buffer/buffer
 import buffer/container
 import css/sheet
 import config/config
@@ -23,6 +22,7 @@ import html/dom
 import html/htmlparser
 import io/lineedit
 import io/loader
+import io/promise
 import io/request
 import io/window
 import ips/forkserver
@@ -101,10 +101,18 @@ proc interruptHandler(rt: JSRuntime, opaque: pointer): int {.cdecl.} =
     discard
   return 0
 
+proc runJSJobs(client: Client) =
+  while JS_IsJobPending(client.jsrt):
+    var ctx: JSContext
+    let r = JS_ExecutePendingJob(client.jsrt, addr ctx)
+    if r == -1:
+      ctx.writeException(client.console.err)
+
 proc evalJS(client: Client, src, filename: string): JSValue =
   if client.console.tty != nil:
     unblockStdin(client.console.tty.getFileHandle())
   result = client.jsctx.eval(src, filename, JS_EVAL_TYPE_GLOBAL)
+  client.runJSJobs()
   if client.console.tty != nil:
     restoreStdin(client.console.tty.getFileHandle())