2021-06-11 01:38:30 +04:30
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-11 16:23:42 -04:00
|
|
|
#include <LibJS/Bytecode/Interpreter.h>
|
2021-09-24 22:40:38 +02:00
|
|
|
#include <LibJS/Runtime/ECMAScriptFunctionObject.h>
|
2021-06-11 01:38:30 +04:30
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
class GeneratorObject final : public Object {
|
|
|
|
JS_OBJECT(GeneratorObject, Object);
|
|
|
|
|
|
|
|
public:
|
2021-11-11 00:46:07 +03:30
|
|
|
static ThrowCompletionOr<GeneratorObject*> create(GlobalObject&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow);
|
|
|
|
GeneratorObject(GlobalObject&, Object& prototype, ExecutionContext);
|
2021-06-11 01:38:30 +04:30
|
|
|
virtual void initialize(GlobalObject&) override;
|
|
|
|
virtual ~GeneratorObject() override;
|
|
|
|
void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2021-11-11 00:46:07 +03:30
|
|
|
ThrowCompletionOr<Value> next_impl(VM&, GlobalObject&, Optional<Value> next_argument, Optional<Value> value_to_throw);
|
2021-06-15 00:04:08 -07:00
|
|
|
void set_done() { m_done = true; }
|
2021-06-11 01:38:30 +04:30
|
|
|
|
2021-06-15 00:04:08 -07:00
|
|
|
private:
|
2021-11-11 00:46:07 +03:30
|
|
|
ExecutionContext m_execution_context;
|
2021-09-24 22:40:38 +02:00
|
|
|
ECMAScriptFunctionObject* m_generating_function { nullptr };
|
2021-06-11 01:38:30 +04:30
|
|
|
Value m_previous_value;
|
2022-02-12 19:48:45 +03:30
|
|
|
Optional<Bytecode::RegisterWindow> m_frame;
|
2021-06-11 01:38:30 +04:30
|
|
|
bool m_done { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|