1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:38:10 +00:00

LibJS: Implement generator functions (only in bytecode mode)

This commit is contained in:
Ali Mohammad Pur 2021-06-11 01:38:30 +04:30 committed by Andreas Kling
parent c53a86a3fe
commit 3234697eca
21 changed files with 407 additions and 34 deletions

View file

@ -668,7 +668,23 @@ void ReturnStatement::generate_bytecode(Bytecode::Generator& generator) const
{
if (m_argument)
m_argument->generate_bytecode(generator);
generator.emit<Bytecode::Op::Return>();
if (generator.is_in_generator_function())
generator.emit<Bytecode::Op::Yield>(nullptr);
else
generator.emit<Bytecode::Op::Return>();
}
void YieldExpression::generate_bytecode(Bytecode::Generator& generator) const
{
VERIFY(generator.is_in_generator_function());
if (m_argument)
m_argument->generate_bytecode(generator);
auto& continuation_block = generator.make_block();
generator.emit<Bytecode::Op::Yield>(Bytecode::Label { continuation_block });
generator.switch_to_basic_block(continuation_block);
}
void IfStatement::generate_bytecode(Bytecode::Generator& generator) const