diff options
-rw-r--r-- | monoucha/fromjs.nim | 3 | ||||
-rw-r--r-- | monoucha/jstypes.nim | 1 | ||||
-rw-r--r-- | monoucha/quickjs.nim | 18 |
3 files changed, 21 insertions, 1 deletions
diff --git a/monoucha/fromjs.nim b/monoucha/fromjs.nim index 4bd52605..7cf5db9a 100644 --- a/monoucha/fromjs.nim +++ b/monoucha/fromjs.nim @@ -483,7 +483,8 @@ proc fromJS*(ctx: JSContext; val: JSValue; res: out JSArrayBufferView): abuf: abuf, offset: offset, nmemb: nmemb, - nsize: nsize + nsize: nsize, + t: JS_GetTypedArrayType(val) ) return ok() diff --git a/monoucha/jstypes.nim b/monoucha/jstypes.nim index cef5527e..af471132 100644 --- a/monoucha/jstypes.nim +++ b/monoucha/jstypes.nim @@ -53,6 +53,7 @@ type offset*: csize_t # offset into the buffer nmemb*: csize_t # number of members nsize*: csize_t # member size + t*: cint # type JSUint8Array* = object abuf*: JSArrayBuffer diff --git a/monoucha/quickjs.nim b/monoucha/quickjs.nim index 749753e7..ea70672c 100644 --- a/monoucha/quickjs.nim +++ b/monoucha/quickjs.nim @@ -668,11 +668,29 @@ proc JS_GetArrayBuffer*(ctx: JSContext; psize: var csize_t; obj: JSValue): proc JS_IsArrayBuffer*(obj: JSValue): JS_BOOL proc JS_GetUint8Array*(ctx: JSContext; psize: ptr csize_t; obj: JSValue): ptr UncheckedArray[uint8] + +type JSTypedArrayEnum* {.size: sizeof(cint).} = enum + JS_TYPED_ARRAY_UINT8C = 0 + JS_TYPED_ARRAY_INT8 + JS_TYPED_ARRAY_UINT8 + JS_TYPED_ARRAY_INT16 + JS_TYPED_ARRAY_UINT16 + JS_TYPED_ARRAY_INT32 + JS_TYPED_ARRAY_UINT32 + JS_TYPED_ARRAY_BIG_INT64 + JS_TYPED_ARRAY_BIG_UINT64 + JS_TYPED_ARRAY_FLOAT16 + JS_TYPED_ARRAY_FLOAT32 + JS_TYPED_ARRAY_FLOAT64 + +proc JS_NewTypedArray*(ctx: JSContext; argc: cint; + argv: ptr UncheckedArray[JSValue]; array_type: JSTypedArrayEnum): JSValue proc JS_GetTypedArrayBuffer*(ctx: JSContext; obj: JSValue; pbyte_offset, pbyte_length, pbytes_per_element: var csize_t): JSValue proc JS_NewUint8Array*(ctx: JSContext; buf: ptr UncheckedArray[uint8]; len: csize_t; free_func: JSFreeArrayBufferDataFunc; opaque: pointer; is_shared: JS_BOOL): JSValue +proc JS_GetTypedArrayType*(obj: JSValue): cint proc JS_IsUint8Array*(obj: JSValue): JS_BOOL proc JS_NewUint8ArrayCopy*(ctx: JSContext; buf: ptr UncheckedArray[uint8]; len: csize_t): JSValue |