From 6e015832820b5bb8b72c8301b5a36dd897759b62 Mon Sep 17 00:00:00 2001 From: Josef Guenther Date: Wed, 30 Sep 2026 22:58:37 -0600 Subject: [PATCH] Add interrupt checks to fast array search loops --- quickjs.c | 6 ++++++ tests/bug1672/Array.prototype.includes-fast.js | 8 ++++++++ tests/bug1672/Array.prototype.indexOf-fast.js | 8 ++++++++ tests/bug1672/Array.prototype.lastIndexOf-fast.js | 8 ++++++++ 4 files changed, 30 insertions(+) create mode 100644 tests/bug1672/Array.prototype.includes-fast.js create mode 100644 tests/bug1672/Array.prototype.indexOf-fast.js create mode 100644 tests/bug1672/Array.prototype.lastIndexOf-fast.js diff --git a/quickjs.c b/quickjs.c index ed65ce420..ae22d0385 100644 --- a/quickjs.c +++ b/quickjs.c @@ -43839,6 +43839,8 @@ static JSValue js_array_includes(JSContext *ctx, JSValueConst this_val, } if (js_get_fast_array(ctx, obj, &arrp, &count)) { for (; n < count; n++) { + if (js_poll_interrupts(ctx)) + goto exception; if (js_strict_eq2(ctx, argv[0], arrp[n], JS_EQ_SAME_VALUE_ZERO)) { goto done; @@ -43888,6 +43890,8 @@ static JSValue js_array_indexOf(JSContext *ctx, JSValueConst this_val, } if (js_get_fast_array(ctx, obj, &arrp, &count)) { for (; n < count; n++) { + if (js_poll_interrupts(ctx)) + goto exception; if (js_strict_eq2(ctx, argv[0], arrp[n], JS_EQ_STRICT)) { goto done; } @@ -43939,6 +43943,8 @@ static JSValue js_array_lastIndexOf(JSContext *ctx, JSValueConst this_val, } if (js_get_fast_array(ctx, obj, &arrp, &count) && count == len) { for (; n >= 0; n--) { + if (js_poll_interrupts(ctx)) + goto exception; if (js_strict_eq2(ctx, argv[0], arrp[n], JS_EQ_STRICT)) { goto done; diff --git a/tests/bug1672/Array.prototype.includes-fast.js b/tests/bug1672/Array.prototype.includes-fast.js new file mode 100644 index 000000000..e85bc6e5e --- /dev/null +++ b/tests/bug1672/Array.prototype.includes-fast.js @@ -0,0 +1,8 @@ +/*--- +flags: [qjs:set-interrupt-handler] +negative: + phase: runtime + type: InternalError +---*/ +const a = new Array(1e5).fill(0) +for (;;) a.includes(42) diff --git a/tests/bug1672/Array.prototype.indexOf-fast.js b/tests/bug1672/Array.prototype.indexOf-fast.js new file mode 100644 index 000000000..ab1f55e1d --- /dev/null +++ b/tests/bug1672/Array.prototype.indexOf-fast.js @@ -0,0 +1,8 @@ +/*--- +flags: [qjs:set-interrupt-handler] +negative: + phase: runtime + type: InternalError +---*/ +const a = new Array(1e5).fill(0) +for (;;) a.indexOf(42) diff --git a/tests/bug1672/Array.prototype.lastIndexOf-fast.js b/tests/bug1672/Array.prototype.lastIndexOf-fast.js new file mode 100644 index 000000000..0fdb5a8b8 --- /dev/null +++ b/tests/bug1672/Array.prototype.lastIndexOf-fast.js @@ -0,0 +1,8 @@ +/*--- +flags: [qjs:set-interrupt-handler] +negative: + phase: runtime + type: InternalError +---*/ +const a = new Array(1e5).fill(0) +for (;;) a.lastIndexOf(42)