Skip to content

Commit 9145ce7

Browse files
committed
[GR-34097] Backport: Reset the resumption state after the resumption of SwitchNode.
PullRequest: js/2171
2 parents 4e8a885 + bc803bf commit 9145ce7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/interop/AsyncInteropTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,28 @@ public void asyncCaseSwitch() {
607607
}
608608
}
609609

610+
@Test
611+
public void testAwaitInSwitchInLoop() {
612+
TestOutput out = new TestOutput();
613+
try (Context context = JSTest.newContextBuilder().out(out).build()) {
614+
context.eval("js", "" //
615+
+ "(async function () {" //
616+
+ " for (o of ['a', 'b']) {" //
617+
+ " switch (o) {" //
618+
+ " case 'a':" //
619+
+ " await 42;" //
620+
+ " console.log('seen a');" //
621+
+ " break;" //
622+
+ " case 'b':" //
623+
+ " console.log('seen b');" //
624+
+ " break;" //
625+
+ " }" //
626+
+ " }" //
627+
+ "})();");
628+
assertEquals("seen a\nseen b\n", out.toString());
629+
}
630+
}
631+
610632
private static Function<String, CompletionStage<String>> asChainable(Value jsFunction) {
611633
assert jsFunction.canExecute();
612634
return v -> {

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/control/SwitchNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public Object resume(VirtualFrame frame) {
207207
int statementIndex;
208208
Object resumptionResult;
209209
if (maybeState instanceof SwitchResumptionRecord) {
210+
resetState(frame);
210211
SwitchResumptionRecord state = (SwitchResumptionRecord) maybeState;
211212
caseIndex = state.caseIndex;
212213
statementIndex = state.statementIndex;

0 commit comments

Comments
 (0)