diff options
author | bptato <nincsnevem662@gmail.com> | 2025-02-19 18:54:44 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-02-19 19:35:07 +0100 |
commit | 3f663454031657610bddceb169cd881754ec232a (patch) | |
tree | ae088232c3bdbe9f74cfaf19a5d9b99e0dfc8131 /src/local | |
parent | b65993b77789ddbde72f65db648ab993a5097121 (diff) | |
download | chawan-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.nim | 12 |
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 |