]> git.kaiwu.me - quickjs.git/commitdiff
Fix stack underflow with generator in iterable (saghul) (#488)
authorFabrice Bellard <fabrice@bellard.org>
Sat, 21 Mar 2026 12:43:57 +0000 (13:43 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 21 Mar 2026 12:43:57 +0000 (13:43 +0100)
quickjs.c

index 4422544ff2fd929813489e1c501dd62f393023cd..835b38277de492fa9bca8007cb9f895daaeac14d 100644 (file)
--- 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