diff --git a/boa_engine/src/bytecompiler.rs b/boa_engine/src/bytecompiler.rs index ad709525e5..3dd8cac706 100644 --- a/boa_engine/src/bytecompiler.rs +++ b/boa_engine/src/bytecompiler.rs @@ -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); } diff --git a/boa_engine/src/tests.rs b/boa_engine/src/tests.rs index a8ee0730b3..5500d3d34e 100644 --- a/boa_engine/src/tests.rs +++ b/boa_engine/src/tests.rs @@ -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();