1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

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. :^)
This commit is contained in:
Andreas Kling 2023-06-17 15:16:30 +02:00
parent 743943a042
commit eee4b6eca7
Notes: sideshowbarker 2024-07-17 16:42:19 +09:00

View file

@ -1267,11 +1267,13 @@ static Bytecode::CodeGenerationErrorOr<void> assign_accumulator_to_variable_decl
Bytecode::CodeGenerationErrorOr<void> 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<Bytecode::Op::LoadImmediate>(js_undefined());
TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this));
TRY(assign_accumulator_to_variable_declarator(generator, declarator, *this));
}
}
return {};