1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

LibJS: Make the BC generator.next(value) work

This used to put the value in the previous frame's accumulator register,
which is only correct for the first invocation of the generator.
This commit is contained in:
Ali Mohammad Pur 2022-04-15 21:24:42 +04:30 committed by Ali Mohammad Pur
parent d5791c85b4
commit e1cd36559d

View file

@ -100,12 +100,17 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global
bytecode_interpreter->accumulator() = js_undefined();
return throw_completion(value_to_throw.release_value());
}
bytecode_interpreter->accumulator() = next_argument.value_or(js_undefined());
Bytecode::RegisterWindow* frame = nullptr;
if (m_frame.has_value())
frame = &m_frame.value();
auto next_value = next_argument.value_or(js_undefined());
if (frame)
frame->registers[0] = next_value;
else
bytecode_interpreter->accumulator() = next_value;
auto next_result = bytecode_interpreter->run_and_return_frame(*m_generating_function->bytecode_executable(), next_block, frame);
vm.pop_execution_context();