Add function to check if object is an arraybuffer

This commit is contained in:
2025-03-03 18:36:10 -06:00
parent ec219aeb38
commit b0fb844b54
2 changed files with 10 additions and 0 deletions

View File

@@ -51869,6 +51869,15 @@ void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj)
}
}
int JS_IsArrayBuffer(JSContext *js, JSValueConst obj)
{
JSObject *p;
if (JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) return 0;
p = JS_VALUE_GET_OBJ(obj);
if (p->class_id != JS_CLASS_ARRAY_BUFFER && p->class_id != JS_CLASS_SHARED_ARRAY_BUFFER) return 0;
return 1;
}
/* get an ArrayBuffer or SharedArrayBuffer */
static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValueConst obj)
{

View File

@@ -947,6 +947,7 @@ JSValue JS_NewArrayBuffer(JSContext *ctx, uint8_t *buf, size_t len,
JS_BOOL is_shared);
JSValue JS_NewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len);
void JS_DetachArrayBuffer(JSContext *ctx, JSValueConst obj);
int JS_IsArrayBuffer(JSContext *js, JSValueConst obj);
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj);
typedef enum JSTypedArrayEnum {