about summary refs log tree commit diff stats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-02 01:36:18 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-02 01:36:18 +0100
commit2fb87f5c609be4d42f71fbd6a9439de47c6d0189 (patch)
tree5769a99d1078ac483ec8a37664cac64139e7716d /src/js
parentd206c2e55515924e1f6a68fdbd70ff21779cdf73 (diff)
downloadchawan-2fb87f5c609be4d42f71fbd6a9439de47c6d0189.tar.gz
js: get rid of emit
now I know how to :P
Diffstat (limited to 'src/js')
-rw-r--r--src/js/javascript.nim37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index 361d9df7..fd0bb818 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -1500,7 +1500,6 @@ proc bindCheckDestroy(stmts: NimNode, info: RegistryInfo) =
 
 proc bindEndStmts(endstmts: NimNode, info: RegistryInfo) =
   let jsname = info.jsname
-  let cdname = "classDef" & jsname
   let dfin = info.dfin
   let classDef = info.classDef
   if info.propGetFun.kind != nnkNilLit or
@@ -1514,33 +1513,27 @@ proc bindEndStmts(endstmts: NimNode, info: RegistryInfo) =
     let propHasFun = info.propHasFun
     let propNamesFun = info.propNamesFun
     endstmts.add(quote do:
-      # No clue how to do this in pure nim.
-      {.emit: ["""
-static JSClassExoticMethods exotic = {
-	.get_own_property = """, `propGetFun`, """,
-        .get_own_property_names = """, `propNamesFun`, """,
-	.has_property = """, `propHasFun`, """,
-	.set_property = """, `propSetFun`, """,
-	.delete_property = """, `propDelFun`, """
-};
-static JSClassDef """, `cdname`, """ = {
-	""", "\"", `jsname`, "\"", """,
-        .can_destroy = """, `dfin`, """,
-	.exotic = &exotic
-};"""
-      ].}
-      var `classDef`: JSClassDefConst
-      {.emit: [
-        `classDef`, " = &", `cdname`, ";"
-      ].}
+      var exotic {.global.} = JSClassExoticMethods(
+        get_own_property: `propGetFun`,
+        get_own_property_names: `propNamesFun`,
+        has_property: `propHasFun`,
+        set_property: `propSetFun`,
+        delete_property: `propDelFun`
+      )
+      var cd {.global.} = JSClassDef(
+        class_name: `jsname`,
+        can_destroy: `dfin`,
+        exotic: addr exotic
+      )
+      let `classDef` = JSClassDefConst(addr cd)
     )
   else:
     endstmts.add(quote do:
-      const cd = JSClassDef(
+      var cd {.global.} = JSClassDef(
         class_name: `jsname`,
         can_destroy: `dfin`
       )
-      let `classDef` = JSClassDefConst(unsafeAddr cd))
+      let `classDef` = JSClassDefConst(addr cd))
 
 macro registerType*(ctx: typed, t: typed, parent: JSClassID = 0,
     asglobal = false, nointerface = false, name: static string = "",