Browse Source

Correctly handle finally..loop..break (#3073)

The match was too greedy, being executed for 'break' abrupt completions as well.

Closes #3054
pull/3077/head
Dirk de Visser 1 year ago committed by GitHub
parent
commit
4a75b299e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      boa_engine/src/tests/control_flow/mod.rs
  2. 2
      boa_engine/src/vm/opcode/control_flow/finally.rs

18
boa_engine/src/tests/control_flow/mod.rs

@ -194,6 +194,24 @@ fn catch_binding_finally() {
)]);
}
#[test]
fn finally_with_loop_break() {
run_test_actions([TestAction::assert_eq(
indoc! {r#"
try {
30;
}
catch {
} finally {
while(true) {
break;
}
}
"#},
30,
)]);
}
#[test]
fn single_case_switch() {
run_test_actions([TestAction::assert_eq(

2
boa_engine/src/vm/opcode/control_flow/finally.rs

@ -119,7 +119,7 @@ impl Operation for FinallyEnd {
let env_truncation_len = context.vm.environments.len().saturating_sub(envs_to_pop);
context.vm.environments.truncate(env_truncation_len);
}
Some(record) if !record.is_throw_with_target() => {
Some(record) if record.is_throw() && !record.is_throw_with_target() => {
let current_stack = context
.vm
.frame_mut()

Loading…
Cancel
Save