diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 4f34295b3b..13f78b2088 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -247,44 +247,7 @@ Bytecode::CodeGenerationErrorOr ScopeNode::generate_bytecode(Bytecode::Gen generator.emit(index, Bytecode::Op::EnvironmentMode::Var, false, true); } } else { - // Perform the steps of FunctionDeclarationInstantiation. - generator.begin_variable_scope(Bytecode::Generator::BindingMode::Var, Bytecode::Generator::SurroundingScopeKind::Function); - pushed_scope_count++; - if (has_lexical_declarations()) { - generator.begin_variable_scope(Bytecode::Generator::BindingMode::Lexical, Bytecode::Generator::SurroundingScopeKind::Function); - pushed_scope_count++; - } - - // FIXME: Implement this boi correctly. - (void)for_each_lexically_scoped_declaration([&](Declaration const& declaration) -> ThrowCompletionOr { - auto is_constant_declaration = declaration.is_constant_declaration(); - // NOTE: Nothing in the callback throws an exception. - MUST(declaration.for_each_bound_name([&](auto const& name) { - auto index = generator.intern_identifier(name); - if (is_constant_declaration || !generator.has_binding(index)) { - generator.register_binding(index); - generator.emit(index, Bytecode::Op::EnvironmentMode::Lexical, is_constant_declaration); - } - })); - - if (is(declaration)) { - auto& function_declaration = static_cast(declaration); - if (auto result = function_declaration.generate_bytecode(generator); result.is_error()) { - maybe_error = result.release_error(); - // To make `for_each_lexically_scoped_declaration` happy. - return failing_completion; - } - auto const& name = function_declaration.name(); - auto index = generator.intern_identifier(name); - if (!generator.has_binding(index)) { - generator.register_binding(index); - generator.emit(index, Bytecode::Op::EnvironmentMode::Lexical, false); - } - generator.emit(index, Bytecode::Op::SetVariable::InitializationMode::InitializeOrSet); - } - - return {}; - }); + // FunctionDeclarationInstantiation is handled by the C++ AO. } if (maybe_error.has_value()) diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 0a3a4d9609..ab1f1407c2 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -573,19 +573,17 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia if (!scope_body) return {}; - if (!Bytecode::Interpreter::current()) { - // NOTE: Due to the use of MUST in the callback, an exception should not result from `for_each_lexically_scoped_declaration`. - MUST(scope_body->for_each_lexically_scoped_declaration([&](Declaration const& declaration) { - // NOTE: Due to the use of MUST with `create_immutable_binding` and `create_mutable_binding` below, - // an exception should not result from `for_each_bound_name`. - MUST(declaration.for_each_bound_name([&](auto const& name) { - if (declaration.is_constant_declaration()) - MUST(lex_environment->create_immutable_binding(vm, name, true)); - else - MUST(lex_environment->create_mutable_binding(vm, name, false)); - })); + // NOTE: Due to the use of MUST in the callback, an exception should not result from `for_each_lexically_scoped_declaration`. + MUST(scope_body->for_each_lexically_scoped_declaration([&](Declaration const& declaration) { + // NOTE: Due to the use of MUST with `create_immutable_binding` and `create_mutable_binding` below, + // an exception should not result from `for_each_bound_name`. + MUST(declaration.for_each_bound_name([&](auto const& name) { + if (declaration.is_constant_declaration()) + MUST(lex_environment->create_immutable_binding(vm, name, true)); + else + MUST(lex_environment->create_mutable_binding(vm, name, false)); })); - } + })); auto private_environment = callee_context.private_environment; for (auto& declaration : functions_to_initialize) {