4#include <QtCore/qstring.h>
5#include <QtCore/qvarlengtharray.h>
6#include <QtCore/qdatetime.h>
19#include <private/qv4mm_p.h>
20#include <private/qv4jscall_p.h>
21#include <private/qv4qobjectwrapper_p.h>
22#include <private/qv4qmetaobjectwrapper_p.h>
23#include <private/qv4urlobject_p.h>
24#include <private/qqmlbuiltins_p.h>
234#ifndef QT_NO_CAST_FROM_ASCII
373 return QJSValuePrivate::asManagedType<ErrorObject>(
this);
385 return QJSValuePrivate::asManagedType<UrlObject>(
this);
400 switch (
error->d()->errorType) {
401 case QV4::Heap::ErrorObject::Error:
403 case QV4::Heap::ErrorObject::EvalError:
405 case QV4::Heap::ErrorObject::RangeError:
407 case QV4::Heap::ErrorObject::ReferenceError:
409 case QV4::Heap::ErrorObject::SyntaxError:
411 case QV4::Heap::ErrorObject::TypeError:
413 case QV4::Heap::ErrorObject::URIError:
427 return QJSValuePrivate::asManagedType<ArrayObject>(
this);
441 return QJSValuePrivate::asManagedType<QV4::Object>(
this);
452 return QJSValuePrivate::asManagedType<FunctionObject>(
this);
455#if QT_DEPRECATED_SINCE(6, 9)
471bool QJSValue::isVariant()
const
473 if (QJSValuePrivate::asManagedType<QV4::VariantObject>(
this))
475 if (
auto vt = QJSValuePrivate::asManagedType<QV4::QQmlValueTypeWrapper>(
this))
476 if (vt->metaObject() == &QQmlVarForeign::staticMetaObject)
549 return string->size() > 0;
643 if (val.isUndefined())
646 return QVariant(QMetaType::fromType<std::nullptr_t>(),
nullptr);
648 return QVariant(val.booleanValue());
650 return QVariant(val.integerValue());
707 const FunctionObject *
f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
719 qWarning(
"QJSValue::call() failed: cannot call function with argument created in a different engine");
756 const FunctionObject *
f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
765 qWarning(
"QJSValue::call() failed: cannot call function with thisObject created in a different engine");
773 qWarning(
"QJSValue::call() failed: cannot call function with argument created in a different engine");
808 const FunctionObject *
f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
819 qWarning(
"QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine");
847 ScopedObject o(scope, QJSValuePrivate::asManagedType<QV4::Object>(
this));
879 o->setPrototypeOf(
nullptr);
886 if (
o->engine() !=
p->engine()) {
887 qWarning(
"QJSValue::setPrototype() failed: cannot set a prototype created in a different engine");
890 if (!
o->setPrototypeOf(
p))
891 qWarning(
"QJSValue::setPrototype() failed: cyclic prototype value");
919 switch (
value.type()) {
947 }
else if (
value.d->isManaged()) {
961 return string ==
s->toQString();
962 if (
value.isNumber())
964 if (
value.isBoolean())
1002 return *
string == *otherString;
1039 return *
string == *otherString;
1040 if (
const String *
s = QJSValuePrivate::asManagedType<String>(&
other))
1041 return *
string ==
s->toQString();
1046 if (
const String *
s = QJSValuePrivate::asManagedType<String>(
this))
1047 return *otherString ==
s->toQString();
1085 if (
engine->hasException)
1132 if (
engine->hasException)
1133 engine->catchException();
1164 qWarning(
"QJSValue::setProperty(%s) failed: cannot set value created in a different engine",
name.toUtf8().constData());
1170 o->put(
s->toPropertyKey(),
v);
1171 if (
engine->hasException)
1172 engine->catchException();
1218 qWarning(
"QJSValue::setProperty(%d) failed: cannot set value created in a different engine", arrayIndex);
1225 if (
engine->hasException)
1226 engine->catchException();
1261 return o->deleteProperty(
s->toPropertyKey());
1282 return o->hasProperty(
s->toPropertyKey());
1361 return date->toQDateTime();
1371 return QJSValuePrivate::asManagedType<DateObject>(
this);
1380 return QJSValuePrivate::asManagedType<RegExpObject>(
this);
1394 return QJSValuePrivate::asManagedType<QV4::QObjectWrapper>(
this);
1407 return QJSValuePrivate::asManagedType<QV4::QMetaObjectWrapper>(
this);
1410#ifndef QT_NO_DATASTREAM
1413 quint32 isNullOrUndefined = 0;
1415 isNullOrUndefined |= 0x1;
1416 if (jsv.isUndefined())
1417 isNullOrUndefined |= 0x2;
1418 stream << isNullOrUndefined;
1419 if (!isNullOrUndefined) {
1421 switch (
v.userType()) {
1422 case QMetaType::Bool:
1423 case QMetaType::Double:
1424 case QMetaType::Int:
1425 case QMetaType::QString:
1429 qWarning() <<
"QDataStream::operator<< was to save a non-trivial QJSValue."
1430 <<
"This is not supported anymore, please stream a QVariant instead.";
1442 stream >> isNullOrUndefined;
1444 if (isNullOrUndefined & 0x1) {
1446 }
else if (isNullOrUndefined & 0x2) {
1452 switch (
v.userType()) {
1453 case QMetaType::Bool:
1456 case QMetaType::Double:
1459 case QMetaType::Int:
1462 case QMetaType::QString:
1466 qWarning() <<
"QDataStream::operator>> to restore a non-trivial QJSValue."
1467 <<
"This is not supported anymore, please stream a QVariant instead.";
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
QJSValue globalObject() const
Returns this engine's Global Object.
QJSValue newErrorObject(QJSValue::ErrorType errorType, const QString &message=QString())
bool isInterrupted() const
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
static void setString(QJSValue *jsval, QString s)
static QV4::Value * qv4ValuePtr(quint64 v)
static double * doublePtr(quint64 v)
static bool checkEngine(QV4::ExecutionEngine *e, const QJSValue &jsval)
static QV4::ExecutionEngine * engine(const QJSValue *jsval)
static QV4::ReturnedValue asReturnedValue(const QJSValue *jsval)
static const QString * asQString(const QJSValue *jsval)
static quint64 encodeNull()
static QString * qStringPtr(quint64 v)
static QV4::ReturnedValue convertToReturnedValue(QV4::ExecutionEngine *e, const QJSValue &jsval)
static void adoptPersistentValue(QJSValue *jsval, QV4::Value *v)
static void setValue(QJSValue *jsval, const QV4::Value &v)
static quint64 encode(int intValue)
static quint64 encodeUndefined()
static void free(QJSValue *jsval)
static Kind tag(quint64 raw)
The QJSValue class acts as a container for Qt/JavaScript data types.
QDateTime toDateTime() const
Returns a QDateTime representation of this value, in local time.
bool hasOwnProperty(const QString &name) const
Returns true if this object has an own (not prototype-inherited) property of the given name,...
bool isUrl() const
Returns true if this QJSValue is an object of the URL JavaScript class; otherwise returns false.
bool isCallable() const
Returns true if this QJSValue is a function, otherwise returns false.
bool hasProperty(const QString &name) const
Returns true if this object has a property of the given name, otherwise returns false.
bool deleteProperty(const QString &name)
Attempts to delete this object's property of the given name.
SpecialValue
This enum is used to specify a single-valued type.
QJSValue & operator=(QJSValue &&other)
Move-assigns other to this QJSValue object.
bool toBool() const
Returns the boolean value of this QJSValue, using the conversion rules described in \l{ECMA-262} sect...
QJSValue call(const QJSValueList &args=QJSValueList()) const
Calls this QJSValue as a function, passing args as arguments to the function, and using the globalObj...
ErrorType errorType() const
QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args=QJSValueList()) const
Calls this QJSValue as a function, using instance as the ‘this’ object in the function call,...
QJSValue prototype() const
If this QJSValue is an object, returns the internal prototype ({proto} property) of this object; othe...
bool isError() const
Returns true if this QJSValue is an object of the Error class; otherwise returns false.
bool isObject() const
Returns true if this QJSValue is of the Object type; otherwise returns false.
const QMetaObject * toQMetaObject() const
~QJSValue()
Destroys this QJSValue.
qint32 toInt() const
Returns the signed 32-bit integer value of this QJSValue, using the conversion rules described in \l{...
double toNumber() const
Returns the number value of this QJSValue, as defined in \l{ECMA-262} section 9.3,...
ObjectConversionBehavior
This enum is used to specify how JavaScript objects and symbols without an equivalent native Qt type ...
bool isArray() const
Returns true if this QJSValue is an object of the Array class; otherwise returns false.
void setProperty(const QString &name, const QJSValue &value)
Sets the value of this QJSValue's property with the given name to the given value.
bool isQObject() const
Returns true if this QJSValue is a QObject; otherwise returns false.
bool isNumber() const
Returns true if this QJSValue is of the primitive type Number; otherwise returns false.
bool isUndefined() const
Returns true if this QJSValue is of the primitive type Undefined or if the managed value has been cle...
bool isBool() const
Returns true if this QJSValue is of the primitive type Boolean; otherwise returns false.
bool strictlyEquals(const QJSValue &other) const
Returns true if this QJSValue is equal to other using strict comparison (no conversion),...
bool isDate() const
Returns true if this QJSValue is an object of the Date class; otherwise returns false.
void setPrototype(const QJSValue &prototype)
If this QJSValue is an object, sets the internal prototype ({proto} property) of this object to be pr...
QJSPrimitiveValue toPrimitive() const
Converts the value to a QJSPrimitiveValue.
QObject * toQObject() const
If this QJSValue is a QObject, returns the QObject pointer that the QJSValue represents; otherwise,...
bool isNull() const
Returns true if this QJSValue is of the primitive type Null; otherwise returns false.
bool isString() const
Returns true if this QJSValue is of the primitive type String; otherwise returns false.
QString toString() const
Returns the string value of this QJSValue, as defined in \l{ECMA-262} section 9.8,...
bool equals(const QJSValue &other) const
Returns true if this QJSValue is equal to other, otherwise returns false.
quint32 toUInt() const
Returns the unsigned 32-bit integer value of this QJSValue, using the conversion rules described in \...
bool isRegExp() const
Returns true if this QJSValue is an object of the RegExp class; otherwise returns false.
bool isQMetaObject() const
QJSValue property(const QString &name) const
Returns the value of this QJSValue's property with the given name.
QVariant toVariant() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QJSValue callAsConstructor(const QJSValueList &args=QJSValueList()) const
Creates a new {Object} and calls this QJSValue as a constructor, using the created object as the ‘thi...
QJSValue(SpecialValue value=UndefinedValue)
Constructs a new QJSValue with a special value.
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
void save(QDataStream &ds) const
Internal function for saving a variant to the stream s.
void load(QDataStream &ds)
Internal function for loading a variant from stream s.
Combined button and popup list for selecting options.
Scoped< String > ScopedString
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
T caughtResult(const QJSValue *v, T(QV4::Value::*convert)() const)
static bool js_equal(const QString &string, const QV4::Value &value)
QDataStream & operator<<(QDataStream &stream, const QJSValue &jsv)
QDataStream & operator>>(QDataStream &stream, QJSValue &jsv)
GLsizei const GLfloat * v
[13]
GLsizei const GLchar *const * string
[0]
#define QStringLiteral(str)
static constexpr ReturnedValue undefined()
static QVariant toVariantLossy(const QV4::Value &value)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols=true)
static QJSPrimitiveValue createPrimitive(const Value &v)
static void free(Value *v)
static PropertyKey fromArrayIndex(uint idx)
static Bool strictEqual(const Value &x, const Value &y)
static ReturnedValue toPrimitive(const Value &value, TypeHint typeHint)
static double stringToNumber(const QString &s)
static Bool call(const Value &, const Value &)
unsigned int toUInt32() const
QML_NEARLY_ALWAYS_INLINE String * stringValue() const
static constexpr Value fromReturnedValue(ReturnedValue val)