Type checks for typed arrays and array buffers.
I just found myself in need of this as well, thanks! 🙌 It'd be great if the function could also take a JSTypedArrayEnum pointer and, if it's not NULL, write the type of the view when val is a typed array.
I just found myself in need of this as well, thanks! 🙌 It'd be great if the function could also take a
JSTypedArrayEnumpointer and, if it's notNULL, write the type of the view whenvalis a typed array.
I can do this as well, any objections from reviewers @saghul?
No objections from me, but I would handle that in a separate PR.
🙌 It'd be great if the function could also take a
JSTypedArrayEnumpointer and, if it's notNULL, write the type of the view whenvalis a typed array.
I would favor an API that retrieves the typed array type, length and data address. A generalized version of JS_GetUint8Array.
As a matter of fact, this would make JS_IsTypedArray redundant, so maybe we should just have this:
struct JSTypedArrayDescription {
JSTypedArrayEnum type;
size_t length;
void *data;
};
// Return value is -1 for proxy errors, 0 if `obj` is not a typed array, 1 if it is a typed array.
// The structure pointed to by `desc` is filled on success unless `desc` is a null pointer.
int JS_GetTypedArray(JSContext *ctx, JSValueConst obj, struct JSTypedArrayDescription *desc);
OK, I have no objection. Will update.
@chqrlie
Return value is -1 for proxy errors
Do we still want to check for proxy case here, given that JS_GetTypedArrayBuffer does not do that?
The change is approved, but not merged. Any plans to align this PR with https://github.com/bellard/quickjs/pull/294?
The change is approved, but not merged. Any plans to align this PR with #294?
Yes, we are discussing prototypes... Trying to cook an API in a hurry does not work. We have to let it simmer for a few days
Agree. I have no problem with it. Just let me know of your intentions, it is enough.
This would be really useful, in particular because I don't think there's currently any way to get the opaque pointer that's used when the typed array is freed. Any plans to merge this?