about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-27 21:33:39 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-27 21:34:08 +0200
commitbbcf2540627bf3adfd015e71895640e6b09fa379 (patch)
tree7eeffff9ae874acf5b5ce94623d2c1aa60e8e34c
parent60917bd1e99b0274f8c68d7493dee093568d8c69 (diff)
downloadchawan-bbcf2540627bf3adfd015e71895640e6b09fa379.tar.gz
dom: add missing nil checks
document is not set in the main process.
-rw-r--r--src/html/dom.nim5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 60a74d17..7491e56b 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -2466,7 +2466,10 @@ windowConsoleError = proc(ctx: JSContext; ss: varargs[string]) =
   ctx.getGlobal().console.error(ss)
 
 getAPIBaseURLImpl = func(ctx: JSContext): URL =
-  return ctx.getGlobal().document.baseURL
+  let window = ctx.getWindow()
+  if window == nil or window.document == nil:
+    return nil
+  return window.document.baseURL
 
 proc fireEvent*(window: Window; name: StaticAtom; target: EventTarget) =
   let event = newEvent(window.toAtom(name), target)