diff options
author | bptato <nincsnevem662@gmail.com> | 2023-10-21 23:34:56 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-10-21 23:40:24 +0200 |
commit | 18008acc141a55449b28c1af487a080c4bbcb355 (patch) | |
tree | a81872bfc2e2add0b0c9b6f65f3be15f4d2790c8 /src/js/fromjs.nim | |
parent | 69870f3b974e65d61b564b396e01d21cc023e6e9 (diff) | |
download | chawan-18008acc141a55449b28c1af487a080c4bbcb355.tar.gz |
base64: reduce pointless re-coding using JSString
We now expose some functions from QuickJS to interact with JavaScript strings without re-encoding them into UTF-8.
Diffstat (limited to 'src/js/fromjs.nim')
-rw-r--r-- | src/js/fromjs.nim | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/js/fromjs.nim b/src/js/fromjs.nim index b2e1cc91..80fdc1cd 100644 --- a/src/js/fromjs.nim +++ b/src/js/fromjs.nim @@ -54,6 +54,9 @@ 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] = if not JS_IsNumber(val): @@ -449,6 +452,8 @@ 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 char: return fromJSChar(ctx, val) elif T is Rune: |