1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:15:06 +00:00

LibJS/Bytecode: Set "home object" of functions within object expression

We manage this by having a stack of home objects in Generator, and then
adding an optional home object parameter to the NewFunction instruction.
This commit is contained in:
Andreas Kling 2023-06-16 10:25:05 +02:00
parent a33af174b2
commit c9bd324369
5 changed files with 45 additions and 4 deletions

View file

@ -448,4 +448,22 @@ void Generator::generate_continue(DeprecatedFlyString const& continue_label)
VERIFY_NOT_REACHED();
}
void Generator::push_home_object(Register register_)
{
m_home_objects.append(register_);
}
void Generator::pop_home_object()
{
m_home_objects.take_last();
}
void Generator::emit_new_function(FunctionNode const& function_node)
{
if (m_home_objects.is_empty())
emit<Op::NewFunction>(function_node);
else
emit<Op::NewFunction>(function_node, m_home_objects.last());
}
}