Skip to content

Commit

Permalink
Removing the panic in favour of an error result (#1874)
Browse files Browse the repository at this point in the history
This Pull Request is related to #1873.

It changes the following:

- Removes the panic in case a label is not found. I think this should be an early syntax error, but at least we shouldn't panic while we fix the issue with the labels.

I think we should solve the issue with labeled statements for 0.15.
  • Loading branch information
Razican committed Feb 27, 2022
1 parent ada4ca8 commit 1887b6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 6 additions & 5 deletions boa_engine/src/bytecompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,11 +1515,12 @@ impl<'b> ByteCompiler<'b> {
break;
}
}
assert!(
found,
"Undefined label '{}'",
self.interner().resolve_expect(label_name)
);
if !found {
return self.context.throw_syntax_error(format!(
"Cannot use the undeclared label '{}'",
self.interner().resolve_expect(label_name)
));
}
} else {
self.jump_info
.last_mut()
Expand Down
3 changes: 1 addition & 2 deletions boa_engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,14 @@ fn for_loop_iteration_variable_does_not_leak() {
}

#[test]
#[should_panic]
fn test_invalid_break_target() {
let src = r#"
while (false) {
break nonexistent;
}
"#;

let _ = &exec(src);
assert!(Context::default().eval(src).is_err());
}

#[test]
Expand Down

0 comments on commit 1887b6a

Please sign in to comment.