diff options
author | Charlie Gordon <github@chqrlie.org> | 2024-03-23 13:19:04 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-14 19:00:24 +0200 |
commit | f8717c285e0203bbf3a01aa92bff23682cf38529 (patch) | |
tree | be2e08a0acb3408ac03b0db59d80455200816e04 | |
parent | 6cdd45bbfe55616097e141f817771616bba6ebe3 (diff) | |
download | chawan-f8717c285e0203bbf3a01aa92bff23682cf38529.tar.gz |
Fix endianness handling in `js_dataview_getValue` / `js_dataview_setValue`
-rw-r--r-- | lib/quickjs/quickjs.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/quickjs/quickjs.c b/lib/quickjs/quickjs.c index ca892728..1fb0f824 100644 --- a/lib/quickjs/quickjs.c +++ b/lib/quickjs/quickjs.c @@ -55269,7 +55269,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; @@ -55280,9 +55281,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); @@ -55367,7 +55367,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; @@ -55406,9 +55407,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); |