diff --git a/Userland/Libraries/LibJS/Print.cpp b/Userland/Libraries/LibJS/Print.cpp index 2ae606baf7..11d95eacb1 100644 --- a/Userland/Libraries/LibJS/Print.cpp +++ b/Userland/Libraries/LibJS/Print.cpp @@ -421,15 +421,15 @@ ErrorOr print_shadow_realm(JS::PrintContext& print_context, JS::ShadowReal return {}; } -ErrorOr print_generator(JS::PrintContext& print_context, JS::GeneratorObject const&, HashTable&) +ErrorOr print_generator(JS::PrintContext& print_context, JS::GeneratorObject const& generator, HashTable&) { - TRY(print_type(print_context, "Generator"sv)); + TRY(print_type(print_context, generator.class_name())); return {}; } -ErrorOr print_async_generator(JS::PrintContext& print_context, JS::AsyncGenerator const&, HashTable&) +ErrorOr print_async_generator(JS::PrintContext& print_context, JS::AsyncGenerator const& generator, HashTable&) { - TRY(print_type(print_context, "AsyncGenerator"sv)); + TRY(print_type(print_context, generator.class_name())); return {}; } diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp index f540032326..39ab4e66fc 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.cpp @@ -35,9 +35,10 @@ ThrowCompletionOr> GeneratorObject::create(Realm& return object; } -GeneratorObject::GeneratorObject(Realm&, Object& prototype, ExecutionContext context) +GeneratorObject::GeneratorObject(Realm&, Object& prototype, ExecutionContext context, Optional generator_brand) : Object(ConstructWithPrototypeTag::Tag, prototype) , m_execution_context(move(context)) + , m_generator_brand(move(generator_brand)) { } diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h index 2989d41dd6..1217870e92 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObject.h +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObject.h @@ -12,7 +12,7 @@ namespace JS { -class GeneratorObject final : public Object { +class GeneratorObject : public Object { JS_OBJECT(GeneratorObject, Object); public: @@ -23,19 +23,22 @@ public: ThrowCompletionOr resume(VM&, Value value, Optional const& generator_brand); ThrowCompletionOr resume_abrupt(VM&, JS::Completion abrupt_completion, Optional const& generator_brand); -private: - GeneratorObject(Realm&, Object& prototype, ExecutionContext); - enum class GeneratorState { SuspendedStart, SuspendedYield, Executing, Completed, }; + GeneratorState generator_state() const { return m_generator_state; } + void set_generator_state(GeneratorState generator_state) { m_generator_state = generator_state; } + +protected: + GeneratorObject(Realm&, Object& prototype, ExecutionContext, Optional generator_brand = {}); ThrowCompletionOr validate(VM&, Optional const& generator_brand); - ThrowCompletionOr execute(VM&, JS::Completion const& completion); + virtual ThrowCompletionOr execute(VM&, JS::Completion const& completion); +private: ExecutionContext m_execution_context; GCPtr m_generating_function; Value m_previous_value;