Add methods to detect arrays (#282)
I have a use case where a user can hand me many different kinds of types, array buffer, uint8array, or a string, and I need to be able to distingush between them. Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
This commit is contained in:
parent
377e6a6c06
commit
ec4f957ca1
2 changed files with 9 additions and 0 deletions
|
@ -48224,6 +48224,10 @@ JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
|
|||
buf, free_func, opaque, FALSE);
|
||||
}
|
||||
|
||||
JS_BOOL JS_IsArrayBuffer(JSValue obj) {
|
||||
return JS_GetClassID(obj) == JS_CLASS_ARRAY_BUFFER;
|
||||
}
|
||||
|
||||
/* create a new ArrayBuffer of length 'len' and copy 'buf' to it */
|
||||
JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len)
|
||||
{
|
||||
|
@ -50720,6 +50724,9 @@ JSValue JS_NewUint8ArrayCopy(JSContext *ctx, const uint8_t *buf, size_t len)
|
|||
return js_new_uint8array(ctx, buffer);
|
||||
}
|
||||
|
||||
JS_BOOL JS_IsUint8Array(JSValue obj) {
|
||||
return JS_GetClassID(obj) == JS_CLASS_UINT8_ARRAY;
|
||||
}
|
||||
|
||||
/* Atomics */
|
||||
#ifdef CONFIG_ATOMICS
|
||||
|
|
|
@ -748,6 +748,7 @@ JS_EXTERN JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
|
|||
JS_EXTERN JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
|
||||
JS_EXTERN void JS_DetachArrayBuffer(JSContext *ctx, JSValue obj);
|
||||
JS_EXTERN uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValue obj);
|
||||
JS_EXTERN JS_BOOL JS_IsArrayBuffer(JSValue obj);
|
||||
JS_EXTERN uint8_t *JS_GetUint8Array(JSContext *ctx, size_t *psize, JSValue obj);
|
||||
JS_EXTERN JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValue obj,
|
||||
size_t *pbyte_offset,
|
||||
|
@ -756,6 +757,7 @@ JS_EXTERN JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValue obj,
|
|||
JS_EXTERN JSValue JS_NewUint8Array(JSContext *ctx, uint8_t *buf, size_t len,
|
||||
JSFreeArrayBufferDataFunc *free_func, void *opaque,
|
||||
JS_BOOL is_shared);
|
||||
JS_EXTERN JS_BOOL JS_IsUint8Array(JSValue obj);
|
||||
JS_EXTERN JSValue JS_NewUint8ArrayCopy(JSContext *ctx, const uint8_t *buf, size_t len);
|
||||
typedef struct {
|
||||
void *(*sab_alloc)(void *opaque, size_t size);
|
||||
|
|
Loading…
Reference in a new issue