Add JS_NewTypedArray()
(#272)
Author: Dmitry Volyntsev <xeioexception@gmail.com> Date: Wed May 8 14:17:00 2024 -0700
This commit is contained in:
parent
f3bf7afb62
commit
044127b43f
2 changed files with 27 additions and 0 deletions
10
quickjs.c
10
quickjs.c
|
@ -49335,6 +49335,16 @@ static JSValue js_typed_array_get_byteOffset(JSContext *ctx,
|
||||||
return js_int32(ta->offset);
|
return js_int32(ta->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
|
||||||
|
JSTypedArrayEnum type)
|
||||||
|
{
|
||||||
|
if (type < JS_TYPED_ARRAY_UINT8C || type > JS_TYPED_ARRAY_FLOAT64)
|
||||||
|
return JS_ThrowRangeError(ctx, "invalid typed array type");
|
||||||
|
|
||||||
|
return js_typed_array_constructor(ctx, JS_UNDEFINED, argc, argv,
|
||||||
|
JS_CLASS_UINT8C_ARRAY + type);
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the buffer associated to the typed array or an exception if
|
/* Return the buffer associated to the typed array or an exception if
|
||||||
it is not a typed array or if the buffer is detached. pbyte_offset,
|
it is not a typed array or if the buffer is detached. pbyte_offset,
|
||||||
pbyte_length or pbytes_per_element can be NULL. */
|
pbyte_length or pbytes_per_element can be NULL. */
|
||||||
|
|
17
quickjs.h
17
quickjs.h
|
@ -751,6 +751,23 @@ JS_EXTERN void JS_DetachArrayBuffer(JSContext *ctx, JSValue obj);
|
||||||
JS_EXTERN uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, 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 JS_BOOL JS_IsArrayBuffer(JSValue obj);
|
||||||
JS_EXTERN uint8_t *JS_GetUint8Array(JSContext *ctx, size_t *psize, JSValue obj);
|
JS_EXTERN uint8_t *JS_GetUint8Array(JSContext *ctx, size_t *psize, JSValue obj);
|
||||||
|
|
||||||
|
typedef enum JSTypedArrayEnum {
|
||||||
|
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_FLOAT32,
|
||||||
|
JS_TYPED_ARRAY_FLOAT64,
|
||||||
|
} JSTypedArrayEnum;
|
||||||
|
|
||||||
|
JS_EXTERN JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
|
||||||
|
JSTypedArrayEnum array_type);
|
||||||
JS_EXTERN JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValue obj,
|
JS_EXTERN JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValue obj,
|
||||||
size_t *pbyte_offset,
|
size_t *pbyte_offset,
|
||||||
size_t *pbyte_length,
|
size_t *pbyte_length,
|
||||||
|
|
Loading…
Reference in a new issue