about summary refs log tree commit diff stats
path: root/src/local
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-19 18:54:44 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-19 19:35:07 +0100
commit3f663454031657610bddceb169cd881754ec232a (patch)
treeae088232c3bdbe9f74cfaf19a5d9b99e0dfc8131 /src/local
parentb65993b77789ddbde72f65db648ab993a5097121 (diff)
downloadchawan-3f663454031657610bddceb169cd881754ec232a.tar.gz
fromjs, javascript: optimize out class name registry
Instead of hashing the class name for isInstanceOf, we now just reuse
the Nim type pointer -> JSClassID map, which should be more efficient.

This removes getClass and hasClass; these can be replaced by just
reusing the class ID returned from registerType.
Diffstat (limited to 'src/local')
-rw-r--r--src/local/client.nim12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/local/client.nim b/src/local/client.nim
index ec2a6b0a..74472e75 100644
--- a/src/local/client.nim
+++ b/src/local/client.nim
@@ -133,18 +133,18 @@ proc sleep(client: Client; millis: int) {.jsfunc.} =
 func line(client: Client): LineEdit {.jsfget.} =
   return client.pager.lineedit
 
-proc addJSModules(client: Client; ctx: JSContext) =
-  ctx.addWindowModule2()
+proc addJSModules(client: Client; ctx: JSContext): JSClassID =
+  let (windowCID, eventCID, eventTargetCID) = ctx.addWindowModule2()
   ctx.addDOMExceptionModule()
   ctx.addConsoleModule()
   ctx.addNavigatorModule()
-  ctx.addDOMModule()
+  ctx.addDOMModule(eventTargetCID)
   ctx.addURLModule()
   ctx.addHTMLModule()
   ctx.addIntlModule()
   ctx.addBlobModule()
   ctx.addFormDataModule()
-  ctx.addXMLHttpRequestModule()
+  ctx.addXMLHttpRequestModule(eventCID, eventTargetCID)
   ctx.addHeadersModule()
   ctx.addRequestModule()
   ctx.addResponseModule()
@@ -154,6 +154,7 @@ proc addJSModules(client: Client; ctx: JSContext) =
   ctx.addPagerModule()
   ctx.addContainerModule()
   ctx.addSelectModule()
+  return windowCID
 
 proc newClient*(config: Config; forkserver: ForkServer; loaderPid: int;
     jsctx: JSContext; warnings: seq[string]; urandom: PosixStream;
@@ -177,7 +178,6 @@ proc newClient*(config: Config; forkserver: ForkServer; loaderPid: int;
   jsctx.definePropertyE(global, "cmd", config.cmd.jsObj)
   JS_FreeValue(jsctx, global)
   config.cmd.jsObj = JS_NULL
-  client.addJSModules(jsctx)
-  let windowCID = jsctx.getClass("Window")
+  let windowCID = client.addJSModules(jsctx)
   jsctx.registerType(Client, asglobal = true, parent = windowCID)
   return client