4#include <QtQml/qjsmanagedvalue.h>
5#include <QtQml/qjsengine.h>
6#include <QtQml/private/qv4persistent_p.h>
7#include <QtQml/private/qv4engine_p.h>
8#include <QtQml/private/qv4mm_p.h>
9#include <QtQml/private/qjsvalue_p.h>
10#include <QtQml/private/qv4runtime_p.h>
11#include <QtQml/private/qv4functionobject_p.h>
12#include <QtQml/private/qv4jscall_p.h>
13#include <QtQml/private/qv4urlobject_p.h>
14#include <QtQml/private/qv4variantobject_p.h>
15#include <QtQml/private/qv4qobjectwrapper_p.h>
16#include <QtQml/private/qv4qmetaobjectwrapper_p.h>
17#include <QtQml/private/qv4regexpobject_p.h>
18#include <QtQml/private/qv4dateobject_p.h>
19#include <QtQml/private/qv4errorobject_p.h>
20#include <QtQml/private/qv4identifiertable_p.h>
22#include <QtCore/qregularexpression.h>
23#include <QtCore/qurl.h>
24#include <QtCore/qdatetime.h>
126 qWarning(
"QJSManagedValue(QJSValue, QJSEngine *) failed: "
127 "Value was created in different engine.");
150 switch (
value.type()) {
225 if (
this != &
other) {
242 return !
other.d ||
other.d->isNullOrUndefined();
275 return v4->jsEngine();
293 *
result.d =
object->getPrototypeOf();
302 if (
result.d->isUndefined())
318 qWarning(
"QJSManagedValue::setPrototype() failed: "
319 "Can only set a prototype on an object (excluding null).");
325 qWarning(
"QJSManagedValue::setPrototype() failed: "
326 "Can only set objects (including null) as prototypes.");
331 qWarning(
"QJSManagedValue::setPrototype() failed: "
332 "Prototype was created in differen engine.");
338 qWarning(
"QJSManagedValue::setPrototype() failed: "
339 "Prototype cycle detected.");
626 return QVariant(QMetaType::fromType<std::nullptr_t>(),
nullptr);
648 return r->toQRegularExpression();
681 return m->metaObject();
692 return t->toQDateTime();
711 return obj->hasProperty(
key);
779 QStringLiteral(
"Value is null and could not be converted to an object"));
786 qWarning(
"QJSManagedValue::setProperty() failed: "
787 "Value was created in different engine.");
807 return obj->deleteProperty(
key);
828 if (arrayIndex == std::numeric_limits<quint32>::max())
852 if (arrayIndex == std::numeric_limits<quint32>::max()) {
853 return obj->getOwnProperty(
obj->engine()->id_uintMax()->toPropertyKey())
875 const QString qString =
string->toQString();
876 if (arrayIndex <
quint32(qString.size()))
877 return qString.
sliced(arrayIndex, 1);
882 if (arrayIndex == std::numeric_limits<quint32>::max())
905 qWarning(
"QJSManagedValue::setProperty() failed: "
906 "Value was created in different engine.");
931 qWarning(
"QJSManagedValue: Calling a default-constructed or moved-from managed value"
932 "should throw an exception, but there is no engine to receive it.");
966 qWarning(
"QJSManagedValue::call() failed: Argument was created in different engine.");
994 qWarning(
"QJSManagedValue::callWithInstance() failed: "
995 "Instance was created in different engine.");
1005 qWarning(
"QJSManagedValue::callWithInstance() failed: "
1006 "Argument was created in different engine.");
1037 qWarning(
"QJSManagedValue::callAsConstructor() failed: "
1038 "Argument was created in different engine.");
1064 *
result.d =
m->internalClass();
1086 const auto heapClass =
c->d();
1087 const int size = heapClass->size;
1091 for (
int i = 0;
i <
size; ++
i) {
1121 *
result.d =
c->engine()->newObject(
c->d());
1127 qWarning(
"QJSManagedValue::instantiate() failed: "
1128 "Argument was created in different engine.");
1141 d(
engine->memoryManager->m_persistentValues->allocate())
\inmodule QtCore\reentrant
The QJSEngine class provides an environment for evaluating JavaScript code.
QV4::ExecutionEngine * handle() const
QJSValue globalObject() const
Returns this engine's Global Object.
QJSEngine * engine() const
Returns the QJSEngine this QJSManagedValue belongs to.
QJSManagedValue()=default
Creates a QJSManagedValue that represents the JavaScript undefined value.
QJSValue toJSValue() const
Copies this QJSManagedValue into a new QJSValue.
QJSManagedValue jsMetaType() const
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
QVariant toVariant() const
Copies this QJSManagedValue into a new QVariant.
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.
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 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.
Type type() const
Returns the JavaScript type of 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.
Type
This enum represents the JavaScript native types, as specified by \l{ECMA-262}.
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 isNull() const
Returns true if this QJSManagedValue holds the JavaScript null value, 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
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
static bool checkEngine(QV4::ExecutionEngine *e, const QJSValue &jsval)
static QV4::ExecutionEngine * engine(const QJSValue *jsval)
static QV4::Value * takeManagedValue(QJSValue *jsval)
static QV4::ReturnedValue asReturnedValue(const QJSValue *jsval)
static const QString * asQString(const QJSValue *jsval)
static QV4::ReturnedValue convertToReturnedValue(QV4::ExecutionEngine *e, const QJSValue &jsval)
The QJSValue class acts as a container for Qt/JavaScript data types.
qsizetype size() const noexcept
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString sliced(qsizetype pos) const &
PersistentValueStorage * m_persistentValues
QList< QVariant > arguments
QJSManagedValue managed(std::move(val), &engine)
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static const QV4::FunctionObject * functionObjectForCall(QV4::Value *d)
static QV4::ExecutionEngine * v4Engine(QV4::Value *d)
constexpr const T & qMin(const T &a, const T &b)
GLenum GLsizei GLsizei GLint * values
[15]
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLchar *const * string
[0]
#define QStringLiteral(str)
QT_BEGIN_NAMESPACE constexpr void qSwap(T &value1, T &value2) noexcept(std::is_nothrow_swappable_v< T >)
An empty marker type to signify the JavaScript null value. \inmodule QtQml.
An empty marker type to signify the JavaScript Undefined type and its single value....
static constexpr ReturnedValue undefined()
static constexpr ReturnedValue null()
IdentifierTable * identifierTable
MemoryManager * memoryManager
QV4::ReturnedValue fromVariant(const QVariant &)
Object * numberPrototype() const
Heap::String * newString(char16_t c)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols=true)
Object * booleanPrototype() const
ReturnedValue throwTypeError()
PropertyKey asPropertyKey(const Heap::String *str)
static ExecutionEngine * getEngine(const Value *v)
static void free(Value *v)
static PropertyKey fromArrayIndex(uint idx)
static Bool strictEqual(const Value &x, const Value &y)
static Bool call(const Value &, const Value &)
constexpr ReturnedValue asReturnedValue() const
QV4_NEARLY_ALWAYS_INLINE double doubleValue() const
bool isNullOrUndefined() const
bool booleanValue() const
bool isFunctionObject() const
QString toQString() const