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#ifndef QV4PROPERTYDESCRIPTOR_H
4#define QV4PROPERTYDESCRIPTOR_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 "qv4global_p.h"
18#include "qv4value_p.h"
19
21
22namespace QV4 {
23
24struct FunctionObject;
25
26struct Property {
27 Value value;
28 Value set;
29
30 // Section 8.10
31 inline void fullyPopulated(PropertyAttributes *attrs) {
32 if (!attrs->hasType()) {
33 value = Value::undefinedValue();
34 }
35 if (attrs->type() == PropertyAttributes::Accessor) {
36 attrs->clearWritable();
37 if (value.isEmpty())
38 value = Value::undefinedValue();
39 if (set.isEmpty())
40 set = Value::undefinedValue();
41 }
42 attrs->resolve();
43 }
44
45 // ES8: 6.2.5.6
46 void completed(PropertyAttributes *attrs) {
47 if (value.isEmpty())
48 value = Encode::undefined();
49 if (attrs->isGeneric() || attrs->isData()) {
50 attrs->setType(PropertyAttributes::Data);
51 if (!attrs->hasWritable())
52 attrs->setWritable(false);
53 } else {
54 if (set.isEmpty())
55 set = Encode::undefined();
56 }
57 if (!attrs->hasEnumerable())
58 attrs->setEnumerable(false);
59 if (!attrs->hasConfigurable())
60 attrs->setConfigurable(false);
61 }
62
63 inline bool isSubset(const PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const;
64 inline void merge(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs);
65
66 inline Heap::FunctionObject *getter() const { return reinterpret_cast<Heap::FunctionObject *>(value.heapObject()); }
67 inline Heap::FunctionObject *setter() const { return reinterpret_cast<Heap::FunctionObject *>(set.heapObject()); }
68 inline void setGetter(FunctionObject *g) { value = reinterpret_cast<Managed *>(g); }
69 inline void setSetter(FunctionObject *s) { set = (s ? reinterpret_cast<Managed *>(s) : nullptr); }
70
71 void copy(const Property *other, PropertyAttributes attrs) {
72 value = other->value;
73 if (attrs.isAccessor())
74 set = other->set;
75 }
76
77 // ES8, section 9.1.6.2/9,.1.6.3
78 bool isCompatible(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const {
79 if (otherAttrs.isEmpty())
80 return true;
81 if (!attrs.isConfigurable()) {
82 if (otherAttrs.hasConfigurable() && otherAttrs.isConfigurable())
83 return false;
84 if (otherAttrs.hasEnumerable() && otherAttrs.isEnumerable() != attrs.isEnumerable())
85 return false;
86 }
87 if (otherAttrs.isGeneric())
88 return true;
89 if (attrs.isData() != otherAttrs.isData()) {
90 if (!attrs.isConfigurable())
91 return false;
92 } else if (attrs.isData() && otherAttrs.isData()) {
93 if (!attrs.isConfigurable() && !attrs.isWritable()) {
94 if (otherAttrs.hasWritable() && otherAttrs.isWritable())
95 return false;
96 if (!other->value.isEmpty() && !value.sameValue(other->value))
97 return false;
98 }
99 } else if (attrs.isAccessor() && otherAttrs.isAccessor()) {
100 if (!attrs.isConfigurable()) {
101 if (!other->value.isEmpty() && !value.sameValue(other->value))
102 return false;
103 if (!other->set.isEmpty() && !set.sameValue(other->set))
104 return false;
105 }
106 }
107 return true;
108 }
109
110
111 explicit Property() { value = Encode::undefined(); set = Value::fromHeapObject(nullptr); }
112 Property(Heap::FunctionObject *getter, Heap::FunctionObject *setter) {
113 value.setM(reinterpret_cast<Heap::Base *>(getter));
114 set.setM(reinterpret_cast<Heap::Base *>(setter));
115 }
116private:
118};
119
120inline bool Property::isSubset(const PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const
121{
122 if (attrs.type() != PropertyAttributes::Generic && attrs.type() != otherAttrs.type())
123 return false;
124 if (attrs.hasEnumerable() && attrs.isEnumerable() != otherAttrs.isEnumerable())
125 return false;
126 if (attrs.hasConfigurable() && attrs.isConfigurable() != otherAttrs.isConfigurable())
127 return false;
128 if (attrs.hasWritable() && attrs.isWritable() != otherAttrs.isWritable())
129 return false;
130 if (attrs.type() == PropertyAttributes::Data && !value.sameValue(other->value))
131 return false;
132 if (attrs.type() == PropertyAttributes::Accessor) {
133 if (value.heapObject() != other->value.heapObject())
134 return false;
135 if (set.heapObject() != other->set.heapObject())
136 return false;
137 }
138 return true;
139}
140
141inline void Property::merge(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs)
142{
143 if (otherAttrs.hasEnumerable())
144 attrs.setEnumerable(otherAttrs.isEnumerable());
145 if (otherAttrs.hasConfigurable())
146 attrs.setConfigurable(otherAttrs.isConfigurable());
147 if (otherAttrs.hasWritable())
148 attrs.setWritable(otherAttrs.isWritable());
149 if (otherAttrs.type() == PropertyAttributes::Accessor) {
150 attrs.setType(PropertyAttributes::Accessor);
151 if (!other->value.isEmpty())
152 value = other->value;
153 if (!other->set.isEmpty())
154 set = other->set;
155 } else if (otherAttrs.type() == PropertyAttributes::Data){
156 attrs.setType(PropertyAttributes::Data);
157 value = other->value;
158 }
159}
160
162 Heap::Base *base;
163 Value *slot;
164
165 void set(EngineBase *e, Value newVal) {
166 WriteBarrier::write(e, base, slot->data_ptr(), newVal.asReturnedValue());
167 }
168 const Value *operator->() const { return slot; }
169 const Value &operator*() const { return *slot; }
170 bool isNull() const { return !slot; }
171};
172
173
174}
175
176QT_END_NAMESPACE
177
178#endif
\inmodule QtQml
bool isString() const
Returns true if the type of this QJSManagedValue is string, or false otherwise.
QJSEngine * engine() const
Returns the QJSEngine this QJSManagedValue belongs to.
bool deleteProperty(quint32 arrayIndex)
Deletes the value stored at arrayIndex from this QJSManagedValue.
friend class QJSEngine
QJSValue toJSValue() const
Copies this QJSManagedValue into a new QJSValue.
QJSManagedValue jsMetaType() const
bool isBoolean() const
Returns true if the type of this QJSManagedValue is boolean, or false otherwise.
const QMetaObject * toQMetaObject() const
If this QJSManagedValue holds a QMetaObject pointer, returns it.
QStringList jsMetaMembers() const
bool isArray() const
Returns true if this value represents a JavaScript Array object, or false otherwise.
bool isError() const
Returns true if this value represents a JavaScript Error object, or false otherwise.
bool strictlyEquals(const QJSManagedValue &other) const
Invokes the JavaScript '===' operator on this QJSManagedValue and other, and returns the result.
bool hasProperty(const QString &name) const
Returns true if this QJSManagedValue has a property name, otherwise returns false.
QJSValue call(const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it with the given arguments,...
QObject * toQObject() const
If this QJSManagedValue holds a QObject pointer, returns it.
bool isRegularExpression() const
Returns true if this value represents a JavaScript regular expression object, or false otherwise.
QJSValue property(const QString &name) const
Returns the property name of this QJSManagedValue.
QJSManagedValue jsMetaInstantiate(const QJSValueList &values={}) const
bool hasOwnProperty(quint32 arrayIndex) const
Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
QVariant toVariant() const
Copies this QJSManagedValue into a new QVariant.
bool hasProperty(quint32 arrayIndex) const
Returns true if this QJSManagedValue has an array index arrayIndex, otherwise returns false.
double toNumber() const
Converts the manged value to a number.
QJSManagedValue & operator=(QJSManagedValue &&other)
Move-assigns a QJSManagedValue from other.
QJSValue callAsConstructor(const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it as constructor with the give...
bool isVariant() const
Returns true if this value represents a QVariant managed on the JavaScript heap, or false otherwise.
bool isFunction() const
Returns true if the type of this QJSManagedValue is function, false otherwise.
QRegularExpression toRegularExpression() const
If this QJSManagedValue holds a JavaScript regular expression object, returns an equivalent QRegularE...
QJSManagedValue prototype() const
Returns the prototype for this QJSManagedValue.
bool isUndefined() const
Returns true if the type of this QJSManagedValue is undefined, or false otherwise.
bool isDate() const
Returns true if this value represents a JavaScript Date object, or false otherwise.
bool equals(const QJSManagedValue &other) const
Invokes the JavaScript '==' operator on this QJSManagedValue and other, and returns the result.
~QJSManagedValue()
Destroys the QJSManagedValue.
QJSPrimitiveValue toPrimitive() const
Converts the manged value to a QJSPrimitiveValue.
bool deleteProperty(const QString &name)
Deletes the property name from this QJSManagedValue.
bool isQMetaObject() const
Returns true if this value represents a QMetaObject pointer managed on the JavaScript heap,...
QDateTime toDateTime() const
If this QJSManagedValue holds a JavaScript Date object, returns an equivalent QDateTime.
int toInteger() const
Converts the manged value to an integer.
QString toString() const
Converts the manged value to a string.
QUrl toUrl() const
If this QJSManagedValue holds a JavaScript Url object, returns an equivalent QUrl.
bool isQObject() const
Returns true if this value represents a QObject pointer managed on the JavaScript heap,...
bool hasOwnProperty(const QString &name) const
Returns true if this QJSManagedValue has a property name, otherwise returns false.
void setPrototype(const QJSManagedValue &prototype)
Sets the prototype of this QJSManagedValue to prototype.
bool isUrl() const
Returns true if this value represents a JavaScript Url object, or false otherwise.
bool isInteger() const
Returns true if this QJSManagedValue holds an integer value, or false otherwise.
bool isNumber() const
Returns true if the type of this QJSManagedValue is number, or false otherwise.
bool isNull() const
Returns true if this QJSManagedValue holds the JavaScript null value, or false otherwise.
bool isSymbol() const
Returns true if the type of this QJSManagedValue is symbol, or false otherwise.
bool isObject() const
Returns true if the type of this QJSManagedValue is object, or false otherwise.
void setProperty(const QString &name, const QJSValue &value)
Sets the property name to value on this QJSManagedValue.
void setProperty(quint32 arrayIndex, const QJSValue &value)
Stores the value at arrayIndex in this QJSManagedValue.
bool toBoolean() const
Converts the manged value to a boolean.
QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &arguments={}) const
If this QJSManagedValue represents a JavaScript FunctionObject, calls it on instance with the given a...
bool isJsMetaType() const
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
static QV4::ExecutionEngine * engine(const QJSValue *jsval)
Definition qjsvalue_p.h:321
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
virtual QVariant property(QPrintDevice::PrintDevicePropertyKey key) const
ArrayElementLessThan(ExecutionEngine *engine, const Value &comparefn)
bool operator()(Value v1, Value v2) const
ReturnedValue operator*() const
Definition qv4value_p.h:476
OptionalReturnedValue(ReturnedValue v)
Definition qv4value_p.h:469
ReturnedValue operator->() const
Definition qv4value_p.h:475
Combined button and popup list for selecting options.
DECLARE_EXPORTED_HEAP_OBJECT(Object, Base)
Definition qv4object_p.h:36
DECLARE_HEAP_OBJECT(MemberData, Base)
DECLARE_HEAP_OBJECT(ArrayData, Base)
Q_STATIC_ASSERT(std::is_trivial_v< ArrayData >)
CallResultDestination
Definition qjsvalue.h:23
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(std::is_trivial_v< Value >)
Scoped< ExecutionContext > ScopedContext
T caughtResult(const QJSValue *v, T(QV4::Value::*convert)() const)
Definition qjsvalue.cpp:514
static bool js_equal(const QString &string, const QV4::Value &value)
Definition qjsvalue.cpp:972
QDataStream & operator<<(QDataStream &stream, const QJSValue &jsv)
QDataStream & operator>>(QDataStream &stream, QJSValue &jsv)
QList< QJSValue > QJSValueList
Definition qjsvalue.h:22
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
#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
double d
[1]
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:407
void set(EngineBase *e, HeapBasePtr b)
Definition qv4value_p.h:417
HeapBasePtr base()
Definition qv4value_p.h:408
void set(EngineBase *e, const Value &newVal)
Definition qv4value_p.h:414
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:449
Value values[1]
Definition qv4value_p.h:430
void set(EngineBase *e, uint index, Value v)
Definition qv4value_p.h:439
void set(EngineBase *e, uint index, Value::HeapBasePtr b)
Definition qv4value_p.h:442
void mark(MarkStack *markStack)
Definition qv4value_p.h:453
Value::HeapBasePtr base()
Definition qv4value_p.h:432
const Value & operator[](uint index) const
Definition qv4value_p.h:445
static constexpr size_t offset
Definition qv4value_p.h:427