From 69090b969fa9d01deeb05011a2bf8537ddf61266 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Sat, 21 Mar 2026 13:43:57 +0100 Subject: [PATCH] Fix stack underflow with generator in iterable (saghul) (#488) --- quickjs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/quickjs.c b/quickjs.c index 4422544..835b382 100644 --- a/quickjs.c +++ b/quickjs.c @@ -28196,8 +28196,7 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name, JS_FreeAtom(ctx, var_name); if (token_is_pseudo_keyword(s, JS_ATOM_of)) { - break_entry.has_iterator = is_for_of = TRUE; - break_entry.drop_count += 2; + is_for_of = TRUE; if (has_initializer) goto initializer_error; } else if (s->token.val == TOK_IN) { @@ -28226,6 +28225,11 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name, the TDZ values are in the closures */ close_scopes(s, s->cur_func->scope_level, block_scope_level); if (is_for_of) { + /* set has_iterator after the iterable expression is parsed so + that a yield in the expression does not try to close a + not-yet-created iterator */ + break_entry.has_iterator = TRUE; + break_entry.drop_count += 2; if (is_async) emit_op(s, OP_for_await_of_start); else