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
2 changed files with 15 additions and 0 deletions
14
quickjs.c
14
quickjs.c
|
@ -53074,6 +53074,20 @@ JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len)
|
||||||
TRUE);
|
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,
|
static JSValue js_array_buffer_constructor(JSContext *ctx,
|
||||||
JSValueConst new_target,
|
JSValueConst new_target,
|
||||||
int argc, JSValueConst *argv)
|
int argc, JSValueConst *argv)
|
||||||
|
|
|
@ -828,6 +828,7 @@ JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
|
||||||
JSFreeArrayBufferDataFunc *free_func, void *opaque,
|
JSFreeArrayBufferDataFunc *free_func, void *opaque,
|
||||||
JS_BOOL is_shared);
|
JS_BOOL is_shared);
|
||||||
JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
|
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);
|
void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj);
|
||||||
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);
|
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue