diff --git a/quickjs.c b/quickjs.c index 5c8a4ca44..85ca12b10 100644 --- a/quickjs.c +++ b/quickjs.c @@ -15484,9 +15484,13 @@ static JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj, obj = JS_IteratorNext2(ctx, enum_obj, method, argc, argv, &done); if (JS_IsException(obj)) goto fail; - if (done != 2) { - *pdone = done; + if (likely(done == 0)) { + *pdone = false; return obj; + } else if (done != 2) { + JS_FreeValue(ctx, obj); + *pdone = true; + return JS_UNDEFINED; } else { done_val = JS_GetProperty(ctx, obj, JS_ATOM_done); if (JS_IsException(done_val)) @@ -38616,10 +38620,8 @@ static JSValue js_object_fromEntries(JSContext *ctx, JSValueConst this_val, item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done); if (JS_IsException(item)) goto fail; - if (done) { - JS_FreeValue(ctx, item); + if (done) break; - } key = JS_UNDEFINED; value = JS_UNDEFINED; @@ -48506,10 +48508,8 @@ static JSValue js_map_constructor(JSContext *ctx, JSValueConst new_target, item = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done); if (JS_IsException(item)) goto fail; - if (done) { - JS_FreeValue(ctx, item); + if (done) break; - } if (is_set) { ret = JS_Call(ctx, adder, obj, 1, vc(&item)); if (JS_IsException(ret)) { @@ -55677,10 +55677,8 @@ static JSValue js_array_from_iterator(JSContext *ctx, uint32_t *plen, val = JS_IteratorNext(ctx, iter, next_method, 0, NULL, &done); if (JS_IsException(val)) goto fail; - if (done) { - JS_FreeValue(ctx, val); + if (done) break; - } if (JS_CreateDataPropertyUint32(ctx, arr, k, val, JS_PROP_THROW) < 0) goto fail; k++; diff --git a/tests/bug999.js b/tests/bug999.js new file mode 100644 index 000000000..28a3a6f04 --- /dev/null +++ b/tests/bug999.js @@ -0,0 +1,3 @@ +function* f(r){ return r } // must return r +[...f({})] +