Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4promiseobject_p.h
Go to the documentation of this file.
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#ifndef QV4PROMISEOBJECT_H
4#define QV4PROMISEOBJECT_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include "qv4object_p.h"
18#include "qv4functionobject_p.h"
19
21
22namespace QV4 {
23
24struct PromiseCapability;
25
26namespace Promise {
27
28struct ReactionEvent;
29struct ResolveThenableEvent;
30
32{
34
35public:
36 ReactionHandler(QObject *parent = nullptr);
37 ~ReactionHandler() override;
38
39 void addReaction(ExecutionEngine *e, const Value *reaction, const Value *value);
40 void addResolveThenable(ExecutionEngine *e, const PromiseObject *promise, const Object *thenable, const FunctionObject *then);
41
42protected:
43 void customEvent(QEvent *event) override;
46};
47
48} // Promise
49
50namespace Heap {
51
55
56#define PromiseObjectMembers(class, Member) \
57 Member(class, HeapValue, HeapValue, resolution) \
58 Member(class, HeapValue, HeapValue, fulfillReactions) \
59 Member(class, HeapValue, HeapValue, rejectReactions)
60
63 void init(ExecutionEngine *e);
64
65 enum State {
66 Pending,
67 Fulfilled,
68 Rejected
69 };
70
71 void setState(State);
72 bool isSettled() const;
73 bool isPending() const;
74 bool isFulfilled() const;
75 bool isRejected() const;
76
78
79 void triggerFullfillReactions(ExecutionEngine *e);
80 void triggerRejectReactions(ExecutionEngine *e);
81};
82
83#define PromiseCapabilityMembers(class, Member) \
84 Member(class, HeapValue, HeapValue, promise) \
85 Member(class, HeapValue, HeapValue, resolve) \
86 Member(class, HeapValue, HeapValue, reject)
87
91
92#define PromiseReactionMembers(class, Member) \
93 Member(class, HeapValue, HeapValue, handler) \
94 Member(class, Pointer, PromiseCapability*, capability)
95
98
99 static Heap::PromiseReaction *createFulfillReaction(ExecutionEngine* e, const QV4::PromiseCapability *capability, const QV4::FunctionObject *onFulfilled);
100 static Heap::PromiseReaction *createRejectReaction(ExecutionEngine* e, const QV4::PromiseCapability *capability, const QV4::FunctionObject *onRejected);
101
102 void triggerWithValue(ExecutionEngine *e, const Value *value);
103
104 enum Type {
105 Function,
106 Identity,
107 Thrower
108 };
109
110 Type type;
111
112 friend class ReactionHandler;
113};
114
115#define CapabilitiesExecutorWrapperMembers(class, Member) \
116 Member(class, Pointer, PromiseCapability*, capabilities)
117
123
124#define PromiseExecutionStateMembers(class, Member) \
125 Member(class, HeapValue, HeapValue, values) \
126 Member(class, HeapValue, HeapValue, capability)
127
135
136#define ResolveElementWrapperMembers(class, Member) \
137 Member(class, HeapValue, HeapValue, state)
138
146
147#define ResolveWrapperMembers(class, Member) \
148 Member(class, Pointer, PromiseObject*, promise)
149
152 void init();
153
154 bool alreadyResolved;
155};
156
157#define RejectWrapperMembers(class, Member) \
158 Member(class, Pointer, PromiseObject*, promise)
159
162 void init();
163
164 bool alreadyResolved;
165};
166
167} // Heap
168
173
178
183
184struct Q_QML_EXPORT PromiseObject : Object
185{
188 V4_PROTOTYPE(promisePrototype)
189};
190
192{
194
195 static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *);
196 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
197
198 static ReturnedValue method_resolve(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
199 static ReturnedValue method_reject(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
200
201 static ReturnedValue method_all(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
202 static ReturnedValue method_race(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
203};
204
206{
207 void init(ExecutionEngine *engine, Object *ctor);
208
209 static ReturnedValue method_then(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
210 static ReturnedValue method_catch(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
211};
212
215
216 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
217};
218
221
222 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
223};
224
227
228 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
229};
230
233
234 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
235};
236
237} // QV4
238
240
241#endif // QV4PROMISEOBJECT_H
\inmodule QtCore
Definition qcoreevent.h:45
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
ReactionHandler(QObject *parent=nullptr)
void addResolveThenable(ExecutionEngine *e, const PromiseObject *promise, const Object *thenable, const FunctionObject *then)
void customEvent(QEvent *event) override
This event handler can be reimplemented in a subclass to receive custom events.
void addReaction(ExecutionEngine *e, const Value *reaction, const Value *value)
void executeResolveThenable(ResolveThenableEvent *event)
void executeReaction(ReactionEvent *event)
else opt state
[0]
Combined button and popup list for selecting options.
quint64 ReturnedValue
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint index
[2]
GLfloat GLfloat f
GLenum type
struct _cl_event * event
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define Q_OBJECT
unsigned int uint
Definition qtypes.h:34
#define V4_NEEDS_DESTROY
#define DECLARE_HEAP_OBJECT(name, base)
#define DECLARE_MARKOBJECTS(class)
#define V4_PROTOTYPE(p)
#define V4_OBJECT2(DataClass, superClass)
void init(ExecutionEngine *engine)
ExecutionEngine * engine() const
static ReturnedValue method_all(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_race(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_reject(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_resolve(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_catch(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_then(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static constexpr VTable::CallAsConstructor virtualCallAsConstructor
static constexpr VTable::Call virtualCall
Definition moc.h:23