summaryrefslogtreecommitdiff
path: root/quickjs.c
diff options
context:
space:
mode:
authorCharlie Gordon <github@chqrlie.org>2024-03-23 13:19:04 +0100
committerCharlie Gordon <github@chqrlie.org>2024-03-23 13:19:04 +0100
commit3b45d155c77bbdfe9177b1e03db830d2aff0b2a8 (patch)
tree6a02973be35f65c6dc0f7902aa4284bb549218ac /quickjs.c
parent653b2276cbc606e1f883af5a0d82f2677327ea7a (diff)
downloadquickjs-3b45d155c77bbdfe9177b1e03db830d2aff0b2a8.tar.gz
quickjs-3b45d155c77bbdfe9177b1e03db830d2aff0b2a8.zip
Fix endianness handling in `js_dataview_getValue` / `js_dataview_setValue`
Diffstat (limited to 'quickjs.c')
-rw-r--r--quickjs.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/quickjs.c b/quickjs.c
index bd0c9e3..e8fdd8a 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -55157,7 +55157,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;
@@ -55168,9 +55169,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);
@@ -55255,7 +55255,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;
@@ -55294,9 +55295,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);