mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 06:09:08 +00:00
LibJS: Implement generator functions (only in bytecode mode)
This commit is contained in:
parent
c53a86a3fe
commit
3234697eca
Notes:
sideshowbarker
2024-07-18 12:27:59 +09:00
Author: https://github.com/alimpfard
Commit: 3234697eca
Pull-request: https://github.com/SerenityOS/serenity/pull/7977
Reviewed-by: https://github.com/awesomekling
21 changed files with 407 additions and 34 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue