| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QV4GENERATOROBJECT_P_H |
| 5 | #define QV4GENERATOROBJECT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qv4functionobject_p.h" |
| 19 | #include "qv4stackframe_p.h" |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | namespace QV4 { |
| 24 | |
| 25 | enum class GeneratorState { |
| 26 | Undefined, |
| 27 | SuspendedStart, |
| 28 | SuspendedYield, |
| 29 | Executing, |
| 30 | Completed |
| 31 | }; |
| 32 | |
| 33 | namespace Heap { |
| 34 | |
| 35 | struct GeneratorFunctionCtor : FunctionObject { |
| 36 | void init(ExecutionEngine *engine); |
| 37 | }; |
| 38 | |
| 39 | struct GeneratorFunction : ArrowFunction { |
| 40 | void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name = nullptr) { |
| 41 | ArrowFunction::init(scope, function, name); |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | struct MemberGeneratorFunction : MemberFunction { |
| 46 | }; |
| 47 | |
| 48 | struct GeneratorPrototype : FunctionObject { |
| 49 | void init(); |
| 50 | }; |
| 51 | |
| 52 | #define GeneratorObjectMembers(class, Member) \ |
| 53 | Member(class, Pointer, ExecutionContext *, context) \ |
| 54 | Member(class, NoMark, GeneratorState, state) \ |
| 55 | Member(class, NoMark, JSTypesStackFrame, cppFrame) \ |
| 56 | Member(class, Pointer, ArrayObject *, values) \ |
| 57 | Member(class, Pointer, ArrayObject *, jsFrame) |
| 58 | |
| 59 | DECLARE_HEAP_OBJECT(GeneratorObject, Object) { |
| 60 | DECLARE_MARKOBJECTS(GeneratorObject) |
| 61 | }; |
| 62 | |
| 63 | } |
| 64 | |
| 65 | struct GeneratorFunctionCtor : FunctionCtor |
| 66 | { |
| 67 | V4_OBJECT2(GeneratorFunctionCtor, FunctionCtor) |
| 68 | |
| 69 | static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *); |
| 70 | static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
| 71 | }; |
| 72 | |
| 73 | struct GeneratorFunction : ArrowFunction |
| 74 | { |
| 75 | V4_OBJECT2(GeneratorFunction, ArrowFunction) |
| 76 | V4_INTERNALCLASS(GeneratorFunction) |
| 77 | |
| 78 | static inline constexpr quint8 IsTailCallable = false; |
| 79 | |
| 80 | static Heap::FunctionObject *create(ExecutionContext *scope, Function *function); |
| 81 | static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
| 82 | }; |
| 83 | |
| 84 | struct MemberGeneratorFunction : MemberFunction |
| 85 | { |
| 86 | V4_OBJECT2(MemberGeneratorFunction, MemberFunction) |
| 87 | V4_INTERNALCLASS(MemberGeneratorFunction) |
| 88 | |
| 89 | static inline constexpr quint8 IsTailCallable = false; |
| 90 | |
| 91 | static Heap::FunctionObject *create(ExecutionContext *scope, Function *function, Object *homeObject, String *name); |
| 92 | static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
| 93 | }; |
| 94 | |
| 95 | struct GeneratorPrototype : Object |
| 96 | { |
| 97 | void init(ExecutionEngine *engine, Object *ctor); |
| 98 | |
| 99 | static ReturnedValue method_next(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
| 100 | static ReturnedValue method_return(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
| 101 | static ReturnedValue method_throw(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
| 102 | }; |
| 103 | |
| 104 | |
| 105 | struct GeneratorObject : Object { |
| 106 | V4_OBJECT2(GeneratorObject, Object) |
| 107 | Q_MANAGED_TYPE(GeneratorObject) |
| 108 | V4_INTERNALCLASS(GeneratorObject) |
| 109 | V4_PROTOTYPE(generatorPrototype) |
| 110 | |
| 111 | ReturnedValue resume(ExecutionEngine *engine, const Value &arg, std::optional<Value>) const; |
| 112 | }; |
| 113 | |
| 114 | } |
| 115 | |
| 116 | QT_END_NAMESPACE |
| 117 | |
| 118 | #endif // QV4GENERATORFUNCTION_P_H |
| 119 | |
| 120 | |