about summary refs log tree commit diff stats
path: root/src/js/fromjs.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-08 18:39:27 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-08 18:39:27 +0200
commit86f4c56507bc94d03e7d94be6ede884b9e7b5358 (patch)
tree929ce32ada67e8b1d57787d8e6d038fa603fc31e /src/js/fromjs.nim
parent5c891488423aa7ccbef2fb4332ff6cb4e3c05154 (diff)
downloadchawan-86f4c56507bc94d03e7d94be6ede884b9e7b5358.tar.gz
js: refactor
* prefix to-be-separated modules with js
* remove dynstreams dependency
* untangle from EmptyPromise
* move typeptr into tojs
Diffstat (limited to 'src/js/fromjs.nim')
-rw-r--r--src/js/fromjs.nim39
1 files changed, 2 insertions, 37 deletions
diff --git a/src/js/fromjs.nim b/src/js/fromjs.nim
index c5c80da1..7a8a0859 100644
--- a/src/js/fromjs.nim
+++ b/src/js/fromjs.nim
@@ -4,11 +4,9 @@ import std/tables
 import std/unicode
 
 import bindings/quickjs
-import io/promise
-import js/error
+import js/jserror
 import js/jstypes
-import js/jsutils
-import js/opaque
+import js/jsopaque
 import types/opt
 import utils/twtstr
 
@@ -374,37 +372,6 @@ proc fromJSArrayBufferView(ctx: JSContext; val: JSValue):
   )
   return ok(view)
 
-proc promiseThenCallback(ctx: JSContext; this_val: JSValue; argc: cint;
-    argv: ptr UncheckedArray[JSValue]; magic: cint;
-    func_data: ptr UncheckedArray[JSValue]): JSValue {.cdecl.} =
-  let fun = func_data[0]
-  let op = JS_GetOpaque(fun, JS_GetClassID(fun))
-  if op != nil:
-    let p = cast[EmptyPromise](op)
-    p.resolve()
-    GC_unref(p)
-    JS_SetOpaque(fun, nil)
-  return JS_UNDEFINED
-
-proc fromJSEmptyPromise(ctx: JSContext; val: JSValue): JSResult[EmptyPromise] =
-  if not JS_IsObject(val):
-    return err(newTypeError("Value is not an object"))
-  var p = EmptyPromise()
-  GC_ref(p)
-  let tmp = JS_NewObject(ctx)
-  JS_SetOpaque(tmp, cast[pointer](p))
-  let fun = JS_NewCFunctionData(ctx, promiseThenCallback, 0, 0, 1,
-    tmp.toJSValueArray())
-  JS_FreeValue(ctx, tmp)
-  let res = JS_Invoke(ctx, val, ctx.getOpaque().strRefs[jstThen], 1,
-    fun.toJSValueArray())
-  JS_FreeValue(ctx, fun)
-  if JS_IsException(res):
-    JS_FreeValue(ctx, res)
-    return err()
-  JS_FreeValue(ctx, res)
-  return ok(p)
-
 type FromJSAllowedT = (object and not (Result|Option|Table|JSValue|JSDict|
   JSArrayBuffer|JSArrayBufferView|JSUint8Array))
 
@@ -437,8 +404,6 @@ proc fromJS*[T](ctx: JSContext; val: JSValue): JSResult[T] =
     return fromJSEnum[T](ctx, val)
   elif T is JSValue:
     return ok(val)
-  elif T is EmptyPromise:
-    return fromJSEmptyPromise(ctx, val)
   elif T is ref object:
     return fromJSObject[T](ctx, val)
   elif T is void: