Skip to content

Commit

Permalink
compiler: close upvalues on loop control statements
Browse files Browse the repository at this point in the history
When removing locals from all scopes, upvalues need to be considered, like
in uc_compiler_leave_scope. Otherwise, the following testcase returns the wrong
value:

let dest;
for (let i in [ 1 ]) {
    let foo = i;
    dest = () => {
        warn(`value: ${foo}\n`);
    };
    continue;
}
dest();
// returns value: null instead of value: 1

Signed-off-by: Felix Fietkau <[email protected]>
  • Loading branch information
nbd168 committed Feb 8, 2024
1 parent dce19b7 commit a30ec8d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2969,7 +2969,8 @@ uc_compiler_compile_control(uc_compiler_t *compiler)

/* pop locals in all scopes covered by the target patchlist */
for (i = locals->count; i > 0 && (size_t)locals->entries[i - 1].depth > p->depth; i--)
uc_compiler_emit_insn(compiler, 0, I_POP);
uc_compiler_emit_insn(compiler, 0,
locals->entries[i - 1].captured ? I_CUPV : I_POP);

uc_vector_grow(p);

Expand Down

0 comments on commit a30ec8d

Please sign in to comment.