about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-16 19:25:09 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-16 19:25:22 +0100
commit5b98b39db1fa151cbe95b84d370ebe3f17fbea7f (patch)
tree87c0a03387b7e0a1b7102326beea533691551148
parentaaeb72f3ac190a8ff1864a85fa651b871e6bd8db (diff)
downloadchawan-5b98b39db1fa151cbe95b84d370ebe3f17fbea7f.tar.gz
fromjs: add type information to JSArrayBufferView + some bindings
-rw-r--r--monoucha/fromjs.nim3
-rw-r--r--monoucha/jstypes.nim1
-rw-r--r--monoucha/quickjs.nim18
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