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
qv4property_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 QV4PROPERTYDESCRIPTOR_H
5#define QV4PROPERTYDESCRIPTOR_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 "qv4global_p.h"
19#include "qv4value_p.h"
20
22
23namespace QV4 {
24
25struct FunctionObject;
26
27struct Property {
28 Value value;
29 Value set;
30
31 // Section 8.10
32 inline void fullyPopulated(PropertyAttributes *attrs) {
33 if (!attrs->hasType()) {
34 value = Value::undefinedValue();
35 }
36 if (attrs->type() == PropertyAttributes::Accessor) {
37 attrs->clearWritable();
38 if (value.isEmpty())
39 value = Value::undefinedValue();
40 if (set.isEmpty())
41 set = Value::undefinedValue();
42 }
43 attrs->resolve();
44 }
45
46 // ES8: 6.2.5.6
47 void completed(PropertyAttributes *attrs) {
48 if (value.isEmpty())
49 value = Encode::undefined();
50 if (attrs->isGeneric() || attrs->isData()) {
51 attrs->setType(PropertyAttributes::Data);
52 if (!attrs->hasWritable())
53 attrs->setWritable(false);
54 } else {
55 if (set.isEmpty())
56 set = Encode::undefined();
57 }
58 if (!attrs->hasEnumerable())
59 attrs->setEnumerable(false);
60 if (!attrs->hasConfigurable())
61 attrs->setConfigurable(false);
62 }
63
64 inline bool isSubset(const PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const;
65 inline void merge(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs);
66
67 inline Heap::FunctionObject *getter() const { return reinterpret_cast<Heap::FunctionObject *>(value.heapObject()); }
68 inline Heap::FunctionObject *setter() const { return reinterpret_cast<Heap::FunctionObject *>(set.heapObject()); }
69 inline void setGetter(FunctionObject *g) { value = reinterpret_cast<Managed *>(g); }
70 inline void setSetter(FunctionObject *s) { set = (s ? reinterpret_cast<Managed *>(s) : nullptr); }
71
72 void copy(const Property *other, PropertyAttributes attrs) {
73 value = other->value;
74 if (attrs.isAccessor())
75 set = other->set;
76 }
77
78 // ES8, section 9.1.6.2/9,.1.6.3
79 bool isCompatible(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const {
80 if (otherAttrs.isEmpty())
81 return true;
82 if (!attrs.isConfigurable()) {
83 if (otherAttrs.hasConfigurable() && otherAttrs.isConfigurable())
84 return false;
85 if (otherAttrs.hasEnumerable() && otherAttrs.isEnumerable() != attrs.isEnumerable())
86 return false;
87 }
88 if (otherAttrs.isGeneric())
89 return true;
90 if (attrs.isData() != otherAttrs.isData()) {
91 if (!attrs.isConfigurable())
92 return false;
93 } else if (attrs.isData() && otherAttrs.isData()) {
94 if (!attrs.isConfigurable() && !attrs.isWritable()) {
95 if (otherAttrs.hasWritable() && otherAttrs.isWritable())
96 return false;
97 if (!other->value.isEmpty() && !value.sameValue(other->value))
98 return false;
99 }
100 } else if (attrs.isAccessor() && otherAttrs.isAccessor()) {
101 if (!attrs.isConfigurable()) {
102 if (!other->value.isEmpty() && !value.sameValue(other->value))
103 return false;
104 if (!other->set.isEmpty() && !set.sameValue(other->set))
105 return false;
106 }
107 }
108 return true;
109 }
110
111
112 explicit Property() { value = Encode::undefined(); set = Value::fromHeapObject(nullptr); }
113 Property(Heap::FunctionObject *getter, Heap::FunctionObject *setter) {
114 value.setM(reinterpret_cast<Heap::Base *>(getter));
115 set.setM(reinterpret_cast<Heap::Base *>(setter));
116 }
117private:
119};
120
121inline bool Property::isSubset(const PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const
122{
123 if (attrs.type() != PropertyAttributes::Generic && attrs.type() != otherAttrs.type())
124 return false;
125 if (attrs.hasEnumerable() && attrs.isEnumerable() != otherAttrs.isEnumerable())
126 return false;
127 if (attrs.hasConfigurable() && attrs.isConfigurable() != otherAttrs.isConfigurable())
128 return false;
129 if (attrs.hasWritable() && attrs.isWritable() != otherAttrs.isWritable())
130 return false;
131 if (attrs.type() == PropertyAttributes::Data && !value.sameValue(other->value))
132 return false;
133 if (attrs.type() == PropertyAttributes::Accessor) {
134 if (value.heapObject() != other->value.heapObject())
135 return false;
136 if (set.heapObject() != other->set.heapObject())
137 return false;
138 }
139 return true;
140}
141
142inline void Property::merge(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs)
143{
144 if (otherAttrs.hasEnumerable())
145 attrs.setEnumerable(otherAttrs.isEnumerable());
146 if (otherAttrs.hasConfigurable())
147 attrs.setConfigurable(otherAttrs.isConfigurable());
148 if (otherAttrs.hasWritable())
149 attrs.setWritable(otherAttrs.isWritable());
150 if (otherAttrs.type() == PropertyAttributes::Accessor) {
151 attrs.setType(PropertyAttributes::Accessor);
152 if (!other->value.isEmpty())
153 value = other->value;
154 if (!other->set.isEmpty())
155 set = other->set;
156 } else if (otherAttrs.type() == PropertyAttributes::Data){
157 attrs.setType(PropertyAttributes::Data);
158 value = other->value;
159 }
160}
161
163 Heap::Base *base;
164 Value *slot;
165
166 void set(EngineBase *e, Value newVal) {
167 WriteBarrier::write(e, base, slot->data_ptr(), newVal.asReturnedValue());
168 }
169 const Value *operator->() const { return slot; }
170 const Value &operator*() const { return *slot; }
171 bool isNull() const { return !slot; }
172};
173
174
175}
176
177QT_END_NAMESPACE
178
179#endif
ArrayElementLessThan(ExecutionEngine *engine, const Value &comparefn)
bool operator()(Value v1, Value v2) const
ReturnedValue operator*() const
Definition qv4value_p.h:477
OptionalReturnedValue(ReturnedValue v)
Definition qv4value_p.h:470
ReturnedValue operator->() const
Definition qv4value_p.h:476
DECLARE_HEAP_OBJECT(StrictArgumentsObject, Object)
DECLARE_EXPORTED_HEAP_OBJECT(Object, Base)
Definition qv4object_p.h:37
DECLARE_HEAP_OBJECT(ArgumentsObject, Object)
DECLARE_HEAP_OBJECT(MemberData, Base)
DECLARE_HEAP_OBJECT(ArrayData, Base)
Q_STATIC_ASSERT(std::is_trivial_v< ArrayData >)
CallResultDestination
Definition qjsvalue.h:23
Value Primitive
Definition qv4value_p.h:351
Scoped< FunctionObject > ScopedFunctionObject
void sortHelper(RandomAccessIterator start, RandomAccessIterator end, LessThan lessThan)
QVector< StackFrame > StackTrace
int qYouForgotTheQ_MANAGED_Macro(T, T)
Scoped< Object > ScopedObject
ReturnedValue value_convert(ExecutionEngine *e, const Value &v)
Scoped< ArrayObject > ScopedArrayObject
Scoped< String > ScopedString
Scoped< StringOrSymbol > ScopedStringOrSymbol
void qYouForgotTheQ_MANAGED_Macro(T1, T2)
PropertyFlag
@ Attr_Invalid
@ Attr_NotConfigurable
@ Attr_Data
@ Attr_NotEnumerable
@ Attr_ReadOnly
@ Attr_NotWritable
@ Attr_ReadOnly_ButConfigurable
@ Attr_Accessor
Q_STATIC_ASSERT(sizeof(CppStackFrame)==sizeof(JSTypesStackFrame))
Scoped< ExecutionContext > ScopedContext
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
DEFINE_OBJECT_VTABLE(StrictArgumentsObject)
DEFINE_OBJECT_VTABLE(ArgumentsObject)
#define V4_ARRAYDATA(DataClass)
#define V4_MANAGED(DataClass, superClass)
#define V4_MANAGED_SIZE_TEST
#define V4_NEEDS_DESTROY
#define V4_MANAGED_ITSELF(DataClass, superClass)
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
#define Q_MANAGED_CHECK
static qint64 virtualGetLength(const Managed *m)
static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *desc, PropertyAttributes attrs)
Heap::CallContext * context() const
static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty)
static OwnPropertyKeyIterator * virtualOwnPropertyKeys(const Object *m, Value *target)
static bool isNonStrictArgumentsObject(Managed *m)
static bool virtualDeleteProperty(Managed *m, PropertyKey id)
static PropertyAttributes virtualGetOwnProperty(const Managed *m, PropertyKey id, Property *p)
bool isMapped(uint arg) const
static bool virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver)
static bool virtualDefineOwnProperty(Managed *m, PropertyKey id, const Property *p, PropertyAttributes attrs)
static qint64 virtualGetLength(const Managed *m)
QStringList toQStringList() const
void(* setAttribute)(Object *o, uint index, PropertyAttributes attrs)
bool(* putArray)(Object *o, uint index, const Value *values, uint n)
bool(* put)(Object *o, uint index, const Value &value)
void(* push_front)(Object *o, const Value *values, uint n)
ReturnedValue(* get)(const Heap::ArrayData *d, uint index)
bool(* del)(Object *o, uint index)
ReturnedValue(* pop_front)(Object *o)
static constexpr size_t offset
Definition qv4value_p.h:408
void set(EngineBase *e, HeapBasePtr b)
Definition qv4value_p.h:418
HeapBasePtr base()
Definition qv4value_p.h:409
void set(EngineBase *e, const Value &newVal)
Definition qv4value_p.h:415
void init(const QStringList &list)
void init(double val)
PropertyAttributes attributes(uint i) const
uint mappedIndex(uint index) const
void setData(EngineBase *e, uint index, Value newVal)
const Value & data(uint index) const
uint mappedIndex(uint index) const
PropertyAttributes attributes(uint i) const
static Heap::MemberData * allocate(QV4::ExecutionEngine *e, uint n, Heap::MemberData *old=nullptr)
const Value * data() const
void set(EngineBase *e, uint index, Value v)
const Value & operator[](uint idx) const
void set(EngineBase *e, uint index, Heap::Base *b)
uint size() const
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override
const Value * operator->() const
bool isNull() const
const Value & operator*() const
void set(EngineBase *e, Value newVal)
void setGetter(FunctionObject *g)
Heap::FunctionObject * getter() const
bool isSubset(const PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const
void setSetter(FunctionObject *s)
void fullyPopulated(PropertyAttributes *attrs)
bool isCompatible(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const
void copy(const Property *other, PropertyAttributes attrs)
void completed(PropertyAttributes *attrs)
Property(Heap::FunctionObject *getter, Heap::FunctionObject *setter)
Heap::FunctionObject * setter() const
void merge(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs)
const Value * data() const
Definition qv4value_p.h:450
Value values[1]
Definition qv4value_p.h:431
void set(EngineBase *e, uint index, Value v)
Definition qv4value_p.h:440
void set(EngineBase *e, uint index, Value::HeapBasePtr b)
Definition qv4value_p.h:443
void mark(MarkStack *markStack)
Definition qv4value_p.h:454
Value::HeapBasePtr base()
Definition qv4value_p.h:433
const Value & operator[](uint index) const
Definition qv4value_p.h:446
static constexpr size_t offset
Definition qv4value_p.h:428