]> git.kaiwu.me - quickjs.git/commitdiff
fixed ArrayBuffer.prototype.resize
authorFabrice Bellard <fabrice@bellard.org>
Mon, 28 Sep 2026 10:07:30 +0000 (12:07 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Mon, 28 Sep 2026 10:07:30 +0000 (12:07 +0200)
quickjs.c

index 91429815efc20d3cb59a7ba8b021cc88c85b11d9..c27450731821aee55a3933ec8ee2a46aabf7bad1 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -57384,12 +57384,12 @@ static JSValue js_array_buffer_resize(JSContext *ctx, JSValueConst this_val,
 {
     JSArrayBuffer *abuf;
     uint8_t *data;
-    int64_t len;
+    uint64_t len;
 
     abuf = JS_GetOpaque2(ctx, this_val, class_id);
     if (!abuf)
         return JS_EXCEPTION;
-    if (JS_ToInt64(ctx, &len, argv[0]))
+    if (JS_ToIndex(ctx, &len, argv[0]))
         return JS_EXCEPTION;
     if (abuf->detached)
         return JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
@@ -57398,7 +57398,7 @@ static JSValue js_array_buffer_resize(JSContext *ctx, JSValueConst this_val,
     // TODO(bnoordhuis) support externally managed RABs
     if (abuf->free_func != js_array_buffer_free)
         return JS_ThrowTypeError(ctx, "external array buffer is not resizable");
-    if (len < 0 || len > abuf->max_byte_length) {
+    if (len > abuf->max_byte_length) {
     bad_length:
         return JS_ThrowRangeError(ctx, "invalid array buffer length");
     }