@@ -15484,9 +15484,13 @@ static JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj,
15484
15484
obj = JS_IteratorNext2(ctx, enum_obj, method, argc, argv, &done);
15485
15485
if (JS_IsException(obj))
15486
15486
goto fail;
15487
- if (done != 2 ) {
15488
- *pdone = done ;
15487
+ if (likely( done == 0) ) {
15488
+ *pdone = false ;
15489
15489
return obj;
15490
+ } else if (done != 2) {
15491
+ JS_FreeValue(ctx, obj);
15492
+ *pdone = true;
15493
+ return JS_UNDEFINED;
15490
15494
} else {
15491
15495
done_val = JS_GetProperty(ctx, obj, JS_ATOM_done);
15492
15496
if (JS_IsException(done_val))
@@ -38616,10 +38620,8 @@ static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val,
38616
38620
item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);
38617
38621
if (JS_IsException(item))
38618
38622
goto fail;
38619
- if (done) {
38620
- JS_FreeValue(ctx, item);
38623
+ if (done)
38621
38624
break;
38622
- }
38623
38625
38624
38626
key = JS_UNDEFINED;
38625
38627
value = JS_UNDEFINED;
@@ -48506,10 +48508,8 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target,
48506
48508
item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);
48507
48509
if (JS_IsException(item))
48508
48510
goto fail;
48509
- if (done) {
48510
- JS_FreeValue(ctx, item);
48511
+ if (done)
48511
48512
break;
48512
- }
48513
48513
if (is_set) {
48514
48514
ret = JS_Call(ctx, adder, obj, 1, vc(&item));
48515
48515
if (JS_IsException(ret)) {
@@ -55677,10 +55677,8 @@ static JSValue js_array_from_iterator(JSContext *ctx, uint32_t *plen,
55677
55677
val = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);
55678
55678
if (JS_IsException(val))
55679
55679
goto fail;
55680
- if (done) {
55681
- JS_FreeValue(ctx, val);
55680
+ if (done)
55682
55681
break;
55683
- }
55684
55682
if (JS_CreateDataPropertyUint32(ctx, arr, k, val, JS_PROP_THROW) < 0)
55685
55683
goto fail;
55686
55684
k++;
0 commit comments