Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Prevent breaks without loop or switch from causing panics #1860

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion boa_engine/src/bytecompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,11 @@ impl<'b> ByteCompiler<'b> {
} else {
self.jump_info
.last_mut()
.expect("no jump information found")
.ok_or_else(|| {
self.context.construct_syntax_error(
"unlabeled break must be inside loop or switch",
)
})?
.breaks
.push(label);
}
Expand Down
14 changes: 14 additions & 0 deletions boa_engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,20 @@ fn test_invalid_break_target() {
assert!(Context::default().eval(src).is_err());
}

#[test]
fn test_invalid_break() {
let mut context = Context::default();
let src = r#"
break;
"#;

let string = forward(&mut context, src);
assert_eq!(
string,
"Uncaught \"SyntaxError\": \"unlabeled break must be inside loop or switch\""
);
}

#[test]
fn test_invalid_continue_target() {
let mut context = Context::default();
Expand Down