]> git.kaiwu.me - quickjs.git/commitdiff
don't take value of dropped iterator items
authorFabrice Bellard <fabrice@bellard.org>
Sat, 21 Nov 2026 13:13:46 +0000 (14:13 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 21 Nov 2026 13:13:46 +0000 (14:13 +0100)
quickjs.c

index 55ffcbc7453e5d821b3504cf4d34f69a83c283bf..bb092d0bc1b73299149837a1f76ce2530ee4afc6 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -47194,9 +47194,18 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValueConst this_val,
             JSValue item;
             while (it->count > 0) {
                 it->count--;
-                item = JS_IteratorNext(ctx, it->obj, it->next, pdone);
+                item = JS_IteratorNext2(ctx, it->obj, it->next, 0, NULL, pdone);
                 if (JS_IsException(item))
                     goto fail_no_close;
+                if (*pdone == 2) {
+                    JSValue done_val;
+                    done_val = JS_GetProperty(ctx, item, JS_ATOM_done);
+                    if (JS_IsException(done_val)) {
+                        JS_FreeValue(ctx, item);
+                        goto fail_no_close;
+                    }
+                    *pdone = JS_ToBoolFree(ctx, done_val);
+                }
                 JS_FreeValue(ctx, item);
                 if (*pdone) {
                     ret = JS_UNDEFINED;