about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/buffer/buffer.nim9
-rw-r--r--src/display/client.nim9
-rw-r--r--src/js/javascript.nim18
-rw-r--r--src/utils/twtstr.nim7
4 files changed, 27 insertions, 16 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim
index 9b464dfd..59c12a14 100644
--- a/src/buffer/buffer.nim
+++ b/src/buffer/buffer.nim
@@ -1206,9 +1206,12 @@ proc handleError(buffer: Buffer, fd: int, err: OSErrorCode) =
 proc runBuffer(buffer: Buffer, rfd: int) =
   buffer.rfd = rfd
   while buffer.alive:
-    {.warning[CastSizes]:off.} # not our bug. TODO remove when fixed
-    let events = buffer.selector.select(-1)
-    {.warning[CastSizes]:on.}
+    when defined(CastSizes):
+      {.warning[CastSizes]:off.} # not our bug. TODO remove when fixed
+      let events = buffer.selector.select(-1)
+      {.warning[CastSizes]:on.}
+    else:
+      let events = buffer.selector.select(-1)
     for event in events:
       if Read in event.events:
         buffer.handleRead(event.fd)
diff --git a/src/display/client.nim b/src/display/client.nim
index 7dbf4713..79b433ae 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -370,9 +370,12 @@ proc inputLoop(client: Client) =
   selector.registerHandle(int(client.console.tty.getFileHandle()), {Read}, nil)
   let sigwinch = selector.registerSignal(int(SIGWINCH), nil)
   while true:
-    {.warning[CastSizes]:off.} # not our bug. TODO remove when fixed
-    let events = client.selector.select(-1)
-    {.warning[CastSizes]:on.}
+    when defined(CastSizes):
+      {.warning[CastSizes]:off.} # not our bug. TODO remove when fixed
+      let events = client.selector.select(-1)
+      {.warning[CastSizes]:on.}
+    else:
+      let events = client.selector.select(-1)
     for event in events:
       if Read in event.events:
         client.handleRead(event.fd)
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:
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index c7ba2db6..f735252c 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -8,10 +8,11 @@ import options
 import punycode
 
 import bindings/libunicode
-import data/idna
 import data/charwidth
-import utils/opt
+import data/idna
+import js/javascript
 import utils/map
+import utils/opt
 
 when defined(posix):
   import posix
@@ -1074,7 +1075,7 @@ func twidth*(s: string, w: int): int =
 func breaksWord*(r: Rune): bool =
   return not (r.isDigitAscii() or r.width() == 0 or r.isAlpha())
 
-type BoundaryFunction* = proc(x: Rune): Opt[bool]
+type BoundaryFunction* = proc(x: Rune): Result[bool, JSError]
 
 proc breaksWord*(r: Rune, check: Opt[BoundaryFunction]): bool =
   if check.isSome: