From b79037dda1e90c2054edb4601c36fba75e683d68 Mon Sep 17 00:00:00 2001 From: jedel1043 Date: Tue, 18 Apr 2023 19:52:07 -0600 Subject: [PATCH] Add assert to restrict initializers on for-of loops --- boa_engine/src/bytecompiler/statement/loop.rs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/boa_engine/src/bytecompiler/statement/loop.rs b/boa_engine/src/bytecompiler/statement/loop.rs index fdc89d804eb..785edceca70 100644 --- a/boa_engine/src/bytecompiler/statement/loop.rs +++ b/boa_engine/src/bytecompiler/statement/loop.rs @@ -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);