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/qv4regexpobject_p.h>
17#include <QtQml/private/qv4dateobject_p.h>
18#include <QtQml/private/qv4errorobject_p.h>
19#include <QtQml/private/qv4identifiertable_p.h>
21#include <QtCore/qregularexpression.h>
22#include <QtCore/qurl.h>
23#include <QtCore/qdatetime.h>
125 qWarning(
"QJSManagedValue(QJSValue, QJSEngine *) failed: "
126 "Value was created in different engine.");
149 switch (
value.type()) {
224 if (
this != &
other) {
241 return !
other.d ||
other.d->isNullOrUndefined();
274 return v4->jsEngine();
292 *
result.d =
object->getPrototypeOf();
301 if (
result.d->isUndefined())
317 qWarning(
"QJSManagedValue::setPrototype() failed: "
318 "Can only set a prototype on an object (excluding null).");
324 qWarning(
"QJSManagedValue::setPrototype() failed: "
325 "Can only set objects (including null) as prototypes.");
330 qWarning(
"QJSManagedValue::setPrototype() failed: "
331 "Prototype was created in differen engine.");
337 qWarning(
"QJSManagedValue::setPrototype() failed: "
338 "Prototype cycle detected.");
625 return QVariant(QMetaType::fromType<std::nullptr_t>(),
nullptr);
647 return r->toQRegularExpression();
680 return m->metaObject();
691 return t->toQDateTime();
710 return obj->hasProperty(
key);
778 QStringLiteral(
"Value is null and could not be converted to an object"));
785 qWarning(
"QJSManagedValue::setProperty() failed: "
786 "Value was created in different engine.");
806 return obj->deleteProperty(
key);
827 if (arrayIndex == std::numeric_limits<quint32>::max())
851 if (arrayIndex == std::numeric_limits<quint32>::max()) {
852 return obj->getOwnProperty(
obj->engine()->id_uintMax()->toPropertyKey())
874 const QString qString =
string->toQString();
876 return qString.
sliced(arrayIndex, 1);
881 if (arrayIndex == std::numeric_limits<quint32>::max())
904 qWarning(
"QJSManagedValue::setProperty() failed: "
905 "Value was created in different engine.");
930 qWarning(
"QJSManagedValue: Calling a default-constructed or moved-from managed value"
931 "should throw an exception, but there is no engine to receive it.");
965 qWarning(
"QJSManagedValue::call() failed: Argument was created in different engine.");
993 qWarning(
"QJSManagedValue::callWithInstance() failed: "
994 "Instance was created in different engine.");
1004 qWarning(
"QJSManagedValue::callWithInstance() failed: "
1005 "Argument was created in different engine.");
1036 qWarning(
"QJSManagedValue::callAsConstructor() failed: "
1037 "Argument was created in different engine.");
1063 *
result.d =
m->internalClass();
1085 const auto heapClass =
c->d();
1086 const int size = heapClass->size;
1089 for (
int i = 0;
i <
size; ++
i)
1090 result.append(heapClass->keyAt(
i));
1117 *
result.d =
c->engine()->newObject(
c->d());
1123 qWarning(
"QJSManagedValue::instantiate() failed: "
1124 "Argument was created in different engine.");
1137 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
qsizetype size() const
Returns the number of characters in this string.
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)
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
Heap::String * newString(const QString &s=QString())
QV4::ReturnedValue fromVariant(const QVariant &)
Object * numberPrototype() const
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