From 8be966524f137428551b417de4e6b097c14a0dd1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 20 Mar 2025 17:19:50 -0500 Subject: [PATCH] LibJS: Mark locals as outside TDZ immediately after initializing This avoids emitting TDZ checks for multiple bindings declared and referenced within one variable declaration, i.e: var foo = 0, bar = foo; In the above case, we'd emit an unnecessary TDZ check for the second reference to `foo`. --- Libraries/LibJS/Bytecode/ASTCodegen.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Libraries/LibJS/Bytecode/ASTCodegen.cpp index c3d925465bc..b56fbbfebd9 100644 --- a/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1616,9 +1616,7 @@ Bytecode::CodeGenerationErrorOr> VariableDeclaration::ge } else if (m_declaration_kind != DeclarationKind::Var) { (void)TRY(assign_value_to_variable_declarator(generator, declarator, *this, generator.add_constant(js_undefined()))); } - } - for (auto& declarator : m_declarations) { if (auto const* identifier = declarator->target().get_pointer>()) { if ((*identifier)->is_local()) { generator.set_local_initialized((*identifier)->local_variable_index());