commit 0673e5d7a8cf804d7cfd4ec293298235b5accc20
parent 70dbb6b2b52c3ae6c87d83fc28c262b70c40c34b
Author: Charlie Gordon <github@chqrlie.org>
Date: Sat, 23 Mar 2024 13:19:04 +0100
Fix endianness handling in `js_dataview_getValue` / `js_dataview_setValue`
Diffstat:
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/quickjs/quickjs.c b/quickjs/quickjs.c
@@ -55454,7 +55454,8 @@ static JSValue js_dataview_getValue(JSContext *ctx,
{
JSTypedArray *ta;
JSArrayBuffer *abuf;
- int is_swap, size;
+ BOOL littleEndian, is_swap;
+ int size;
uint8_t *ptr;
uint32_t v;
uint64_t pos;
@@ -55465,9 +55466,8 @@ static JSValue js_dataview_getValue(JSContext *ctx,
size = 1 << typed_array_size_log2(class_id);
if (JS_ToIndex(ctx, &pos, argv[0]))
return JS_EXCEPTION;
- is_swap = TRUE;
- if (argc > 1)
- is_swap = !JS_ToBool(ctx, argv[1]);
+ littleEndian = argc > 1 && JS_ToBool(ctx, argv[1]);
+ is_swap = littleEndian ^ !is_be();
abuf = ta->buffer->u.array_buffer;
if (abuf->detached)
return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
@@ -55552,7 +55552,8 @@ static JSValue js_dataview_setValue(JSContext *ctx,
{
JSTypedArray *ta;
JSArrayBuffer *abuf;
- int is_swap, size;
+ BOOL littleEndian, is_swap;
+ int size;
uint8_t *ptr;
uint64_t v64;
uint32_t v;
@@ -55591,9 +55592,8 @@ static JSValue js_dataview_setValue(JSContext *ctx,
v64 = u.u64;
}
}
- is_swap = TRUE;
- if (argc > 2)
- is_swap = !JS_ToBool(ctx, argv[2]);
+ littleEndian = argc > 2 && JS_ToBool(ctx, argv[2]);
+ is_swap = littleEndian ^ !is_be();
abuf = ta->buffer->u.array_buffer;
if (abuf->detached)
return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);