mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 11:04:59 +00:00
LibJS: Allow anonymous functions as default exports
This requires a special case with names as the default function is supposed to have a unique name ("*default*" in our case) but when checked should have name "default".
This commit is contained in:
parent
0fc67ffd62
commit
9f661d20f7
5 changed files with 79 additions and 19 deletions
|
@ -460,7 +460,12 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
|
|||
auto const& function_declaration = static_cast<FunctionDeclaration const&>(declaration);
|
||||
|
||||
// 1. Let fo be InstantiateFunctionObject of d with arguments env and privateEnv.
|
||||
auto* function = ECMAScriptFunctionObject::create(realm(), function_declaration.name(), function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(), function_declaration.might_need_arguments_object(), function_declaration.contains_direct_call_to_eval());
|
||||
// NOTE: Special case if the function is a default export of an anonymous function
|
||||
// it has name "*default*" but internally should have name "default".
|
||||
FlyString function_name = function_declaration.name();
|
||||
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(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(), function_declaration.might_need_arguments_object(), function_declaration.contains_direct_call_to_eval());
|
||||
|
||||
// 2. Perform ! env.InitializeBinding(dn, fo).
|
||||
MUST(environment->initialize_binding(vm, name, function));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue