return JS_EXCEPTION;
}
+/* Note: always return JS_UNDEFINED when *pdone = TRUE. */
static JSValue JS_IteratorNext(JSContext *ctx, JSValueConst enum_obj,
JSValueConst method,
int argc, JSValueConst *argv, BOOL *pdone)
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))
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;
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, (JSValueConst *)&item);
if (JS_IsException(ret)) {
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++;