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] - Continue panic fixes #1896

Closed
wants to merge 3 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions boa_engine/src/bytecompiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,9 +1454,7 @@ impl<'b> ByteCompiler<'b> {
.iter()
.rev()
.filter(|info| info.kind == JumpControlInfoKind::Loop);
let address = if node.label().is_none() {
items.next().expect("continue target").start_address
} else {
let address = if let Some(label_name) = node.label() {
let mut num_loops = 0;
let mut emit_for_of_in_exit = 0;
let mut address_info = None;
Expand All @@ -1470,7 +1468,14 @@ impl<'b> ByteCompiler<'b> {
emit_for_of_in_exit += 1;
}
}
let address = address_info.expect("continue target").start_address;
let address = address_info
.ok_or_else(|| {
self.context.construct_syntax_error(format!(
"Cannot use the undeclared label '{}'",
self.context.interner().resolve_expect(label_name)
))
})?
.start_address;
for _ in 0..emit_for_of_in_exit {
self.emit_opcode(Opcode::Pop);
self.emit_opcode(Opcode::Pop);
Expand All @@ -1479,6 +1484,14 @@ impl<'b> ByteCompiler<'b> {
self.emit_opcode(Opcode::LoopEnd);
}
address
} else {
items
.next()
.ok_or_else(|| {
self.context
.construct_syntax_error("continue must be inside loop")
})?
.start_address
};
self.emit_opcode(Opcode::LoopEnd);
self.emit_opcode(Opcode::LoopStart);
Expand Down
26 changes: 26 additions & 0 deletions boa_engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,31 @@ fn test_invalid_break_target() {
assert!(Context::default().eval(src).is_err());
}

#[test]
fn test_invalid_continue_target() {
let mut context = Context::default();
let src = r#"
while (false) {
continue nonexistent;
}
"#;
let string = forward(&mut context, src);
assert_eq!(
string,
"Uncaught \"SyntaxError\": \"Cannot use the undeclared label 'nonexistent'\""
);
}

#[test]
fn test_invalid_continue() {
let mut context = Context::default();
let string = forward(&mut context, r"continue;");
assert_eq!(
string,
"Uncaught \"SyntaxError\": \"continue must be inside loop\""
);
}

#[test]
fn unary_pre() {
let unary_inc = r#"
Expand Down Expand Up @@ -690,6 +715,7 @@ fn unary_delete() {
mod in_operator {
use super::*;
use crate::forward_val;

#[test]
fn propery_in_object() {
let p_in_o = r#"
Expand Down