about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-11-22 19:08:13 +0100
committerbptato <nincsnevem662@gmail.com>2024-11-22 20:06:25 +0100
commit7d549f10ba356486201645ae11fc4796ef5a4441 (patch)
tree4d5f0f12ee42597f7803907b519100e6793559f7 /src
parent309852b46d93bc33e5ddaa1c5c49d071f71f0900 (diff)
downloadchawan-7d549f10ba356486201645ae11fc4796ef5a4441.tar.gz
dom: add document named property getter, update monoucha
Diffstat (limited to 'src')
-rw-r--r--src/html/dom.nim47
-rw-r--r--src/version.nim2
2 files changed, 40 insertions, 9 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 99cced5d..b7ecffe0 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -1647,18 +1647,19 @@ proc getter(ctx: JSContext; this: HTMLCollection; atom: JSAtom): JSValue
     return ctx.toJS(this.namedItem(s)).uninitIfNull()
   return JS_UNINITIALIZED
 
-func names(ctx: JSContext; collection: HTMLCollection): JSPropertyEnumList
+proc names(ctx: JSContext; collection: HTMLCollection): JSPropertyEnumList
     {.jspropnames.} =
   let L = collection.length
   var list = newJSPropertyEnumList(ctx, L)
   var ids = initOrderedSet[CAtom]()
+  let empty = ctx.toAtom("")
   for u in 0 ..< L:
     list.add(u)
-    let elem = collection.item(u)
-    if elem.id != CAtomNull:
-      ids.incl(elem.id)
-    if elem.namespace == Namespace.HTML:
-      ids.incl(elem.name)
+    let element = collection.item(u)
+    if element.id != CAtomNull and element.id != empty:
+      ids.incl(element.id)
+    if element.namespace == Namespace.HTML:
+      ids.incl(element.name)
   for id in ids:
     list.add(collection.root.document.toStr(id))
   return list
@@ -2353,6 +2354,36 @@ func nextElementSibling*(elem: Element): Element {.jsfget.} =
 func documentElement*(document: Document): Element {.jsfget.} =
   return document.firstElementChild()
 
+proc names(ctx: JSContext; document: Document): JSPropertyEnumList
+    {.jspropnames.} =
+  var list = newJSPropertyEnumList(ctx, 0)
+  #TODO I'm not quite sure why location isn't added, so I'll add it
+  # manually for now.
+  list.add("location")
+  let empty = ctx.toAtom("")
+  #TODO exposed embed, exposed object
+  for child in document.elements({TAG_FORM, TAG_IFRAME, TAG_IMG}):
+    if child.name != CAtomNull and child.name != empty:
+      if child.tagType == TAG_IMG and child.id != CAtomNull and
+          child.id != empty:
+        list.add(ctx.toStr(child.id))
+      list.add(ctx.toStr(child.name))
+  return list
+
+proc getter(ctx: JSContext; document: Document; s: string): JSValue
+    {.jsgetownprop.} =
+  if s.len != 0:
+    let id = ctx.toAtom(s)
+    let empty = ctx.toAtom("")
+    #TODO exposed embed, exposed object
+    for child in document.elements({TAG_FORM, TAG_IFRAME, TAG_IMG}):
+      if child.tagType == TAG_IMG and child.id == id and
+          child.name != CAtomNull and child.name != empty:
+        return ctx.toJS(child)
+      if child.name == id:
+        return ctx.toJS(child)
+  return JS_UNINITIALIZED
+
 func attr*(element: Element; s: CAtom): string =
   let i = element.findAttr(s)
   if i != -1:
@@ -3054,10 +3085,10 @@ proc newDocument*(factory: CAtomFactory): Document =
   let document = Document(
     url: newURL("about:blank").get,
     index: -1,
-    factory: factory
+    factory: factory,
+    contentType: "application/xml"
   )
   document.implementation = DOMImplementation(document: document)
-  document.contentType = "application/xml"
   return document
 
 proc newDocument(ctx: JSContext): Document {.jsctor.} =
diff --git a/src/version.nim b/src/version.nim
index 2a0a56e6..869974ae 100644
--- a/src/version.nim
+++ b/src/version.nim
@@ -29,4 +29,4 @@ tryImport monoucha/version, "monoucha"
 static:
   checkVersion("chagashi", 0, 6, 0)
   checkVersion("chame", 1, 0, 2)
-  checkVersion("monoucha", 0, 7, 0)
+  checkVersion("monoucha", 0, 7, 1)