summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2025-04-22 19:05:36 +0200
committerFabrice Bellard <fabrice@bellard.org>2025-04-22 19:05:36 +0200
commit08a28c0cc3b2af966fd2ae900869c7ffe7b2b9f2 (patch)
tree0b154382ecab1f91ec7a9869a8d4ab21a9afef76
parenta0a760f74fd0c28ee56dc0971ba60e45d844e41f (diff)
downloadquickjs-08a28c0cc3b2af966fd2ae900869c7ffe7b2b9f2.tar.gz
quickjs-08a28c0cc3b2af966fd2ae900869c7ffe7b2b9f2.zip
fixed TypedArray.prototype.with with detached ArrayBuffer
-rw-r--r--quickjs.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/quickjs.c b/quickjs.c
index 8d5150d..d6d1478 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -51922,6 +51922,8 @@ static JSValue js_typed_array_with(JSContext *ctx, JSValueConst this_val,
p = get_typed_array(ctx, this_val, /*is_dataview*/0);
if (!p)
return JS_EXCEPTION;
+ if (typed_array_is_detached(ctx, p))
+ return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
if (JS_ToInt64Sat(ctx, &idx, argv[0]))
return JS_EXCEPTION;
@@ -51929,13 +51931,14 @@ static JSValue js_typed_array_with(JSContext *ctx, JSValueConst this_val,
len = p->u.array.count;
if (idx < 0)
idx = len + idx;
- if (idx < 0 || idx >= len)
- return JS_ThrowRangeError(ctx, "invalid array index");
val = JS_ToPrimitive(ctx, argv[1], HINT_NUMBER);
if (JS_IsException(val))
return JS_EXCEPTION;
+ if (typed_array_is_detached(ctx, p) || idx < 0 || idx >= len)
+ return JS_ThrowRangeError(ctx, "invalid array index");
+
arr = js_typed_array_constructor_ta(ctx, JS_UNDEFINED, this_val,
p->class_id);
if (JS_IsException(arr)) {