]> git.kaiwu.me - quickjs.git/commitdiff
fixed TypedArray.prototype.with with detached ArrayBuffer
authorFabrice Bellard <fabrice@bellard.org>
Tue, 22 Apr 2025 17:05:36 +0000 (19:05 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Tue, 22 Apr 2025 17:05:36 +0000 (19:05 +0200)
quickjs.c

index 8d5150d2004e8020f9e2702817a97c4116324fbe..d6d1478d3ac4a41e86808485628fe47c0e1a6602 100644 (file)
--- 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)) {