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
qjsmanagedvalue.h
Go to the documentation of this file.
1// Copyright (C) 2020 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
5#ifndef QJSMANAGEDVALUE_H
6#define QJSMANAGEDVALUE_H
7
8#include <QtQml/qtqmlglobal.h>
9#include <QtQml/qjsprimitivevalue.h>
10#include <QtQml/qjsvalue.h>
11
12QT_BEGIN_NAMESPACE
13
14namespace QV4 {
15struct Value;
16struct ExecutionEngine;
17}
18
19class QJSEngine;
20class Q_QML_EXPORT QJSManagedValue
21{
22 Q_DISABLE_COPY(QJSManagedValue)
23public:
24 enum Type {
25 Undefined,
26 Boolean,
27 Number,
28 String,
29 Object,
30 Symbol,
31 Function
32 };
33
34 QJSManagedValue() = default;
35 QJSManagedValue(QJSValue value, QJSEngine *engine);
36 QJSManagedValue(const QJSPrimitiveValue &value, QJSEngine *engine);
37 QJSManagedValue(const QVariant &variant, QJSEngine *engine);
38 QJSManagedValue(const QString &string, QJSEngine *engine);
39
40 ~QJSManagedValue();
41 QJSManagedValue(QJSManagedValue &&other);
42 QJSManagedValue &operator=(QJSManagedValue &&other);
43
44 bool equals(const QJSManagedValue &other) const;
45 bool strictlyEquals(const QJSManagedValue &other) const;
46
47 QJSEngine *engine() const;
48
50 void setPrototype(const QJSManagedValue &prototype);
51
52 Type type() const;
53
54 // Compatibility with QJSValue
55 bool isUndefined() const { return type() == Undefined; }
56 bool isBoolean() const { return type() == Boolean; }
57 bool isNumber() const { return type() == Number; }
58 bool isString() const { return type() == String; }
59 bool isObject() const { return type() == Object; }
60 bool isSymbol() const { return type() == Symbol; }
61 bool isFunction() const { return type() == Function; }
62
63 // Special case of Number
64 bool isInteger() const;
65
66 // Selected special cases of Object
67 bool isNull() const;
68 bool isRegularExpression() const;
69 bool isArray() const;
70 bool isUrl() const;
71 bool isVariant() const;
72 bool isQObject() const;
73 bool isQMetaObject() const;
74 bool isDate() const;
75 bool isError() const;
76 bool isJsMetaType() const;
77
78 // Native type transformations
79 QString toString() const;
80 double toNumber() const;
81 bool toBoolean() const;
82
83 // Variant-like type transformations
85 QJSValue toJSValue() const;
86 QVariant toVariant() const;
87
88 // Special cases
89 int toInteger() const;
91 QUrl toUrl() const;
92 QObject *toQObject() const;
93 const QMetaObject *toQMetaObject() const;
94 QDateTime toDateTime() const;
95
96 // Properties of objects
97 bool hasProperty(const QString &name) const;
98 bool hasOwnProperty(const QString &name) const;
99 QJSValue property(const QString &name) const;
100 void setProperty(const QString &name, const QJSValue &value);
101 bool deleteProperty(const QString &name);
102
103 // ### Qt 7 use qsizetype instead.
104 // Array indexing
105 bool hasProperty(quint32 arrayIndex) const;
106 bool hasOwnProperty(quint32 arrayIndex) const;
107 QJSValue property(quint32 arrayIndex) const;
108 void setProperty(quint32 arrayIndex, const QJSValue &value);
109 bool deleteProperty(quint32 arrayIndex);
110
111 // Calling functions
112 QJSValue call(const QJSValueList &arguments = {}) const;
113 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &arguments = {}) const;
114 QJSValue callAsConstructor(const QJSValueList &arguments = {}) const;
115
116 // JavaScript metatypes
119 QJSManagedValue jsMetaInstantiate(const QJSValueList &values = {}) const;
120
121private:
122 friend class QJSValue;
123 friend class QJSEngine;
125
126 QJSManagedValue(QV4::ExecutionEngine *engine);
127 QV4::Value *d = nullptr;
128};
129
130QT_END_NAMESPACE
131
132#endif
\inmodule QtQml
QJSManagedValue(QJSValue value, QJSEngine *engine)
Creates a QJSManagedValue from value, using the heap of engine.
bool isString() const
Returns true if the type of this QJSManagedValue is string, or false otherwise.
bool deleteProperty(quint32 arrayIndex)
Deletes the value stored at arrayIndex from this QJSManagedValue.
QJSManagedValue()=default
Creates a QJSManagedValue that represents the JavaScript undefined value.
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 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.
QJSManagedValue(const QJSPrimitiveValue &value, QJSEngine *engine)
Creates a QJSManagedValue from value using the heap of engine.
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.
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.
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 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.
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
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
virtual QVariant property(QPrintDevice::PrintDevicePropertyKey key) const
virtual bool setProperty(QPrintDevice::PrintDevicePropertyKey key, const QVariant &value)
QQmlEngine * engine() const
Return the QQmlEngine this incubation controller is set on, or 0 if it has not been set on any engine...
bool isError() const
Returns true if the incubator's status() is Error.
bool isNull() const
Returns true if the incubator's status() is Null.
Method & operator=(Method &&) noexcept
Move-assigns other to this Method instance.
Definition qqmlsa.cpp:624
Definition qjsvalue.h:24