]> git.kaiwu.me - quickjs.git/commitdiff
fixed iterator close in Map/Set constructor
authorFabrice Bellard <fabrice@bellard.org>
Mon, 21 Apr 2025 14:12:56 +0000 (16:12 +0200)
committerFabrice Bellard <fabrice@bellard.org>
Mon, 21 Apr 2025 14:12:56 +0000 (16:12 +0200)
quickjs.c

index ac00898bb03bac281490d6843755fd53a67a1846..85dc0d084230dce3ba2b82c028ee1763b751a176 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -47148,7 +47148,7 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target,
                 ret = JS_Call(ctx, adder, obj, 1, (JSValueConst *)&item);
                 if (JS_IsException(ret)) {
                     JS_FreeValue(ctx, item);
-                    goto fail;
+                    goto fail_close;
                 }
             } else {
                 JSValue key, value;
@@ -47173,7 +47173,7 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target,
                     JS_FreeValue(ctx, item);
                     JS_FreeValue(ctx, key);
                     JS_FreeValue(ctx, value);
-                    goto fail;
+                    goto fail_close;
                 }
                 JS_FreeValue(ctx, key);
                 JS_FreeValue(ctx, value);
@@ -47186,11 +47186,10 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target,
         JS_FreeValue(ctx, adder);
     }
     return obj;
+ fail_close:
+    /* close the iterator object, preserving pending exception */
+    JS_IteratorClose(ctx, iter, TRUE);
  fail:
-    if (JS_IsObject(iter)) {
-        /* close the iterator object, preserving pending exception */
-        JS_IteratorClose(ctx, iter, TRUE);
-    }
     JS_FreeValue(ctx, next_method);
     JS_FreeValue(ctx, iter);
     JS_FreeValue(ctx, adder);