diff options
author | bptato <nincsnevem662@gmail.com> | 2023-07-03 18:00:29 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-07-03 18:00:29 +0200 |
commit | 6372f3bd156bd24e53ae418bfc04ffceb45139f1 (patch) | |
tree | 219045e87b8e264392e085c69862b359fa176e3c /src/js/javascript.nim | |
parent | 307003b8043998283ea0d7a64bcd5f8c2c3f554d (diff) | |
download | chawan-6372f3bd156bd24e53ae418bfc04ffceb45139f1.tar.gz |
Fix JS type conversion regressions
Diffstat (limited to 'src/js/javascript.nim')
-rw-r--r-- | src/js/javascript.nim | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/js/javascript.nim b/src/js/javascript.nim index bc2896bd..1f213f64 100644 --- a/src/js/javascript.nim +++ b/src/js/javascript.nim @@ -732,7 +732,7 @@ macro unpackReturnType(f: typed) = x = x[1].getTypeImpl() let params = x.findChild(it.kind == nnkFormalParams) let rv = params[0] - doAssert rv[0].strVal == "Opt" + doAssert rv[0].strVal == "Result" let rvv = rv[1] result = quote do: `rvv` @@ -772,13 +772,15 @@ proc fromJSOption[T](ctx: JSContext, val: JSValue): Result[Option[T], JSError] = let res = ?fromJS[T](ctx, val) return ok(some(res)) -# unwrap +# wrap proc fromJSOpt[T](ctx: JSContext, val: JSValue): Result[T, JSError] = if JS_IsUndefined(val): #TODO what about null? return err() - let res = ?fromJS[T](ctx, val) - return ok(res) + let res = fromJS[T.valType](ctx, val) + if res.isErr: + return ok(opt(T.valType)) + return ok(opt(res.get)) proc fromJSBool(ctx: JSContext, val: JSValue): Result[bool, JSError] = let ret = JS_ToBool(ctx, val) @@ -1287,11 +1289,13 @@ proc addUnionParam0(gen: var JSFuncGenerator, tt: NimNode, s: NimNode, val: NimN # 5. If V is a platform object, then: if objg.isSome: - let query = quote do: - isPlatformObject(ctx, `val`) let t = objg.get + let x = ident("x") + let query = quote do: + let `x` = fromJS[`t`](ctx, `val`) + `x`.isOk gen.addUnionParamBranch(query, quote do: - let `s` = fromJS_or_die(`t`, ctx, `val`, `ev`, `dl`), + let `s` = `x`.get, fallback) # 10. If Type(V) is Object, then: # Sequence: |