diff options
author | bellard <6490144+bellard@users.noreply.github.com> | 2025-06-14 11:30:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-14 11:30:13 +0200 |
commit | 9b935dba42c2c108759c50c0c55ef0003b53e725 (patch) | |
tree | 855ce82890c6b6052169dfee55035f5b5b8f38b5 /quickjs.c | |
parent | 638ec8ca5e1d4aed002a9fb3ef3358e2a6bc42ab (diff) | |
parent | 0f7eadf95ce8509af1df838ed3e83fd68a04e269 (diff) | |
download | quickjs-9b935dba42c2c108759c50c0c55ef0003b53e725.tar.gz quickjs-9b935dba42c2c108759c50c0c55ef0003b53e725.zip |
Merge pull request #418 from nickva/fix-byteoffset-for-detached-array-buffers
Fix byteOffset for detached array buffers
Diffstat (limited to 'quickjs.c')
-rw-r--r-- | quickjs.c | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -54017,7 +54017,8 @@ static JSValue js_typed_array_subarray(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { JSValueConst args[4]; - JSValue arr, byteOffset, ta_buffer; + JSValue arr, ta_buffer; + JSTypedArray *ta; JSObject *p; int len, start, final, count, shift, offset; @@ -54034,12 +54035,10 @@ static JSValue js_typed_array_subarray(JSContext *ctx, JSValueConst this_val, goto exception; } count = max_int(final - start, 0); - byteOffset = js_typed_array_get_byteOffset(ctx, this_val, 0); - if (JS_IsException(byteOffset)) - goto exception; shift = typed_array_size_log2(p->class_id); - offset = JS_VALUE_GET_INT(byteOffset) + (start << shift); - JS_FreeValue(ctx, byteOffset); + ta = p->u.typed_array; + /* Read byteOffset (ta->offset) even if detached */ + offset = ta->offset + (start << shift); ta_buffer = js_typed_array_get_buffer(ctx, this_val, 0); if (JS_IsException(ta_buffer)) goto exception; |