mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-25 07:08:12 +08:00
Improve JS_GetArrayBuffer
This commit is contained in:
parent
6e2e68fd08
commit
83fa050312
11
quickjs.c
11
quickjs.c
@ -53214,7 +53214,8 @@ static JSArrayBuffer *js_get_array_buffer(JSContext *ctx, JSValueConst obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* return NULL if exception. WARNING: any JS call can detach the
|
/* return NULL if exception. WARNING: any JS call can detach the
|
||||||
buffer and render the returned pointer invalid */
|
buffer and render the returned pointer invalid. psize can be
|
||||||
|
NULL. */
|
||||||
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj)
|
uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj)
|
||||||
{
|
{
|
||||||
JSArrayBuffer *abuf = js_get_array_buffer(ctx, obj);
|
JSArrayBuffer *abuf = js_get_array_buffer(ctx, obj);
|
||||||
@ -53224,10 +53225,14 @@ uint8_t *JS_GetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst obj)
|
|||||||
JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
|
JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
*psize = abuf->byte_length;
|
if (psize) {
|
||||||
|
*psize = abuf->byte_length;
|
||||||
|
}
|
||||||
return abuf->data;
|
return abuf->data;
|
||||||
fail:
|
fail:
|
||||||
*psize = 0;
|
if (psize) {
|
||||||
|
*psize = 0;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user