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

Make missing break labels not panic #1859

Closed
wants to merge 1 commit into from
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
11 changes: 6 additions & 5 deletions boa_engine/src/bytecompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,11 +1480,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!(
"Undefined label '{}'",
self.interner().resolve_expect(label_name)
));
}
} else {
self.jump_info
.last_mut()
Expand Down
5 changes: 2 additions & 3 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) {
while (true) {
break nonexistent;
}
"#;

let _ = &exec(src);
assert!(matches!(Context::default().eval(src.as_bytes()), Err(_)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be changed to assert!(Context::default().eval(&src).is_err())?

It seems simpler :)

}

#[test]
Expand Down