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`.
This commit is contained in:
Andreas Kling 2025-03-20 17:19:50 -05:00 committed by Alexander Kalenik
parent 01031bcccb
commit b971e1ece0
Notes: github-actions[bot] 2025-03-20 23:59:34 +00:00

View file

@ -1616,9 +1616,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> 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<NonnullRefPtr<Identifier const>>()) {
if ((*identifier)->is_local()) {
generator.set_local_initialized((*identifier)->local_variable_index());