about summary refs log tree commit diff stats
path: root/src/js/fromjs.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-17 21:14:51 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-17 21:20:04 +0100
commitfc8937b53327f99b5809f78e3257e62a05bd1c79 (patch)
tree64655d81478c9fb8ac93d67259c60cb4fd246b5f /src/js/fromjs.nim
parentd385d07b197cef65c2d2a800378de9152551e3e6 (diff)
downloadchawan-fc8937b53327f99b5809f78e3257e62a05bd1c79.tar.gz
config: clean up/simplify
* Parse the default config at runtime. There's no significant
  performance difference, but this makes it much less painful to write
  config code.
* Add better error reporting
* Make fromJS2 easier to use
* Unquote ChaPaths while parsing config
Diffstat (limited to 'src/js/fromjs.nim')
-rw-r--r--src/js/fromjs.nim10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/js/fromjs.nim b/src/js/fromjs.nim
index 112efd75..be90e192 100644
--- a/src/js/fromjs.nim
+++ b/src/js/fromjs.nim
@@ -471,6 +471,11 @@ proc fromJSEmptyPromise(ctx: JSContext, val: JSValue): JSResult[EmptyPromise] =
 type FromJSAllowedT = (object and not (Result|Option|Table|JSValue|JSDict|
   JSArrayBuffer|JSArrayBufferView|JSUint8Array))
 
+macro fromJS2(ctx: JSContext; val: JSValue; x: static string): untyped =
+  let id = ident("fromJS" & x)
+  return quote do:
+    `id`(`ctx`, `val`)
+
 proc fromJS*[T](ctx: JSContext, val: JSValue): JSResult[T] =
   when T is string:
     return fromJSString(ctx, val)
@@ -511,11 +516,8 @@ proc fromJS*[T](ctx: JSContext, val: JSValue): JSResult[T] =
     return fromJSArrayBuffer(ctx, val)
   elif T is JSArrayBufferView:
     return fromJSArrayBufferView(ctx, val)
-  elif compiles(fromJS2(ctx, val, result)):
-    fromJS2(ctx, val, result)
   else:
-    static:
-      error("Unrecognized type " & $T)
+    return fromJS2(ctx, val, $T)
 
 const JS_ATOM_TAG_INT = cuint(1u32 shl 31)