[njs] QuickJS: accept ArrayBuffer as an arument for qjs_typed_array_data().
noreply at nginx.com
noreply at nginx.com
Thu Jan 23 00:06:02 UTC 2025
details: https://github.com/nginx/njs/commit/1a482317e65d52cdaa9f0e8bff0a8e624f359b9e
branches: master
commit: 1a482317e65d52cdaa9f0e8bff0a8e624f359b9e
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Mon, 13 Jan 2025 22:00:10 -0800
description:
QuickJS: accept ArrayBuffer as an arument for qjs_typed_array_data().
---
src/qjs.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/qjs.c b/src/qjs.c
index f9615668..487a03fc 100644
--- a/src/qjs.c
+++ b/src/qjs.c
@@ -456,17 +456,25 @@ qjs_bytes_free(JSContext *ctx, qjs_bytes_t *bytes)
JSValue
qjs_typed_array_data(JSContext *ctx, JSValueConst value, njs_str_t *data)
{
- size_t byte_offset, byte_length;
+ size_t byte_offset, byte_length;
+ JSValue ab;
+
+ /* TODO: DataView. */
- value = JS_GetTypedArrayBuffer(ctx, value, &byte_offset, &byte_length,
+ ab = JS_GetTypedArrayBuffer(ctx, value, &byte_offset, &byte_length,
NULL);
- if (JS_IsException(value)) {
- return value;
+ if (JS_IsException(ab)) {
+ data->start = JS_GetArrayBuffer(ctx, &data->length, value);
+ if (data->start == NULL) {
+ return JS_EXCEPTION;
+ }
+
+ return JS_UNDEFINED;
}
- data->start = JS_GetArrayBuffer(ctx, &data->length, value);
+ data->start = JS_GetArrayBuffer(ctx, &data->length, ab);
- JS_FreeValue(ctx, value);
+ JS_FreeValue(ctx, ab);
if (data->start == NULL) {
return JS_EXCEPTION;
More information about the nginx-devel
mailing list