mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
LibJS: Implement generator functions (only in bytecode mode)
This commit is contained in:
parent
c53a86a3fe
commit
3234697eca
21 changed files with 407 additions and 34 deletions
|
@ -218,8 +218,7 @@ void Call::execute(Bytecode::Interpreter& interpreter) const
|
|||
void NewFunction::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
auto& global_object = interpreter.global_object();
|
||||
interpreter.accumulator() = ScriptFunction::create(global_object, m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.current_scope(), m_function_node.is_strict_mode());
|
||||
interpreter.accumulator() = ScriptFunction::create(interpreter.global_object(), m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.current_scope(), m_function_node.is_generator(), m_function_node.is_strict_mode());
|
||||
}
|
||||
|
||||
void Return::execute(Bytecode::Interpreter& interpreter) const
|
||||
|
@ -280,6 +279,18 @@ void PushLexicalEnvironment::execute(Bytecode::Interpreter& interpreter) const
|
|||
interpreter.vm().call_frame().scope = block_lexical_environment;
|
||||
}
|
||||
|
||||
void Yield::execute(Bytecode::Interpreter& interpreter) const
|
||||
{
|
||||
auto yielded_value = interpreter.accumulator().value_or(js_undefined());
|
||||
auto object = JS::Object::create_empty(interpreter.global_object());
|
||||
object->put("result", yielded_value);
|
||||
if (m_continuation_label.has_value())
|
||||
object->put("continuation", Value(static_cast<double>(reinterpret_cast<u64>(&m_continuation_label->block()))));
|
||||
else
|
||||
object->put("continuation", Value(0));
|
||||
interpreter.do_return(object);
|
||||
}
|
||||
|
||||
String Load::to_string(Bytecode::Executable const&) const
|
||||
{
|
||||
return String::formatted("Load {}", m_src);
|
||||
|
@ -445,4 +456,11 @@ String PushLexicalEnvironment::to_string(const Bytecode::Executable& executable)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
String Yield::to_string(Bytecode::Executable const&) const
|
||||
{
|
||||
if (m_continuation_label.has_value())
|
||||
return String::formatted("Yield continuation:@{}", m_continuation_label->block().name());
|
||||
return String::formatted("Yield return");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue