mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-22 13:48:11 +08:00
Add JS_IsArrayBuffer()
Unlike JS_GetArrayBuffer() it does not throw an exception if `val` is not an array buffer.
This commit is contained in:
parent
2df2bcf908
commit
696fadb3d5
14
quickjs.c
14
quickjs.c
@ -53074,6 +53074,20 @@ JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len)
|
||||
TRUE);
|
||||
}
|
||||
|
||||
/* return -1 if exception (proxy case) or TRUE/FALSE */
|
||||
int JS_IsArrayBuffer(JSContext *ctx, JSValueConst val)
|
||||
{
|
||||
JSObject *p;
|
||||
|
||||
if (js_resolve_proxy(ctx, &val, TRUE))
|
||||
return -1;
|
||||
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
|
||||
return FALSE;
|
||||
p = JS_VALUE_GET_OBJ(val);
|
||||
return p->class_id == JS_CLASS_ARRAY_BUFFER ||
|
||||
p->class_id == JS_CLASS_SHARED_ARRAY_BUFFER;
|
||||
}
|
||||
|
||||
static JSValue js_array_buffer_constructor(JSContext *ctx,
|
||||
JSValueConst new_target,
|
||||
int argc, JSValueConst *argv)
|
||||
|
@ -828,6 +828,7 @@ JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
|
||||
JSFreeArrayBufferDataFunc *free_func, void *opaque,
|
||||
JS_BOOL is_shared);
|
||||
JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
|
||||
int JS_IsArrayBuffer(JSContext *ctx, JSValueConst val);
|
||||
void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj);
|
||||
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user