Skip to content

Commit

Permalink
Add assert to restrict initializers on for-of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Apr 19, 2023
1 parent a48869b commit b79037d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions boa_engine/src/bytecompiler/statement/loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,22 @@ impl ByteCompiler<'_, '_> {
ByteCompiler::access_set_top_of_stack_expr_fn,
);
}
// Can ignore initializers since those aren't allowed on for-of loops.
IterableLoopInitializer::Var(declaration) => match declaration.binding() {
Binding::Identifier(ident) => {
self.create_mutable_binding(*ident, true, false);
self.emit_binding(BindingOpcode::InitVar, *ident);
}
Binding::Pattern(pattern) => {
for ident in bound_names(pattern) {
self.create_mutable_binding(ident, true, false);
IterableLoopInitializer::Var(declaration) => {
// ignore initializers since those aren't allowed on for-of loops.
assert!(declaration.init().is_none());
match declaration.binding() {
Binding::Identifier(ident) => {
self.create_mutable_binding(*ident, true, false);
self.emit_binding(BindingOpcode::InitVar, *ident);
}
Binding::Pattern(pattern) => {
for ident in bound_names(pattern) {
self.create_mutable_binding(ident, true, false);
}
self.compile_declaration_pattern(pattern, BindingOpcode::InitVar);
}
self.compile_declaration_pattern(pattern, BindingOpcode::InitVar);
}
},
}
IterableLoopInitializer::Let(declaration) => match declaration {
Binding::Identifier(ident) => {
self.create_mutable_binding(*ident, false, false);
Expand Down

0 comments on commit b79037d

Please sign in to comment.