about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-22 00:38:47 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-22 00:50:16 +0200
commitfa58bf29ac47c347fb41e87e5e4878740f970df0 (patch)
tree65fcc39c6918a4d12923939e9d850a61c67d3da5 /src/html
parente3d9ee2c6224cd30bf56e24f7988899e0e3985c1 (diff)
downloadchawan-fa58bf29ac47c347fb41e87e5e4878740f970df0.tar.gz
dom: remove unnecessary/unused properties
* remove some properties we no longer use
* convert novalidate into a reflected attribute
* fix satClassList
* remove reference to root node in every Node

The last one is an obvious win when considering how often rootNode is
used vs the memory used by a pointless pointer on every single object.
Diffstat (limited to 'src/html')
-rw-r--r--src/html/catom.nim3
-rw-r--r--src/html/dom.nim16
2 files changed, 8 insertions, 11 deletions
diff --git a/src/html/catom.nim b/src/html/catom.nim
index e8252fcd..9180ecd6 100644
--- a/src/html/catom.nim
+++ b/src/html/catom.nim
@@ -21,7 +21,7 @@ macro makeStaticAtom =
       satCharset = "charset"
       satChecked = "checked"
       satClass = "class"
-      satClassList
+      satClassList = "classList"
       satColor = "color"
       satCols = "cols"
       satColspan = "colspan"
@@ -49,6 +49,7 @@ macro makeStaticAtom =
       satMultiple = "multiple"
       satName = "name"
       satNomodule = "nomodule"
+      satNovalidate = "novalidate"
       satOnclick = "onclick"
       satOnload = "onload"
       satReferrerpolicy = "referrerpolicy"
diff --git a/src/html/dom.nim b/src/html/dom.nim
index bedde23b..32e98824 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -125,7 +125,6 @@ type
   Node* = ref object of EventTarget
     childList*: seq[Node]
     parentNode* {.jsget.}: Node
-    root: Node
     index*: int # Index in parents children. -1 for nodes without a parent.
     # Live collection cache: pointers to live collections are saved in all
     # nodes they refer to. These are removed when the collection is destroyed,
@@ -261,7 +260,6 @@ type
     selected*: bool
 
   HTMLHeadingElement* = ref object of HTMLElement
-    rank*: uint16
 
   HTMLBRElement* = ref object of HTMLElement
 
@@ -270,7 +268,6 @@ type
   HTMLUListElement* = ref object of HTMLElement
 
   HTMLOListElement* = ref object of HTMLElement
-    start*: Option[int]
 
   HTMLLIElement* = ref object of HTMLElement
     value* {.jsget.}: Option[int32]
@@ -284,9 +281,7 @@ type
     fetchStarted: bool
 
   HTMLFormElement* = ref object of HTMLElement
-    smethod*: string
     enctype*: string
-    novalidate*: bool
     constructingEntryList*: bool
     controls*: seq[FormAssociatedElement]
     relList {.jsget.}: DOMTokenList
@@ -814,6 +809,7 @@ const ReflectTable0 = [
   makes("target", TAG_A, TAG_AREA, TAG_LABEL, TAG_LINK),
   makes("href", TAG_LINK),
   makeb("required", TAG_INPUT, TAG_SELECT, TAG_TEXTAREA),
+  makeb("novalidate", "noValidate", TAG_FORM),
   makes("rel", TAG_A, TAG_LINK, TAG_LABEL),
   makes("for", "htmlFor", TAG_LABEL),
   makeul("cols", TAG_TEXTAREA, 20u32),
@@ -1934,9 +1930,11 @@ func childTextContent*(node: Node): string =
     if child of Text:
       result &= Text(child).data
 
-func rootNode*(node: Node): Node =
-  if node.root == nil: return node
-  return node.root
+func rootNode(node: Node): Node =
+  var node = node
+  while node.parentNode != nil:
+    node = node.parentNode
+  return node
 
 func isConnected(node: Node): bool {.jsfget.} =
   return node.rootNode of Document #TODO shadow root
@@ -3166,7 +3164,6 @@ proc remove*(node: Node; suppressObservers: bool) =
   parent.childList.setLen(parent.childList.len - 1)
   node.parentNode.invalidateCollections()
   node.parentNode = nil
-  node.root = nil
   node.index = -1
   if node.document != nil and (node of HTMLStyleElement or
       node of HTMLLinkElement):
@@ -3371,7 +3368,6 @@ proc insertNode(parent, node, before: Node) =
       parent.childList[i + 1] = parent.childList[i]
       parent.childList[i + 1].index = i + 1
   parent.childList[node.index] = node
-  node.root = parent.rootNode
   node.parentNode = parent
   node.invalidateCollections()
   parent.invalidateCollections()