Update JS_NewTypedArray()
to C level API
This commit is contained in:
parent
97be5a32af
commit
9c2a19eaac
2 changed files with 17 additions and 5 deletions
18
quickjs.c
18
quickjs.c
|
@ -53429,14 +53429,26 @@ static JSValue js_typed_array_get_byteOffset(JSContext *ctx,
|
||||||
return JS_NewInt32(ctx, ta->offset);
|
return JS_NewInt32(ctx, ta->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
|
JSValue JS_NewTypedArray(JSContext *ctx, size_t length, const void *init,
|
||||||
JSTypedArrayEnum type)
|
JSTypedArrayEnum type)
|
||||||
{
|
{
|
||||||
|
JSValue args[1], ret;
|
||||||
|
|
||||||
if (type < JS_TYPED_ARRAY_UINT8C || type > JS_TYPED_ARRAY_FLOAT64)
|
if (type < JS_TYPED_ARRAY_UINT8C || type > JS_TYPED_ARRAY_FLOAT64)
|
||||||
return JS_ThrowRangeError(ctx, "invalid typed array type");
|
return JS_ThrowRangeError(ctx, "invalid typed array type");
|
||||||
|
|
||||||
return js_typed_array_constructor(ctx, JS_UNDEFINED, argc, argv,
|
args[0] = JS_NewInt64(ctx, length);
|
||||||
JS_CLASS_UINT8C_ARRAY + type);
|
ret = js_typed_array_constructor(ctx, JS_UNDEFINED, 1, (JSValueConst *)args,
|
||||||
|
JS_CLASS_UINT8C_ARRAY + type);
|
||||||
|
JS_FreeValue(ctx, args[0]);
|
||||||
|
|
||||||
|
if (init != NULL && !JS_IsException(ret)) {
|
||||||
|
JSObject *p = JS_VALUE_GET_OBJ(ret);
|
||||||
|
size_t len = length * (1 << typed_array_size_log2(p->class_id));
|
||||||
|
memcpy(p->u.array.u.ptr, init, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the buffer associated to the typed array or an exception if
|
/* Return the buffer associated to the typed array or an exception if
|
||||||
|
|
|
@ -845,8 +845,8 @@ typedef enum JSTypedArrayEnum {
|
||||||
JS_TYPED_ARRAY_FLOAT64,
|
JS_TYPED_ARRAY_FLOAT64,
|
||||||
} JSTypedArrayEnum;
|
} JSTypedArrayEnum;
|
||||||
|
|
||||||
JSValue JS_NewTypedArray(JSContext *ctx, int argc, JSValueConst *argv,
|
JSValue JS_NewTypedArray(JSContext *ctx, size_t length, const void *init,
|
||||||
JSTypedArrayEnum array_type);
|
JSTypedArrayEnum type);
|
||||||
JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
|
JSValue JS_GetTypedArrayBuffer(JSContext *ctx, JSValueConst obj,
|
||||||
size_t *pbyte_offset,
|
size_t *pbyte_offset,
|
||||||
size_t *pbyte_length,
|
size_t *pbyte_length,
|
||||||
|
|
Loading…
Reference in a new issue