From: Fabrice Bellard Date: Tue, 24 Nov 2026 13:04:19 +0000 (+0100) Subject: added js_poll_interrupts() in array functions X-Git-Url: https://git.kaiwu.me/http/%22../%7B@url%7D?a=commitdiff_plain;h=fa8665bdd4d9192f04b30a46eaa64ebd6b61e4b5;p=quickjs.git added js_poll_interrupts() in array functions --- diff --git a/quickjs.c b/quickjs.c index c783699..68eb55a 100644 --- a/quickjs.c +++ b/quickjs.c @@ -44097,6 +44097,8 @@ static JSValue js_array_every(JSContext *ctx, JSValueConst this_val, n = 0; for(k = 0; k < len; k++) { + if (js_poll_interrupts(ctx)) + goto exception; if (special & special_TA) { val = JS_GetPropertyInt64(ctx, obj, k); if (JS_IsException(val)) @@ -44220,6 +44222,8 @@ static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val, acc = JS_DupValue(ctx, argv[1]); } else { for(;;) { + if (js_poll_interrupts(ctx)) + goto exception; if (k >= len) { JS_ThrowTypeError(ctx, "empty array"); goto exception; @@ -44241,6 +44245,8 @@ static JSValue js_array_reduce(JSContext *ctx, JSValueConst this_val, } } for (; k < len; k++) { + if (js_poll_interrupts(ctx)) + goto exception; k1 = (special & special_reduceRight) ? len - k - 1 : k; if (special & special_TA) { val = JS_GetPropertyInt64(ctx, obj, k1); @@ -44346,6 +44352,8 @@ static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val, } } for (; n < len; n++) { + if (js_poll_interrupts(ctx)) + goto exception; val = JS_GetPropertyInt64(ctx, obj, n); if (JS_IsException(val)) goto exception; @@ -44395,6 +44403,8 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValueConst this_val, } } for (; n < len; n++) { + if (js_poll_interrupts(ctx)) + goto exception; int present = JS_TryGetPropertyInt64(ctx, obj, n, &val); if (present < 0) goto exception; @@ -44437,6 +44447,8 @@ static JSValue js_array_lastIndexOf(JSContext *ctx, JSValueConst this_val, } /* XXX: should special case fast arrays */ for (; n >= 0; n--) { + if (js_poll_interrupts(ctx)) + goto exception; present = JS_TryGetPropertyInt64(ctx, obj, n, &val); if (present < 0) goto exception; @@ -44499,6 +44511,8 @@ static JSValue js_array_find(JSContext *ctx, JSValueConst this_val, // TODO(bnoordhuis) add fast path for fast arrays for(; k != end; k += dir) { + if (js_poll_interrupts(ctx)) + goto exception; index_val = JS_NewInt64(ctx, k); if (JS_IsException(index_val)) goto exception;