diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index d0f9ce0329..27184a4106 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1010,7 +1010,23 @@ Bytecode::CodeGenerationErrorOr FunctionDeclaration::generate_bytecode(Byt Bytecode::CodeGenerationErrorOr FunctionExpression::generate_bytecode(Bytecode::Generator& generator) const { + bool has_name = !name().is_empty(); + Optional name_identifier; + + if (has_name) { + generator.begin_variable_scope(Bytecode::Generator::BindingMode::Lexical); + + name_identifier = generator.intern_identifier(name()); + generator.emit(*name_identifier, Bytecode::Op::EnvironmentMode::Lexical, true); + } + generator.emit(*this); + + if (has_name) { + generator.emit(*name_identifier, Bytecode::Op::SetVariable::InitializationMode::Initialize, Bytecode::Op::EnvironmentMode::Lexical); + generator.end_variable_scope(); + } + return {}; }