about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-08-27 15:36:19 +0200
committerbptato <nincsnevem662@gmail.com>2023-08-28 20:08:35 +0200
commit1aafbc1d8adc69ea593efb4c0b9a7c5c2f3b9fa5 (patch)
treef247b2a52820f608f6d8e8d41b8027e521bbf6f9 /src/html
parent9991bd3393483158ab0d1b9d995f695dee3c65dc (diff)
downloadchawan-1aafbc1d8adc69ea593efb4c0b9a7c5c2f3b9fa5.tar.gz
javascript: de-ref some interfaces
Also, make ActionMap use getters/hasprop instead of a table copy.

peakmem remains up +200M at 950M after commit
9991bd3393483158ab0d1b9d995f695dee3c65dc. :(
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim19
-rw-r--r--src/html/env.nim50
2 files changed, 36 insertions, 33 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index a5dc8212..57b62ec6 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -97,12 +97,12 @@ type
     navigate*: proc(url: URL)
 
   # Navigator stuff
-  Navigator* = ref object
+  Navigator* = object
     plugins: PluginArray
 
-  PluginArray* = ref object
+  PluginArray* = object
 
-  MimeTypeArray* = ref object
+  MimeTypeArray* = object
 
   # "For historical reasons, console is lowercased."
   # Also, for a more practical reason: so the javascript macros don't confuse
@@ -161,7 +161,7 @@ type
     value* {.jsget.}: string
     ownerElement* {.jsget.}: Element
 
-  DOMImplementation = ref object
+  DOMImplementation = object
     document: Document
 
   Document* = ref object of Node
@@ -2827,15 +2827,15 @@ proc createElement(document: Document, localName: string):
 proc createDocumentFragment(document: Document): DocumentFragment {.jsfunc.} =
   return newDocumentFragment(document)
 
-proc createDocumentType(implementation: DOMImplementation, qualifiedName,
+proc createDocumentType(implementation: ptr DOMImplementation, qualifiedName,
     publicId, systemId: string): Result[DocumentType, DOMException] {.jsfunc.} =
   if not qualifiedName.matchQNameProduction():
     return err(newDOMException("Invalid character in document type name",
       "InvalidCharacterError"))
-  return ok(implementation.document.newDocumentType(qualifiedName, publicId,
-    systemId))
+  let document = implementation.document
+  return ok(document.newDocumentType(qualifiedName, publicId, systemId))
 
-proc createHTMLDocument(implementation: DOMImplementation, title =
+proc createHTMLDocument(implementation: ptr DOMImplementation, title =
     none(string)): Document {.jsfunc.} =
   let doc = newDocument()
   doc.contentType = "text/html"
@@ -2852,6 +2852,9 @@ proc createHTMLDocument(implementation: DOMImplementation, title =
   #TODO set origin
   return doc
 
+proc hasFeature(implementation: ptr DOMImplementation): bool {.jsfunc.} =
+  return true
+
 proc createCDATASection(document: Document, data: string): Result[CDATASection, DOMException] {.jsfunc.} =
   if not document.isxml:
     return err(newDOMException("CDATA sections are not supported in HTML",
diff --git a/src/html/env.nim b/src/html/env.nim
index 6e81e614..82ed163b 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -20,24 +20,24 @@ import xhr/formdata
 import xhr/xmlhttprequest
 
 # NavigatorID
-proc appCodeName(navigator: Navigator): string {.jsfget.} = "Mozilla"
-proc appName(navigator: Navigator): string {.jsfget.} = "Netscape"
-proc appVersion(navigator: Navigator): string {.jsfget.} = "5.0 (Windows)"
-proc platform(navigator: Navigator): string {.jsfget.} = "Win32"
-proc product(navigator: Navigator): string {.jsfget.} = "Gecko"
-proc productSub(navigator: Navigator): string {.jsfget.} = "20100101"
-proc userAgent(navigator: Navigator): string {.jsfget.} = "chawan" #TODO TODO TODO this should be configurable
-proc vendor(navigator: Navigator): string {.jsfget.} = ""
-proc vendorSub(navigator: Navigator): string {.jsfget.} = ""
-proc taintEnabled(navigator: Navigator): bool {.jsfget.} = false
-proc oscpu(navigator: Navigator): string {.jsfget.} = "Windows NT 10.0"
+proc appCodeName(navigator: ptr Navigator): string {.jsfget.} = "Mozilla"
+proc appName(navigator: ptr Navigator): string {.jsfget.} = "Netscape"
+proc appVersion(navigator: ptr Navigator): string {.jsfget.} = "5.0 (Windows)"
+proc platform(navigator: ptr Navigator): string {.jsfget.} = "Win32"
+proc product(navigator: ptr Navigator): string {.jsfget.} = "Gecko"
+proc productSub(navigator: ptr Navigator): string {.jsfget.} = "20100101"
+proc userAgent(navigator: ptr Navigator): string {.jsfget.} = "chawan" #TODO TODO TODO this should be configurable
+proc vendor(navigator: ptr Navigator): string {.jsfget.} = ""
+proc vendorSub(navigator: ptr Navigator): string {.jsfget.} = ""
+proc taintEnabled(navigator: ptr Navigator): bool {.jsfget.} = false
+proc oscpu(navigator: ptr Navigator): string {.jsfget.} = "Windows NT 10.0"
 
 # NavigatorLanguage
-proc language(navigator: Navigator): string {.jsfget.} = "en-US"
-proc languages(navigator: Navigator): seq[string] {.jsfget.} = @["en-US"] #TODO frozen array?
+proc language(navigator: ptr Navigator): string {.jsfget.} = "en-US"
+proc languages(navigator: ptr Navigator): seq[string] {.jsfget.} = @["en-US"] #TODO frozen array?
 
 # NavigatorOnline
-proc onLine(navigator: Navigator): bool {.jsfget.} =
+proc onLine(navigator: ptr Navigator): bool {.jsfget.} =
   true # at the very least, the terminal is on-line :)
 
 #TODO NavigatorContentUtils
@@ -45,19 +45,19 @@ proc onLine(navigator: Navigator): bool {.jsfget.} =
 # NavigatorCookies
 # "this website needs cookies to be enabled to function correctly"
 # It's probably better to lie here.
-proc cookieEnabled(navigator: Navigator): bool {.jsfget.} = true
+proc cookieEnabled(navigator: ptr Navigator): bool {.jsfget.} = true
 
 # NavigatorPlugins
-proc pdfViewerEnabled(navigator: Navigator): bool {.jsfget.} = false
-proc javaEnabled(navigator: Navigator): bool {.jsfunc.} = false
-proc namedItem(pluginArray: PluginArray): string {.jsfunc.} = ""
-proc namedItem(mimeTypeArray: MimeTypeArray): string {.jsfunc.} = ""
-proc item(pluginArray: PluginArray): JSValue {.jsfunc.} = JS_NULL
-proc length(pluginArray: PluginArray): int {.jsfget.} = 0
-proc item(mimeTypeArray: MimeTypeArray): JSValue {.jsfunc.} = JS_NULL
-proc length(mimeTypeArray: MimeTypeArray): int {.jsfget.} = 0
-proc getter(pluginArray: PluginArray, i: int): Option[JSValue] {.jsgetprop.} = discard
-proc getter(mimeTypeArray: MimeTypeArray, i: int): Option[JSValue] {.jsgetprop.} = discard
+proc pdfViewerEnabled(navigator: ptr Navigator): bool {.jsfget.} = false
+proc javaEnabled(navigator: ptr Navigator): bool {.jsfunc.} = false
+proc namedItem(pluginArray: ptr PluginArray): string {.jsfunc.} = ""
+proc namedItem(mimeTypeArray: ptr MimeTypeArray): string {.jsfunc.} = ""
+proc item(pluginArray: ptr PluginArray): JSValue {.jsfunc.} = JS_NULL
+proc length(pluginArray: ptr PluginArray): int {.jsfget.} = 0
+proc item(mimeTypeArray: ptr MimeTypeArray): JSValue {.jsfunc.} = JS_NULL
+proc length(mimeTypeArray: ptr MimeTypeArray): int {.jsfget.} = 0
+proc getter(pluginArray: ptr PluginArray, i: int): Option[JSValue] {.jsgetprop.} = discard
+proc getter(mimeTypeArray: ptr MimeTypeArray, i: int): Option[JSValue] {.jsgetprop.} = discard
 
 proc addNavigatorModule(ctx: JSContext) =
   ctx.registerType(Navigator)