diff --git a/boa_engine/src/bytecompiler.rs b/boa_engine/src/bytecompiler.rs index e50a4173b9..50450fd60c 100644 --- a/boa_engine/src/bytecompiler.rs +++ b/boa_engine/src/bytecompiler.rs @@ -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() diff --git a/boa_engine/src/tests.rs b/boa_engine/src/tests.rs index 1d8176012a..b93da4cc1c 100644 --- a/boa_engine/src/tests.rs +++ b/boa_engine/src/tests.rs @@ -431,7 +431,6 @@ fn for_loop_iteration_variable_does_not_leak() { } #[test] -#[should_panic] fn test_invalid_break_target() { let src = r#" while (false) { @@ -439,7 +438,7 @@ fn test_invalid_break_target() { } "#; - let _ = &exec(src); + assert!(Context::default().eval(src).is_err()); } #[test]