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/bindings | |
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/bindings')
-rw-r--r-- | src/bindings/quickjs.nim | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim index a401bf1b..f6719e3d 100644 --- a/src/bindings/quickjs.nim +++ b/src/bindings/quickjs.nim @@ -90,6 +90,8 @@ type JSFreeArrayBufferDataFunc* = proc (rt: JSRuntime, opaque, p: pointer) {.cdecl.} + JSString* {.importc: "JSString*", header: qjsheader.} = distinct pointer + JSPropertyDescriptor* {.importc, header: qjsheader.} = object flags*: cint value*: JSValue @@ -264,6 +266,9 @@ const const JS_PARSE_JSON_EXT* = (1 shl 0) +template JS_VALUE_GET_STRING*(v: untyped): JSString = + JSString(JS_VALUE_GET_PTR(v)) + template JS_CFUNC_DEF*(n: string, len: uint8, func1: JSCFunction): JSCFunctionListEntry = JSCFunctionListEntry(name: cstring(n), @@ -432,6 +437,12 @@ proc JS_ToCStringLen*(ctx: JSContext, plen: ptr csize_t, val1: JSValue): cstring proc JS_ToCString*(ctx: JSContext, val1: JSValue): cstring proc JS_FreeCString*(ctx: JSContext, `ptr`: cstring) +proc JS_NewNarrowStringLen*(ctx: JSContext, s: cstring, len: csize_t): JSValue +proc JS_IsStringWideChar*(str: JSString): JS_BOOL +proc JS_GetNarrowStringBuffer*(str: JSString): ptr UncheckedArray[uint8] +proc JS_GetWideStringBuffer*(str: JSString): ptr UncheckedArray[uint16] +proc JS_GetStringLength*(str: JSString): uint32 + proc JS_Eval*(ctx: JSContext, input: cstring, input_len: cint, filename: cstring, eval_flags: cint): JSValue proc JS_SetInterruptHandler*(rt: JSRuntime, cb: JSInterruptHandler, opaque: pointer) proc JS_SetCanBlock*(rt: JSRuntime, can_block: JS_BOOL) |