1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:47:34 +00:00

LibJS: Fix that in Bytecode mode functions where not created anymore

This is not a proper fix as we should follow the spec here but it gets
us back to a slightly more working state.
This commit is contained in:
davidot 2021-09-30 15:02:36 +02:00 committed by Linus Groh
parent 0f5fe3b70e
commit 715f9666f2

View file

@ -26,6 +26,24 @@ void ASTNode::generate_bytecode(Bytecode::Generator&) const
void ScopeNode::generate_bytecode(Bytecode::Generator& generator) const
{
// FIXME: This is an ad-hoc fix but should be done as the spec says in
// {Global, Block, Function, Eval}DeclarationInstantiation.
for (auto& function : m_functions_hoistable_with_annexB_extension) {
generator.emit<Bytecode::Op::NewFunction>(function);
generator.emit<Bytecode::Op::SetVariable>(generator.intern_string(function.name()));
}
HashTable<FlyString> functions_initialized;
for_each_var_function_declaration_in_reverse_order([&](FunctionDeclaration const& function) {
if (functions_initialized.set(function.name()) != AK::HashSetResult::InsertedNewEntry)
return IterationDecision::Continue;
generator.emit<Bytecode::Op::NewFunction>(function);
generator.emit<Bytecode::Op::SetVariable>(generator.intern_string(function.name()));
return IterationDecision::Continue;
});
// FIXME: Register lexical and variable scope declarations
for (auto& child : children()) {
child.generate_bytecode(generator);