about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-08-23 23:50:14 +0200
committerbptato <nincsnevem662@gmail.com>2023-08-23 23:52:05 +0200
commite50186dd1112e24cbf74acda0ea2bd4c63ee2ed9 (patch)
tree756fc3b3a749716b5f188696b03820b0d529936d /src/html
parent65fe1de341be4c6f8a7f1a0ec6d954be463bba29 (diff)
downloadchawan-e50186dd1112e24cbf74acda0ea2bd4c63ee2ed9.tar.gz
dom: add some null checks for window
Now that we have established that window *can* be nil.
(Though the document.location window null check is probably
unnecessary, because it is only called from scripts... but better
safe than sorry.)
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim12
-rw-r--r--src/html/env.nim2
2 files changed, 9 insertions, 5 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index b33cbd19..a5dc8212 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -1158,6 +1158,8 @@ proc newLocation*(window: Window): Location =
   return location
 
 func location(document: Document): Location {.jsfget.} =
+  if document.window == nil:
+    return nil
   return document.window.location
 
 func document(location: Location): Document =
@@ -1169,8 +1171,10 @@ func url(location: Location): URL =
     return document.url
   return newURL("about:blank").get
 
-proc setLocation*(document: Document, s: string): Err[DOMException]
+proc setLocation*(document: Document, s: string): Err[JSError]
     {.jsfset: "location".} =
+  if document.location == nil:
+    return err(newTypeError("document.location is not an object"))
   let url = parseURL(s)
   if url.isNone:
     return err(newDOMException("Invalid URL", "SyntaxError"))
@@ -1182,16 +1186,16 @@ proc setLocation*(document: Document, s: string): Err[DOMException]
 func href(location: Location): string {.jsuffget.} =
   return location.url.serialize()
 
-proc setHref(location: Location, s: string): Err[DOMException]
+proc setHref(location: Location, s: string): Err[JSError]
     {.jsfset: "href".} =
   if location.document == nil:
     return ok()
   return location.document.setLocation(s)
 
-proc assign(location: Location, s: string): Err[DOMException] {.jsuffunc.} =
+proc assign(location: Location, s: string): Err[JSError] {.jsuffunc.} =
   location.setHref(s)
 
-proc replace(location: Location, s: string): Err[DOMException] {.jsuffunc.} =
+proc replace(location: Location, s: string): Err[JSError] {.jsuffunc.} =
   location.setHref(s)
 
 proc reload(location: Location) {.jsuffunc.} =
diff --git a/src/html/env.nim b/src/html/env.nim
index c38852d5..6e81e614 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -89,7 +89,7 @@ proc screenTop(window: Window): int64 {.jsfget.} = 0
 #TODO outerWidth, outerHeight
 proc devicePixelRatio(window: Window): float64 {.jsfget.} = 1
 
-proc setLocation(window: Window, s: string): Err[DOMException]
+proc setLocation(window: Window, s: string): Err[JSError]
     {.jsfset: "location".} =
   window.document.setLocation(s)