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/qv4urlobject_p.h>
232#ifndef QT_NO_CAST_FROM_ASCII
371 return QJSValuePrivate::asManagedType<ErrorObject>(
this);
380 return QJSValuePrivate::asManagedType<UrlObject>(
this);
395 switch (
error->d()->errorType) {
396 case QV4::Heap::ErrorObject::Error:
398 case QV4::Heap::ErrorObject::EvalError:
400 case QV4::Heap::ErrorObject::RangeError:
402 case QV4::Heap::ErrorObject::ReferenceError:
404 case QV4::Heap::ErrorObject::SyntaxError:
406 case QV4::Heap::ErrorObject::TypeError:
408 case QV4::Heap::ErrorObject::URIError:
422 return QJSValuePrivate::asManagedType<ArrayObject>(
this);
436 return QJSValuePrivate::asManagedType<QV4::Object>(
this);
447 return QJSValuePrivate::asManagedType<FunctionObject>(
this);
458 return QJSValuePrivate::asManagedType<QV4::VariantObject>(
this);
528 return string->size() > 0;
622 if (
val.isUndefined())
625 return QVariant(QMetaType::fromType<std::nullptr_t>(),
nullptr);
683 const FunctionObject *
f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
695 qWarning(
"QJSValue::call() failed: cannot call function with argument created in a different engine");
732 const FunctionObject *
f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
741 qWarning(
"QJSValue::call() failed: cannot call function with thisObject created in a different engine");
749 qWarning(
"QJSValue::call() failed: cannot call function with argument created in a different engine");
784 const FunctionObject *
f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
795 qWarning(
"QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine");
823 ScopedObject o(scope, QJSValuePrivate::asManagedType<QV4::Object>(
this));
855 o->setPrototypeOf(
nullptr);
862 if (
o->engine() !=
p->engine()) {
863 qWarning(
"QJSValue::setPrototype() failed: cannot set a prototype created in a different engine");
866 if (!
o->setPrototypeOf(
p))
867 qWarning(
"QJSValue::setPrototype() failed: cyclic prototype value");
895 switch (
value.type()) {
923 }
else if (
value.d->isManaged()) {
937 return string ==
s->toQString();
938 if (
value.isNumber())
940 if (
value.isBoolean())
978 return *
string == *otherString;
1015 return *
string == *otherString;
1016 if (
const String *
s = QJSValuePrivate::asManagedType<String>(&
other))
1017 return *
string ==
s->toQString();
1022 if (
const String *
s = QJSValuePrivate::asManagedType<String>(
this))
1023 return *otherString ==
s->toQString();
1061 if (
engine->hasException)
1108 if (
engine->hasException)
1109 engine->catchException();
1140 qWarning(
"QJSValue::setProperty(%s) failed: cannot set value created in a different engine",
name.toUtf8().constData());
1146 o->put(
s->toPropertyKey(),
v);
1147 if (
engine->hasException)
1148 engine->catchException();
1194 qWarning(
"QJSValue::setProperty(%d) failed: cannot set value created in a different engine", arrayIndex);
1201 if (
engine->hasException)
1202 engine->catchException();
1237 return o->deleteProperty(
s->toPropertyKey());
1258 return o->hasProperty(
s->toPropertyKey());
1337 return date->toQDateTime();
1347 return QJSValuePrivate::asManagedType<DateObject>(
this);
1356 return QJSValuePrivate::asManagedType<RegExpObject>(
this);
1370 return QJSValuePrivate::asManagedType<QV4::QObjectWrapper>(
this);
1383 return QJSValuePrivate::asManagedType<QV4::QMetaObjectWrapper>(
this);
1386#ifndef QT_NO_DATASTREAM
1389 quint32 isNullOrUndefined = 0;
1391 isNullOrUndefined |= 0x1;
1393 isNullOrUndefined |= 0x2;
1394 stream << isNullOrUndefined;
1395 if (!isNullOrUndefined) {
1397 switch (
v.userType()) {
1398 case QMetaType::Bool:
1399 case QMetaType::Double:
1400 case QMetaType::Int:
1401 case QMetaType::QString:
1405 qWarning() <<
"QDataStream::operator<< was to save a non-trivial QJSValue."
1406 <<
"This is not supported anymore, please stream a QVariant instead.";
1418 stream >> isNullOrUndefined;
1420 if (isNullOrUndefined & 0x1) {
1422 }
else if (isNullOrUndefined & 0x2) {
1428 switch (
v.userType()) {
1429 case QMetaType::Bool:
1432 case QMetaType::Double:
1435 case QMetaType::Int:
1438 case QMetaType::QString:
1442 qWarning() <<
"QDataStream::operator>> to restore a non-trivial QJSValue."
1443 <<
"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 class; otherwise returns false.
bool isVariant() const
Returns true if this QJSValue is a variant value; 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.
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
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 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)
QString toQStringNoThrow() const