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(QV4::ExecutionContext *scope); |
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 Heap::FunctionObject *create(ExecutionContext *scope, Function *function); |
79 | static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
80 | }; |
81 | |
82 | struct MemberGeneratorFunction : MemberFunction |
83 | { |
84 | V4_OBJECT2(MemberGeneratorFunction, MemberFunction) |
85 | V4_INTERNALCLASS(MemberGeneratorFunction) |
86 | |
87 | static Heap::FunctionObject *create(ExecutionContext *scope, Function *function, Object *homeObject, String *name); |
88 | static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); |
89 | }; |
90 | |
91 | struct GeneratorPrototype : Object |
92 | { |
93 | void init(ExecutionEngine *engine, Object *ctor); |
94 | |
95 | static ReturnedValue method_next(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
96 | static ReturnedValue method_return(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
97 | static ReturnedValue method_throw(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); |
98 | }; |
99 | |
100 | |
101 | struct GeneratorObject : Object { |
102 | V4_OBJECT2(GeneratorObject, Object) |
103 | Q_MANAGED_TYPE(GeneratorObject) |
104 | V4_INTERNALCLASS(GeneratorObject) |
105 | V4_PROTOTYPE(generatorPrototype) |
106 | |
107 | ReturnedValue resume(ExecutionEngine *engine, const Value &arg) const; |
108 | }; |
109 | |
110 | } |
111 | |
112 | QT_END_NAMESPACE |
113 | |
114 | #endif // QV4GENERATORFUNCTION_P_H |
115 | |
116 | |