about summary refs log tree commit diff stats
path: root/src/js
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-02 18:11:42 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-02 18:11:42 +0100
commit3419a65f2d4000a401e77217a1d6d00c6578ed09 (patch)
tree021d6a6dee89d09b0098f81f71d238fb02c64081 /src/js
parentea1043eeb44c3a5ca617e547797023c0cfac63f3 (diff)
downloadchawan-3419a65f2d4000a401e77217a1d6d00c6578ed09.tar.gz
quickjs: reduce diff with upstream
* the uint8array thing is probably from txiki.js, but we never used it
* upstream now has JS_GetClassID, importing that instead... (so this
  commit won't build :/)
Diffstat (limited to 'src/js')
-rw-r--r--src/js/base64.nim9
-rw-r--r--src/js/fromjs.nim5
2 files changed, 8 insertions, 6 deletions
diff --git a/src/js/base64.nim b/src/js/base64.nim
index c9375c13..3d540664 100644
--- a/src/js/base64.nim
+++ b/src/js/base64.nim
@@ -17,13 +17,20 @@ proc atob*(data: string): DOMResult[NarrowString] =
     return errDOMException("Invalid character in string",
       "InvalidCharacterError")
 
-proc btoa*(data: JSString): DOMResult[string] =
+proc btoa*(ctx: JSContext, data: JSValue): DOMResult[string] =
+  let data = JS_ToString(ctx, data)
+  if JS_IsException(data):
+    return err()
+  assert JS_IsString(data)
   if JS_IsStringWideChar(data):
+    JS_FreeValue(ctx, data)
     return errDOMException("Invalid character in string",
       "InvalidCharacterError")
   let len = int(JS_GetStringLength(data))
   if len == 0:
+    JS_FreeValue(ctx, data)
     return ok("")
   let buf = JS_GetNarrowStringBuffer(data)
   let res = base64.encode(toOpenArray(buf, 0, len - 1))
+  JS_FreeValue(ctx, data)
   return ok(res)
diff --git a/src/js/fromjs.nim b/src/js/fromjs.nim
index f0ff8a91..112efd75 100644
--- a/src/js/fromjs.nim
+++ b/src/js/fromjs.nim
@@ -76,9 +76,6 @@ func fromJSString(ctx: JSContext, val: JSValue): JSResult[string] =
   JS_FreeCString(ctx, outp)
   return ok(ret)
 
-func fromJSString2(ctx: JSContext, val: JSValue): JSResult[JSString] =
-  return ok(JS_VALUE_GET_STRING(val))
-
 func fromJSInt[T: SomeInteger](ctx: JSContext, val: JSValue):
     JSResult[T] =
   when T is int:
@@ -477,8 +474,6 @@ type FromJSAllowedT = (object and not (Result|Option|Table|JSValue|JSDict|
 proc fromJS*[T](ctx: JSContext, val: JSValue): JSResult[T] =
   when T is string:
     return fromJSString(ctx, val)
-  elif T is JSString:
-    return fromJSString2(ctx, val)
   elif T is (proc):
     return fromJSFunction[T](ctx, val)
   elif T is Option: