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
qv4persistent_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QV4PERSISTENT_H
5#define QV4PERSISTENT_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 "qv4value_p.h"
19#include "qv4managed_p.h"
20
22
23namespace QV4 {
24
25struct Q_QML_EXPORT PersistentValueStorage
26{
29
30 Value *allocate();
31 static void free(Value *v)
32 {
33 if (v)
35 }
36
38
39 struct Iterator {
40 Iterator(void *p, int idx);
41 Iterator(const Iterator &o);
42 Iterator & operator=(const Iterator &o);
43 ~Iterator();
44 void *p;
45 int index;
46 Iterator &operator++();
47 bool operator !=(const Iterator &other) {
48 return p != other.p || index != other.index;
49 }
50 Value &operator *();
51 };
52 Iterator begin() { return Iterator(firstPage, 0); }
53 Iterator end() { return Iterator(nullptr, 0); }
54
55 void clearFreePageHint();
56
57 static ExecutionEngine *getEngine(const Value *v);
58
60 void *firstPage;
61 void *freePageHint = nullptr;
62private:
63 static void freeUnchecked(Value *v);
64 static void freePage(void *page);
65};
66
67class Q_QML_EXPORT PersistentValue
68{
69public:
70 constexpr PersistentValue() noexcept = default;
73
78
81
85
86 void set(ExecutionEngine *engine, const Value &value);
89
91 return (val ? val->asReturnedValue() : Encode::undefined());
92 }
93 Value *valueRef() const {
94 return val;
95 }
96 Managed *asManaged() const {
97 if (!val)
98 return nullptr;
99 return val->managed();
100 }
101 template<typename T>
102 T *as() const {
103 if (!val)
104 return nullptr;
105 return val->as<T>();
106 }
107
109 if (!val)
110 return nullptr;
112 }
113
114 bool isUndefined() const { return !val || val->isUndefined(); }
115 bool isNullOrUndefined() const { return !val || val->isNullOrUndefined(); }
116 void clear() {
118 val = nullptr;
119 }
120 bool isEmpty() { return !val; }
121
122private:
123 Value *val = nullptr;
124};
125
126class Q_QML_EXPORT WeakValue
127{
128public:
130 WeakValue(const WeakValue &other);
133 ~WeakValue();
134
135 void set(ExecutionEngine *engine, const Value &value);
136
138
140
142 return (val ? val->asReturnedValue() : Encode::undefined());
143 }
144 Value *valueRef() const {
145 return val;
146 }
148 if (!val)
149 return nullptr;
150 return val->managed();
151 }
152 template <typename T>
153 T *as() const {
154 if (!val)
155 return nullptr;
156 return val->as<T>();
157 }
158
160 if (!val)
161 return nullptr;
163 }
164
165 bool isUndefined() const { return !val || val->isUndefined(); }
166 bool isNullOrUndefined() const { return !val || val->isNullOrUndefined(); }
167 void clear() { free(); }
168
170
171private:
172 Value *val = nullptr;
173
174private:
176
177 void free();
178};
179
180} // namespace QV4
181
182QT_END_NAMESPACE
183
184#endif
Definition qjsvalue.h:23