Browse Source

Removing the panic in favour of an error result (#1874)

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.
pull/1876/head
Iban Eguia 3 years ago
parent
commit
1887b6aebb
  1. 9
      boa_engine/src/bytecompiler.rs
  2. 3
      boa_engine/src/tests.rs

9
boa_engine/src/bytecompiler.rs

@ -1515,11 +1515,12 @@ impl<'b> ByteCompiler<'b> {
break; break;
} }
} }
assert!( if !found {
found, return self.context.throw_syntax_error(format!(
"Undefined label '{}'", "Cannot use the undeclared label '{}'",
self.interner().resolve_expect(label_name) self.interner().resolve_expect(label_name)
); ));
}
} else { } else {
self.jump_info self.jump_info
.last_mut() .last_mut()

3
boa_engine/src/tests.rs

@ -431,7 +431,6 @@ fn for_loop_iteration_variable_does_not_leak() {
} }
#[test] #[test]
#[should_panic]
fn test_invalid_break_target() { fn test_invalid_break_target() {
let src = r#" let src = r#"
while (false) { while (false) {
@ -439,7 +438,7 @@ fn test_invalid_break_target() {
} }
"#; "#;
let _ = &exec(src); assert!(Context::default().eval(src).is_err());
} }
#[test] #[test]

Loading…
Cancel
Save