From eee4b6eca72bad35a60f3e5b6071a91341b3c272 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Jun 2023 15:16:30 +0200 Subject: [PATCH] LibJS/Bytecode: Let `var` without initializer codegen to nothing Otherwise we incorrectly overwrite the binding with `undefined` at the point where the `var` statement is. Fixes 9 test262 tests. :^) --- Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index a1b30c1401..ac999b69f7 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1267,11 +1267,13 @@ static Bytecode::CodeGenerationErrorOr assign_accumulator_to_variable_decl Bytecode::CodeGenerationErrorOr VariableDeclaration::generate_bytecode(Bytecode::Generator& generator) const { for (auto& declarator : m_declarations) { - if (declarator->init()) + if (declarator->init()) { TRY(declarator->init()->generate_bytecode(generator)); - else + TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); + } else if (m_declaration_kind != DeclarationKind::Var) { generator.emit(js_undefined()); - TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); + TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this)); + } } return {};