LibJS+LibWeb: Pass function metadata collected in parsing using a struct

By using separate struct we can avoid updating AST node and
ECMAScriptFunctionObject constructors every time there is a need to
add or remove some additional information colllected during parsing.
This commit is contained in:
Aliaksandr Kalenik
2024-05-22 11:04:50 +01:00
committed by Andreas Kling
parent 99f6528009
commit e934132442
12 changed files with 75 additions and 73 deletions

View File

@@ -499,7 +499,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
if (function_name == ExportStatement::local_name_for_default)
function_name = "default"sv;
auto function = ECMAScriptFunctionObject::create(realm(), function_name, function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), function_declaration.local_variables_names(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(),
function_declaration.uses_this_from_environment(), function_declaration.might_need_arguments_object(), function_declaration.contains_direct_call_to_eval());
function_declaration.parsing_insights());
// 2. Perform ! env.InitializeBinding(dn, fo, normal).
MUST(environment->initialize_binding(vm, name, function, Environment::InitializeBindingHint::Normal));
@@ -758,9 +758,11 @@ ThrowCompletionOr<void> SourceTextModule::execute_module(VM& vm, GCPtr<PromiseCa
// the top-level module code.
// FIXME: Improve this situation, so we can match the spec better.
FunctionParsingInsights parsing_insights;
parsing_insights.uses_this_from_environment = true;
auto module_wrapper_function = ECMAScriptFunctionObject::create(
realm(), "module code with top-level await", StringView {}, this->m_ecmascript_code,
{}, 0, {}, environment(), nullptr, FunctionKind::Async, true, UsesThisFromEnvironment::Yes, false, false);
{}, 0, {}, environment(), nullptr, FunctionKind::Async, true, parsing_insights);
module_wrapper_function->set_is_module_wrapper(true);
// AD-HOC: We push/pop the moduleContext around the call to ensure that the async execution context