diff --git a/quickjs.c b/quickjs.c index bf5989d..702c4d3 100644 --- a/quickjs.c +++ b/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) diff --git a/quickjs.h b/quickjs.h index 84a7e0b..f608b5c 100644 --- a/quickjs.h +++ b/quickjs.h @@ -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);