diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-14 18:44:57 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-14 19:00:24 +0200 |
commit | 74a91ab5b92052bb595795b9791b412e563ffa16 (patch) | |
tree | 852e4e255d589863d8c7cc967accd16ad08889d2 | |
parent | b46f8e9c5b9546e87ba5157905b72178119032ea (diff) | |
download | chawan-74a91ab5b92052bb595795b9791b412e563ffa16.tar.gz |
dom: use pointers instead of numerical ids for collections
The "id" scheme had obvious problems when multiple documents existed. Originally it was needed because the old hacky integration with QuickJS would occasionally result in objects being moved to other addresses. This has been fixed long ago when I decided to vendor in a fork, so we can just use pointers as ids unique to the entire process.
-rw-r--r-- | src/html/dom.nim | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index d96877ff..28e3f558 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -106,7 +106,6 @@ type match: proc(node: Node): bool {.noSideEffect.} snapshot: seq[Node] livelen: int - id: int NodeList = ref object of Collection @@ -127,12 +126,10 @@ type parentNode* {.jsget.}: Node root: Node index*: int # Index in parents children. -1 for nodes without a parent. - # Live collection cache: ids of live collections are saved in all + # Live collection cache: pointers to live collections are saved in all # nodes they refer to. These are removed when the collection is destroyed, # and invalidated when the owner node's children or attributes change. - # (We can't just store pointers, because those may be invalidated by - # the JavaScript finalizers.) - liveCollections: HashSet[int] + liveCollections: HashSet[pointer] childNodes_cached: NodeList document_internal: Document # not nil @@ -176,8 +173,7 @@ type renderBlockingElements: seq[Element] - invalidCollections: HashSet[int] # collection ids - colln: int + invalidCollections: HashSet[pointer] # pointers to Collection objects all_cached: HTMLAllCollection cachedSheets: seq[CSSStylesheet] @@ -942,6 +938,8 @@ func `$`*(node: Node): string = result = "<!DOCTYPE" & ' ' & DocumentType(node).name & ">" elif node of Document: result = "Node of Document" + elif node of DocumentFragment: + result = "Node of DocumentFragment" else: result = "Unknown node" @@ -1040,6 +1038,9 @@ iterator options*(select: HTMLSelectElement): HTMLOptionElement {.inline.} = if opt of HTMLOptionElement: yield HTMLOptionElement(opt) +func id(collection: Collection): pointer = + return cast[pointer](collection) + proc populateCollection(collection: Collection) = if collection.childonly: for child in collection.root.childList: @@ -1100,10 +1101,8 @@ func newCollection[T: Collection](root: Node, match: CollectionMatchFun, islive: islive, childonly: childonly, match: match, - root: root, - id: root.document.colln + root: root ) - inc root.document.colln result.populateCollection() func jsNodeType0(node: Node): NodeType = |