about summary refs log tree commit diff stats
path: root/src/js/javascript.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-26 19:42:19 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-26 19:42:19 +0100
commit774aad55da0fc62f8de8c95dbbb3d2ad41010e3f (patch)
treec80f7a6d783261b5fe741749aa5f8a52abcc7919 /src/js/javascript.nim
parent636ddbb788a4a4dcd4dc4bc247159b6bb191ef8a (diff)
downloadchawan-774aad55da0fc62f8de8c95dbbb3d2ad41010e3f.tar.gz
dom: correct constructors, more create functions
Diffstat (limited to 'src/js/javascript.nim')
-rw-r--r--src/js/javascript.nim19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index bf81a09d..5e038290 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -1299,6 +1299,25 @@ macro jsctor*(fun: typed) =
   gen.registerConstructor()
   result = newStmtList(fun)
 
+macro jsgctor*(fun: typed) =
+  var gen = setupGenerator(fun, CONSTRUCTOR, thisname = none(string))
+  if gen.newName in existing_funcs:
+    #TODO TODO TODO implement function overloading
+    error("Function overloading hasn't been implemented yet...")
+  gen.addFixParam("this")
+  gen.addRequiredParams()
+  gen.addOptionalParams()
+  gen.finishFunCallList()
+  let jfcl = gen.jsFunCallList
+  let dl = gen.dielabel
+  gen.jsCallAndRet = quote do:
+    block `dl`:
+      return ctx.toJS(`jfcl`)
+    return JS_UNDEFINED
+  discard gen.newJSProc(getJSParams())
+  gen.registerConstructor()
+  result = newStmtList(fun)
+
 macro jshasprop*(fun: typed) =
   var gen = setupGenerator(fun, PROPERTY_HAS, thisname = some("obj"))
   if gen.newName in existing_funcs: