aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-21 22:15:49 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-22 20:26:12 +0100
commit861ced23471cdd0392cc5de52a554fc570c0d2c6 (patch)
tree23945f53027c837cf3760bf625d1968d1e87feaf /src
parent3caeb2c1277e857179fdb5b8c9d39b1a5f22391f (diff)
downloadchawan-861ced23471cdd0392cc5de52a554fc570c0d2c6.tar.gz
dom: add some missing nil checks
Diffstat (limited to 'src')
-rw-r--r--src/html/dom.nim20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 494f2fbb..b723207d 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -1042,7 +1042,8 @@ func makeulgz(name: static string; ts: varargs[TagType]; default = 0u32):
u: default
)
-func makef(name: static string; ts: set[TagType]; ctype: static string): ReflectEntry =
+func makef(name: static string; ts: set[TagType]; ctype: static string):
+ ReflectEntry =
const attrname = attrType0(name)
ReflectEntry(
attrname: attrname,
@@ -2677,6 +2678,8 @@ proc applyUASheet*(document: Document) =
document.documentElement.invalidate()
proc applyQuirksSheet*(document: Document) =
+ if document.window == nil:
+ return
const quirks = staticRead"res/quirk.css"
document.uaSheets.add(quirks.parseStylesheet(document.factory, nil,
document.window.attrsp).applyMediaQuery(document.window))
@@ -2692,7 +2695,7 @@ proc applyUserSheet*(document: Document; user: string) =
#TODO this should be cached & called incrementally
proc applyAuthorSheets*(document: Document) =
let window = document.window
- if window.styling and document.documentElement != nil:
+ if window != nil and window.styling and document.documentElement != nil:
document.authorSheets = @[]
for elem in document.documentElement.descendants:
if elem of HTMLStyleElement:
@@ -3626,10 +3629,14 @@ proc newElement*(document: Document; localName, namespaceURI, prefix: CAtom):
of TAG_LABEL:
HTMLLabelElement()
of TAG_CANVAS:
+ let imageId = if document.window != nil:
+ -1
+ else:
+ document.window.getImageId()
let bitmap = if document.scriptingEnabled:
NetworkBitmap(
contentType: "image/x-cha-canvas",
- imageId: document.window.getImageId(),
+ imageId: imageId,
width: 300,
height: 150
)
@@ -4257,8 +4264,8 @@ proc loadResource*(window: Window; svg: SVGSVGElement) =
)
window.pendingResources.add(p)
-proc reflectEvent(element: Element; target: EventTarget; name, ctype: StaticAtom;
- value: string) =
+proc reflectEvent(element: Element; target: EventTarget;
+ name, ctype: StaticAtom; value: string) =
let document = element.document
let ctx = document.window.jsctx
let urls = document.baseURL.serialize(excludepassword = true)
@@ -4323,7 +4330,8 @@ proc reflectAttr(element: Element; name: CAtom; value: Option[string]) =
case element.tagType
of TAG_BODY:
if name == satOnload and element.scriptingEnabled:
- element.reflectEvent(element.document.window, name, satLoad, value.get(""))
+ element.reflectEvent(element.document.window, name, satLoad,
+ value.get(""))
return
of TAG_INPUT:
let input = HTMLInputElement(element)