mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
LibJS: Implement async functions as generator functions in BC mode
This applies a simple transformation, and adds a simple wrapper that translates the generator interface to the async function interface.
This commit is contained in:
parent
c604e95993
commit
3b0bf05fa5
14 changed files with 192 additions and 43 deletions
|
@ -911,7 +911,7 @@ void ReturnStatement::generate_bytecode(Bytecode::Generator& generator) const
|
|||
if (m_argument)
|
||||
m_argument->generate_bytecode(generator);
|
||||
|
||||
if (generator.is_in_generator_function())
|
||||
if (generator.is_in_generator_or_async_function())
|
||||
generator.emit<Bytecode::Op::Yield>(nullptr);
|
||||
else
|
||||
generator.emit<Bytecode::Op::Return>();
|
||||
|
@ -1269,4 +1269,16 @@ void ThisExpression::generate_bytecode(Bytecode::Generator& generator) const
|
|||
generator.emit<Bytecode::Op::ResolveThisBinding>();
|
||||
}
|
||||
|
||||
void AwaitExpression::generate_bytecode(Bytecode::Generator& generator) const
|
||||
{
|
||||
VERIFY(generator.is_in_async_function());
|
||||
|
||||
// Transform `await expr` to `yield expr`
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue