Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant
4#ifndef QV4PROMISEOBJECT_H
5#define QV4PROMISEOBJECT_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 "qv4object_p.h"
20
22
23namespace QV4 {
24
26
27namespace Promise {
28
29struct ReactionEvent;
31
33{
35
36public:
37 ReactionHandler(QObject *parent = nullptr);
39
40 void addReaction(ExecutionEngine *e, const Value *reaction, const Value *value);
41 void addResolveThenable(ExecutionEngine *e, const PromiseObject *promise, const Object *thenable, const FunctionObject *then);
42
43protected:
44 void customEvent(QEvent *event) override;
45 void executeReaction(ReactionEvent *event);
47};
48
49} // Promise
50
51namespace Heap {
52
54 void init(ExecutionEngine *engine);
55};
56
57#define PromiseObjectMembers(class, Member)
58 Member(class, HeapValue, HeapValue, resolution)
59 Member(class, HeapValue, HeapValue, fulfillReactions)
60 Member(class, HeapValue, HeapValue, rejectReactions)
61
62DECLARE_HEAP_OBJECT(PromiseObject, Object) {
63 DECLARE_MARKOBJECTS(PromiseObject)
64 void init(ExecutionEngine *e);
65
66 enum State {
67 Pending,
68 Fulfilled,
69 Rejected
70 };
71
72 void setState(State);
73 bool isSettled() const;
74 bool isPending() const;
75 bool isFulfilled() const;
76 bool isRejected() const;
77
78 State state;
79
80 void triggerFullfillReactions(ExecutionEngine *e);
81 void triggerRejectReactions(ExecutionEngine *e);
82};
83
84#define PromiseCapabilityMembers(class, Member)
85 Member(class, HeapValue, HeapValue, promise)
86 Member(class, HeapValue, HeapValue, resolve)
87 Member(class, HeapValue, HeapValue, reject)
88
89DECLARE_HEAP_OBJECT(PromiseCapability, Object) {
90 DECLARE_MARKOBJECTS(PromiseCapability)
91};
92
93#define PromiseReactionMembers(class, Member)
94 Member(class, HeapValue, HeapValue, handler)
95 Member(class, Pointer, PromiseCapability*, capability)
96
98 DECLARE_MARKOBJECTS(PromiseReaction)
99
100 static Heap::PromiseReaction *createFulfillReaction(ExecutionEngine* e, const QV4::PromiseCapability *capability, const QV4::FunctionObject *onFulfilled);
101 static Heap::PromiseReaction *createRejectReaction(ExecutionEngine* e, const QV4::PromiseCapability *capability, const QV4::FunctionObject *onRejected);
102
103 void triggerWithValue(ExecutionEngine *e, const Value *value);
104
105 enum Type {
106 Function,
107 Identity,
108 Thrower
109 };
110
111 Type type;
112
113 friend class ReactionHandler;
114};
115
116#define CapabilitiesExecutorWrapperMembers(class, Member)
117 Member(class, Pointer, PromiseCapability*, capabilities)
118
120 DECLARE_MARKOBJECTS(CapabilitiesExecutorWrapper)
121 void init();
122 void destroy();
123};
124
125#define PromiseExecutionStateMembers(class, Member)
126 Member(class, HeapValue, HeapValue, values)
127 Member(class, HeapValue, HeapValue, capability)
128
130 DECLARE_MARKOBJECTS(PromiseExecutionState)
131 void init();
132
133 uint index;
134 uint remainingElementCount;
135};
136
137#define ResolveElementWrapperMembers(class, Member)
138 Member(class, HeapValue, HeapValue, state)
139
141 DECLARE_MARKOBJECTS(ResolveElementWrapper)
142 void init();
143
144 uint index;
145 bool alreadyResolved;
146};
147
148#define ResolveWrapperMembers(class, Member)
149 Member(class, Pointer, PromiseObject*, promise)
150
152 DECLARE_MARKOBJECTS(ResolveWrapper)
153 void init();
154
155 bool alreadyResolved;
156};
157
158#define RejectWrapperMembers(class, Member)
159 Member(class, Pointer, PromiseObject*, promise)
160
162 DECLARE_MARKOBJECTS(RejectWrapper)
163 void init();
164
165 bool alreadyResolved;
166};
167
168} // Heap
169
171{
172 V4_OBJECT2(PromiseReaction, Object)
173};
174
176{
177 V4_OBJECT2(PromiseCapability, Object)
178};
179
181{
182 V4_OBJECT2(PromiseExecutionState, Object)
183};
184
191
193{
194 V4_OBJECT2(PromiseCtor, FunctionObject)
195
196 static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *);
197 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
198
199 static ReturnedValue method_resolve(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
200 static ReturnedValue method_reject(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
201
202 static ReturnedValue method_all(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
203 static ReturnedValue method_race(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
204};
205
207{
208 void init(ExecutionEngine *engine, Object *ctor);
209
210 static ReturnedValue method_then(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
211 static ReturnedValue method_catch(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
212};
213
215 V4_OBJECT2(CapabilitiesExecutorWrapper, FunctionObject)
216
217 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
218};
219
221 V4_OBJECT2(ResolveElementWrapper, FunctionObject)
222
223 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
224};
225
227 V4_OBJECT2(ResolveWrapper, FunctionObject)
228
229 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
230};
231
233 V4_OBJECT2(RejectWrapper, FunctionObject)
234
235 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
236};
237
238} // QV4
239
240QT_END_NAMESPACE
241
242#endif // QV4PROMISEOBJECT_H
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)
DECLARE_HEAP_OBJECT(StrictArgumentsObject, Object)
DECLARE_HEAP_OBJECT(DynamicFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(PromiseCapability, Object)
DECLARE_HEAP_OBJECT(PromiseObject, Object)
Definition qjsvalue.h:23
#define V4_NEEDS_DESTROY
void init(ExecutionEngine *engine)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
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)