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
qv4propertykey_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 QV4PROPERTYKEY_H
4#define QV4PROPERTYKEY_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 <private/qv4writebarrier_p.h>
18#include <private/qv4global_p.h>
19#include <private/qv4staticvalue_p.h>
20#include <QtCore/qhashfunctions.h>
21
23
24class QString;
25
26namespace QV4 {
27
29{
30private:
31 // Property keys are Strings, Symbols or unsigned integers.
32 // For convenience we derive them from Values, allowing us to store them
33 // on the JS stack
34 //
35 // They do however behave somewhat different than a Value:
36 // * If the key is a String, the pointer to the string is stored in the identifier
37 // table and thus unique.
38 // * If the key is a Symbol it simply points to the referenced symbol object
39 // * if the key is an array index (a uint < UINT_MAX), it's encoded as an
40 // integer value
42
43 inline bool isManaged() const { return val.isManaged(); }
44 inline quint32 value() const { return val.value(); }
45
46public:
48 {
51 return key;
52 }
53
55 {
57 key.val.setInt_32(idx);
58 return key;
59 }
60
61 bool isStringOrSymbol() const { return isManaged(); }
63 {
65 return value();
66 }
67
68 bool isArrayIndex() const { return val.isInteger(); }
69 bool isValid() const { return !val.isUndefined(); }
70
71 // We cannot #include the declaration of Heap::StringOrSymbol here.
72 // Therefore we do some gymnastics to enforce the type safety.
73
74 template<typename StringOrSymbol = Heap::StringOrSymbol, typename Engine = QV4::EngineBase>
76 {
77 static_assert(std::is_base_of_v<Heap::StringOrSymbol, StringOrSymbol>);
81 // treat this as an insertion - the StringOrSymbol becomes reachable
82 // via the propertykey, so we consequently need to mark it durnig gc
83 b->mark(stack);
84 }
85 });
86 key.val.setM(b);
87 Q_ASSERT(key.isManaged());
88 return key;
89 }
90
91 template<typename StringOrSymbol = Heap::StringOrSymbol>
93 {
94 static_assert(std::is_base_of_v<Heap::StringOrSymbol, StringOrSymbol>);
95 if (!isManaged())
96 return nullptr;
97 return static_cast<StringOrSymbol *>(val.m());
98 }
99
100 Q_QML_EXPORT bool isString() const;
101 Q_QML_EXPORT bool isSymbol() const;
103
104 Q_QML_EXPORT QString toQString() const;
106 quint64 id() const { return val._val; }
108 PropertyKey key; key.val._val = id; return key;
109 }
110
117
118 bool operator ==(const PropertyKey &other) const { return val._val == other.val._val; }
119 bool operator !=(const PropertyKey &other) const { return val._val != other.val._val; }
120 bool operator <(const PropertyKey &other) const { return val._val < other.val._val; }
121 friend size_t qHash(const PropertyKey &key, size_t seed = 0) { return qHash(key.val._val, seed); }
122};
123
124}
125
127
128#endif
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean GLboolean GLboolean b
GLuint64 key
GLuint GLfloat * val
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
unsigned int quint32
Definition qtypes.h:50
unsigned long long quint64
Definition qtypes.h:61
unsigned int uint
Definition qtypes.h:34
QSharedPointer< T > other(t)
[5]
QJSEngine engine
[0]
bool isStringOrSymbol() const
bool isValid() const
bool isArrayIndex() const
static PropertyKey fromId(quint64 id)
Heap::StringOrSymbol * toStringOrSymbol(ExecutionEngine *e)
Q_QML_EXPORT QString toQString() const
bool isCanonicalNumericIndexString() const
Q_QML_EXPORT bool isSymbol() const
bool operator<(const PropertyKey &other) const
Q_QML_EXPORT bool isString() const
StringOrSymbol * asStringOrSymbol() const
uint asArrayIndex() const
bool operator==(const PropertyKey &other) const
static PropertyKey invalid()
static PropertyKey fromStringOrSymbol(Engine *engine, StringOrSymbol *b)
friend size_t qHash(const PropertyKey &key, size_t seed=0)
static PropertyKey fromArrayIndex(uint idx)
Heap::String * asFunctionName(ExecutionEngine *e, FunctionNamePrefix prefix) const
quint64 id() const
bool operator!=(const PropertyKey &other) const
bool isManaged() const
QV4_NEARLY_ALWAYS_INLINE constexpr void setInt_32(int i)
static constexpr StaticValue undefinedValue()
static void markCustom(Engine *engine, F &&markFunction)
static constexpr bool isInsertionBarrier