Skip to content

Commit d6e6e77

Browse files
Fabrice Bellardsaghul
authored andcommitted
ensure that JS_IteratorNext() returns JS_UNDEFINED when done = TRUE
Fixes: #999
1 parent 6071c55 commit d6e6e77

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

quickjs.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15484,9 +15484,13 @@ static JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj,
1548415484
obj = JS_IteratorNext2(ctx, enum_obj, method, argc, argv, &done);
1548515485
if (JS_IsException(obj))
1548615486
goto fail;
15487-
if (done != 2) {
15488-
*pdone = done;
15487+
if (likely(done == 0)) {
15488+
*pdone = false;
1548915489
return obj;
15490+
} else if (done != 2) {
15491+
JS_FreeValue(ctx, obj);
15492+
*pdone = true;
15493+
return JS_UNDEFINED;
1549015494
} else {
1549115495
done_val = JS_GetProperty(ctx, obj, JS_ATOM_done);
1549215496
if (JS_IsException(done_val))
@@ -38616,10 +38620,8 @@ static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val,
3861638620
item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);
3861738621
if (JS_IsException(item))
3861838622
goto fail;
38619-
if (done) {
38620-
JS_FreeValue(ctx, item);
38623+
if (done)
3862138624
break;
38622-
}
3862338625

3862438626
key = JS_UNDEFINED;
3862538627
value = JS_UNDEFINED;
@@ -48506,10 +48508,8 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target,
4850648508
item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);
4850748509
if (JS_IsException(item))
4850848510
goto fail;
48509-
if (done) {
48510-
JS_FreeValue(ctx, item);
48511+
if (done)
4851148512
break;
48512-
}
4851348513
if (is_set) {
4851448514
ret = JS_Call(ctx, adder, obj, 1, vc(&item));
4851548515
if (JS_IsException(ret)) {
@@ -55677,10 +55677,8 @@ static JSValue js_array_from_iterator(JSContext *ctx, uint32_t *plen,
5567755677
val = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done);
5567855678
if (JS_IsException(val))
5567955679
goto fail;
55680-
if (done) {
55681-
JS_FreeValue(ctx, val);
55680+
if (done)
5568255681
break;
55683-
}
5568455682
if (JS_CreateDataPropertyUint32(ctx, arr, k, val, JS_PROP_THROW) < 0)
5568555683
goto fail;
5568655684
k++;

0 commit comments

Comments
 (0)