Skip to content

Commit fcdebd7

Browse files
committedDec 4, 2024
Fix break statement in presence of labels
In this snippet... for (;;) label: break ...the break statement jumped back to the start of the loop instead of *out* of the loop. Fixes: #741
1 parent ebc1a65 commit fcdebd7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed
 

‎quickjs.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -24917,9 +24917,7 @@ static __exception int emit_break(JSParseState *s, JSAtom name, int is_cont)
2491724917
emit_goto(s, OP_goto, top->label_cont);
2491824918
return 0;
2491924919
}
24920-
if (!is_cont &&
24921-
top->label_break != -1 &&
24922-
(name == JS_ATOM_NULL || top->label_name == name)) {
24920+
if (!is_cont && top->label_break != -1 && top->label_name == name) {
2492324921
emit_goto(s, OP_goto, top->label_break);
2492424922
return 0;
2492524923
}

‎tests/bug741.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {assert} from "./assert.js"
2+
3+
while (1) label: break
4+
5+
var i = 0
6+
while (i < 3) label: {
7+
if (i > 0)
8+
break
9+
i++
10+
}
11+
assert(i, 1)
12+
13+
for (;;) label: break
14+
15+
for (i = 0; i < 3; i++) label: {
16+
if (i > 0)
17+
break
18+
}
19+
assert(i, 1)

0 commit comments

Comments
 (0)