Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qjsvalue.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
4#include <QtCore/qstring.h>
5#include <QtCore/qvarlengtharray.h>
6#include <QtCore/qdatetime.h>
7#include "qjsvalue.h"
8#include "qjsprimitivevalue.h"
9#include "qjsmanagedvalue.h"
10#include "qjsvalue_p.h"
11#include "qv4value_p.h"
12#include "qv4object_p.h"
13#include "qv4functionobject_p.h"
14#include "qv4dateobject_p.h"
15#include "qv4runtime_p.h"
16#include "qv4variantobject_p.h"
17#include "qv4regexpobject_p.h"
18#include "qv4errorobject_p.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>
25
178
179using namespace QV4;
180
187
194
201
208
215
220 : d(value == NullValue ? QJSValuePrivate::encodeNull() : QJSValuePrivate::encodeUndefined())
221{
222}
223
230
234#ifndef QT_NO_CAST_FROM_ASCII
236{
237}
238#endif
239
266
286
297
305{
306 switch (QJSValuePrivate::tag(d)) {
309 return true;
310 default:
311 break;
312 }
313
314 return false;
315}
316
325
333{
334 switch (QJSValuePrivate::tag(d)) {
336 return true;
338 return QJSValuePrivate::qv4ValuePtr(d)->isString();
339 }
340 default:
341 break;
342 }
343
344 return false;
345}
346
352{
353 switch (QJSValuePrivate::tag(d)) {
355 return true;
357 return QJSValuePrivate::qv4ValuePtr(d)->isUndefined();
358 default:
359 break;
360 }
361
362 return false;
363}
364
372{
373 return QJSValuePrivate::asManagedType<ErrorObject>(this);
374}
375
383bool QJSValue::isUrl() const
384{
385 return QJSValuePrivate::asManagedType<UrlObject>(this);
386}
387
396{
397 const QV4::ErrorObject *error = QJSValuePrivate::asManagedType<ErrorObject>(this);
398 if (!error)
399 return NoError;
400 switch (error->d()->errorType) {
401 case QV4::Heap::ErrorObject::Error:
402 return GenericError;
403 case QV4::Heap::ErrorObject::EvalError:
404 return EvalError;
405 case QV4::Heap::ErrorObject::RangeError:
406 return RangeError;
407 case QV4::Heap::ErrorObject::ReferenceError:
408 return ReferenceError;
409 case QV4::Heap::ErrorObject::SyntaxError:
410 return SyntaxError;
411 case QV4::Heap::ErrorObject::TypeError:
412 return TypeError;
413 case QV4::Heap::ErrorObject::URIError:
414 return URIError;
415 }
416 Q_UNREACHABLE_RETURN(NoError);
417}
418
426{
427 return QJSValuePrivate::asManagedType<ArrayObject>(this);
428}
429
440{
441 return QJSValuePrivate::asManagedType<QV4::Object>(this);
442}
443
451{
452 return QJSValuePrivate::asManagedType<FunctionObject>(this);
453}
454
455#if QT_DEPRECATED_SINCE(6, 9)
471bool QJSValue::isVariant() const
472{
473 if (QJSValuePrivate::asManagedType<QV4::VariantObject>(this))
474 return true;
475 if (auto vt = QJSValuePrivate::asManagedType<QV4::QQmlValueTypeWrapper>(this))
476 if (vt->metaObject() == &QQmlVarForeign::staticMetaObject)
477 return true;
478 return false;
479}
480#endif
481
495{
496 if (const QString *string = QJSValuePrivate::asQString(this))
497 return *string;
498
500}
501
502template<typename T>
503T caughtResult(const QJSValue *v, T (QV4::Value::*convert)() const)
504{
507 if (engine && engine->hasException) {
508 engine->catchException();
509 return T();
510 }
511 return result;
512}
513
526double QJSValue::toNumber() const
527{
528 if (const QString *string = QJSValuePrivate::asQString(this))
529 return RuntimeHelpers::stringToNumber(*string);
530
531 return caughtResult<double>(this, &QV4::Value::toNumber);
532}
533
547{
548 if (const QString *string = QJSValuePrivate::asQString(this))
549 return string->size() > 0;
550
551 return caughtResult<bool>(this, &QV4::Value::toBoolean);
552}
553
567{
568 if (const QString *string = QJSValuePrivate::asQString(this))
570
571 return caughtResult<qint32>(this, &QV4::Value::toInt32);
572}
573
587{
588 if (const QString *string = QJSValuePrivate::asQString(this))
590
591 return caughtResult<quint32>(this, &QV4::Value::toUInt32);
592}
593
605
638{
639 if (const QString *string = QJSValuePrivate::asQString(this))
640 return QVariant(*string);
641
643 if (val.isUndefined())
644 return QVariant();
645 if (val.isNull())
646 return QVariant(QMetaType::fromType<std::nullptr_t>(), nullptr);
647 if (val.isBoolean())
648 return QVariant(val.booleanValue());
649 if (val.isInt32()) // Includes doubles that can be losslessly casted to int
650 return QVariant(val.integerValue());
651 if (val.isNumber())
652 return QVariant(val.doubleValue());
653
654 Q_ASSERT(val.isManaged());
655
656 if (val.isString())
657 return QVariant(val.toQString());
658 if (val.as<QV4::Managed>()) {
659 if (behavior == RetainJSObjects)
661 val, /*typeHint*/ QMetaType{}, /*createJSValueForObjectsAndSymbols=*/ true);
662 else
664 }
665
666 Q_ASSERT(false);
667 return QVariant();
668}
669
689
706{
707 const FunctionObject *f = QJSValuePrivate::asManagedType<FunctionObject>(this);
708 if (!f)
709 return QJSValue();
710
713
714 Scope scope(engine);
715 JSCallArguments jsCallData(scope, args.size());
716 *jsCallData.thisObject = engine->globalObject;
717 for (int i = 0; i < args.size(); ++i) {
719 qWarning("QJSValue::call() failed: cannot call function with argument created in a different engine");
720 return QJSValue();
721 }
723 }
724
725 ScopedValue result(scope, f->call(jsCallData));
726 if (engine->hasException)
727 result = engine->catchException();
728 if (engine->isInterrupted.loadRelaxed())
729 result = engine->newErrorObject(QStringLiteral("Interrupted"));
730
731 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
732}
733
755{
756 const FunctionObject *f = QJSValuePrivate::asManagedType<FunctionObject>(this);
757 if (!f)
758 return QJSValue();
759
762 Scope scope(engine);
763
764 if (!QJSValuePrivate::checkEngine(engine, instance)) {
765 qWarning("QJSValue::call() failed: cannot call function with thisObject created in a different engine");
766 return QJSValue();
767 }
768
769 JSCallArguments jsCallData(scope, args.size());
770 *jsCallData.thisObject = QJSValuePrivate::convertToReturnedValue(engine, instance);
771 for (int i = 0; i < args.size(); ++i) {
773 qWarning("QJSValue::call() failed: cannot call function with argument created in a different engine");
774 return QJSValue();
775 }
777 }
778
779 ScopedValue result(scope, f->call(jsCallData));
780 if (engine->hasException)
781 result = engine->catchException();
782 if (engine->isInterrupted.loadRelaxed())
783 result = engine->newErrorObject(QStringLiteral("Interrupted"));
784
785 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
786}
787
807{
808 const FunctionObject *f = QJSValuePrivate::asManagedType<FunctionObject>(this);
809 if (!f)
810 return QJSValue();
811
814
815 Scope scope(engine);
816 JSCallArguments jsCallData(scope, args.size());
817 for (int i = 0; i < args.size(); ++i) {
819 qWarning("QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine");
820 return QJSValue();
821 }
823 }
824
825 ScopedValue result(scope, f->callAsConstructor(jsCallData));
826 if (engine->hasException)
827 result = engine->catchException();
828 if (engine->isInterrupted.loadRelaxed())
829 result = engine->newErrorObject(QStringLiteral("Interrupted"));
830
831 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
832}
833
842{
844 if (!engine)
845 return QJSValue();
846 QV4::Scope scope(engine);
847 ScopedObject o(scope, QJSValuePrivate::asManagedType<QV4::Object>(this));
848 if (!o)
849 return QJSValue();
850 ScopedObject p(scope, o->getPrototypeOf());
851 if (!p)
852 return QJSValue(NullValue);
853 return QJSValuePrivate::fromReturnedValue(p.asReturnedValue());
854}
855
868void QJSValue::setPrototype(const QJSValue& prototype)
869{
871 if (!engine)
872 return;
873 Scope scope(engine);
875 if (!o)
876 return;
878 if (val.isNull()) {
879 o->setPrototypeOf(nullptr);
880 return;
881 }
882
883 ScopedObject p(scope, val);
884 if (!p)
885 return;
886 if (o->engine() != p->engine()) {
887 qWarning("QJSValue::setPrototype() failed: cannot set a prototype created in a different engine");
888 return;
889 }
890 if (!o->setPrototypeOf(p))
891 qWarning("QJSValue::setPrototype() failed: cyclic prototype value");
892}
893
902{
903 if (d == other.d)
904 return *this;
905
907 d = 0;
908
909 if (const QString *string = QJSValuePrivate::asQString(&other))
910 QJSValuePrivate::setString(this, *string);
911 else
913
914 return *this;
915}
916
918{
919 switch (value.type()) {
922 return;
925 return;
927 d = QJSValuePrivate::encode(value.asBoolean());
928 return;
930 d = QJSValuePrivate::encode(value.asInteger());
931 return;
933 d = QJSValuePrivate::encode(value.asDouble());
934 return;
936 d = QJSValuePrivate::encode(value.asString());
937 return;
938 }
939
940 Q_UNREACHABLE();
941}
942
944{
945 if (!value.d) {
947 } else if (value.d->isManaged()) {
948 // If it's managed, we can adopt the persistent value.
950 value.d = nullptr;
951 } else {
954 value.d = nullptr;
955 }
956}
957
958static bool js_equal(const QString &string, const QV4::Value &value)
959{
960 if (String *s = value.stringValue())
961 return string == s->toQString();
962 if (value.isNumber())
963 return RuntimeHelpers::stringToNumber(string) == value.asDouble();
964 if (value.isBoolean())
965 return RuntimeHelpers::stringToNumber(string) == double(value.booleanValue());
966 if (QV4::Object *o = value.objectValue()) {
967 Scope scope(o->engine());
969 return js_equal(string, p);
970 }
971 return false;
972}
973
999{
1000 if (const QString *string = QJSValuePrivate::asQString(this)) {
1001 if (const QString *otherString = QJSValuePrivate::asQString(&other))
1002 return *string == *otherString;
1004 }
1005
1006 if (const QString *otherString = QJSValuePrivate::asQString(&other))
1007 return js_equal(*otherString, QJSValuePrivate::asReturnedValue(this));
1008
1011}
1012
1036{
1037 if (const QString *string = QJSValuePrivate::asQString(this)) {
1038 if (const QString *otherString = QJSValuePrivate::asQString(&other))
1039 return *string == *otherString;
1040 if (const String *s = QJSValuePrivate::asManagedType<String>(&other))
1041 return *string == s->toQString();
1042 return false;
1043 }
1044
1045 if (const QString *otherString = QJSValuePrivate::asQString(&other)) {
1046 if (const String *s = QJSValuePrivate::asManagedType<String>(this))
1047 return *otherString == s->toQString();
1048 return false;
1049 }
1050
1053}
1054
1073{
1075 if (!engine)
1076 return QJSValue();
1077
1078 QV4::Scope scope(engine);
1080 if (!o)
1081 return QJSValue();
1082
1083 ScopedString s(scope, engine->newString(name));
1084 QV4::ScopedValue result(scope, o->get(s->toPropertyKey()));
1085 if (engine->hasException)
1086 result = engine->catchException();
1087
1088 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
1089}
1090
1121{
1123 if (!engine)
1124 return QJSValue();
1125
1126 QV4::Scope scope(engine);
1128 if (!o)
1129 return QJSValue();
1130
1131 QV4::ScopedValue result(scope, arrayIndex == UINT_MAX ? o->get(engine->id_uintMax()) : o->get(arrayIndex));
1132 if (engine->hasException)
1133 engine->catchException();
1134 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
1135}
1136
1153{
1155 if (!engine)
1156 return;
1157 Scope scope(engine);
1158
1160 if (!o)
1161 return;
1162
1164 qWarning("QJSValue::setProperty(%s) failed: cannot set value created in a different engine", name.toUtf8().constData());
1165 return;
1166 }
1167
1168 ScopedString s(scope, engine->newString(name));
1170 o->put(s->toPropertyKey(), v);
1171 if (engine->hasException)
1172 engine->catchException();
1173}
1174
1207{
1209 if (!engine)
1210 return;
1211 Scope scope(engine);
1212
1214 if (!o)
1215 return;
1216
1218 qWarning("QJSValue::setProperty(%d) failed: cannot set value created in a different engine", arrayIndex);
1219 return;
1220 }
1221
1223 PropertyKey id = arrayIndex != UINT_MAX ? PropertyKey::fromArrayIndex(arrayIndex) : engine->id_uintMax()->propertyKey();
1224 o->put(id, v);
1225 if (engine->hasException)
1226 engine->catchException();
1227}
1228
1250{
1252 if (!engine)
1253 return false;
1254
1255 Scope scope(engine);
1257 if (!o)
1258 return false;
1259
1260 ScopedString s(scope, engine->newString(name));
1261 return o->deleteProperty(s->toPropertyKey());
1262}
1263
1271{
1273 if (!engine)
1274 return false;
1275
1276 Scope scope(engine);
1278 if (!o)
1279 return false;
1280
1281 ScopedString s(scope, engine->newString(name));
1282 return o->hasProperty(s->toPropertyKey());
1283}
1284
1292{
1294 if (!engine)
1295 return false;
1296
1297 Scope scope(engine);
1299 if (!o)
1300 return false;
1301
1302 ScopedString s(scope, engine->newIdentifier(name));
1303 return o->getOwnProperty(s->propertyKey()) != Attr_Invalid;
1304}
1305
1317{
1319 if (!engine)
1320 return nullptr;
1321 QV4::Scope scope(engine);
1323 if (!wrapper)
1324 return nullptr;
1325
1326 return wrapper->object();
1327}
1328
1338{
1340 if (!engine)
1341 return nullptr;
1342 QV4::Scope scope(engine);
1344 if (!wrapper)
1345 return nullptr;
1346
1347 return wrapper->metaObject();
1348}
1349
1350
1359{
1360 if (const QV4::DateObject *date = QJSValuePrivate::asManagedType<DateObject>(this))
1361 return date->toQDateTime();
1362 return QDateTime();
1363}
1364
1370{
1371 return QJSValuePrivate::asManagedType<DateObject>(this);
1372}
1373
1379{
1380 return QJSValuePrivate::asManagedType<RegExpObject>(this);
1381}
1382
1393{
1394 return QJSValuePrivate::asManagedType<QV4::QObjectWrapper>(this);
1395}
1396
1406{
1407 return QJSValuePrivate::asManagedType<QV4::QMetaObjectWrapper>(this);
1408}
1409
1410#ifndef QT_NO_DATASTREAM
1412{
1413 quint32 isNullOrUndefined = 0;
1414 if (jsv.isNull())
1415 isNullOrUndefined |= 0x1;
1416 if (jsv.isUndefined())
1417 isNullOrUndefined |= 0x2;
1418 stream << isNullOrUndefined;
1419 if (!isNullOrUndefined) {
1420 const QVariant v = jsv.toVariant();
1421 switch (v.userType()) {
1422 case QMetaType::Bool:
1423 case QMetaType::Double:
1424 case QMetaType::Int:
1425 case QMetaType::QString:
1426 v.save(stream);
1427 break;
1428 default:
1429 qWarning() << "QDataStream::operator<< was to save a non-trivial QJSValue."
1430 << "This is not supported anymore, please stream a QVariant instead.";
1431 QVariant().save(stream);
1432 break;
1433 }
1434
1435 }
1436 return stream;
1437}
1438
1440{
1441 quint32 isNullOrUndefined;
1442 stream >> isNullOrUndefined;
1443
1444 if (isNullOrUndefined & 0x1) {
1446 } else if (isNullOrUndefined & 0x2) {
1447 jsv = QJSValue();
1448 } else {
1449 QVariant v;
1450 v.load(stream);
1451
1452 switch (v.userType()) {
1453 case QMetaType::Bool:
1454 jsv = QJSValue(v.toBool());
1455 break;
1456 case QMetaType::Double:
1457 jsv = QJSValue(v.toDouble());
1458 break;
1459 case QMetaType::Int:
1460 jsv = QJSValue(v.toInt());
1461 break;
1462 case QMetaType::QString:
1463 jsv = QJSValue(v.toString());
1464 break;
1465 default:
1466 qWarning() << "QDataStream::operator>> to restore a non-trivial QJSValue."
1467 << "This is not supported anymore, please stream a QVariant instead.";
1468 break;
1469 }
1470 }
1471 return stream;
1472}
1473#endif
1474
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore\reentrant
Definition qdatetime.h:283
QJSValue globalObject() const
Returns this engine's Global Object.
QJSValue newErrorObject(QJSValue::ErrorType errorType, const QString &message=QString())
bool isInterrupted() const
\inmodule QtQml
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
Definition qjsvalue_p.h:197
static void setString(QJSValue *jsval, QString s)
Definition qjsvalue_p.h:278
static QV4::Value * qv4ValuePtr(quint64 v)
Definition qjsvalue_p.h:139
static double * doublePtr(quint64 v)
Definition qjsvalue_p.h:128
static bool checkEngine(QV4::ExecutionEngine *e, const QJSValue &jsval)
Definition qjsvalue_p.h:331
static QV4::ExecutionEngine * engine(const QJSValue *jsval)
Definition qjsvalue_p.h:321
static QV4::ReturnedValue asReturnedValue(const QJSValue *jsval)
Definition qjsvalue_p.h:257
static const QString * asQString(const QJSValue *jsval)
Definition qjsvalue_p.h:248
static quint64 encodeNull()
Definition qjsvalue_p.h:94
static QString * qStringPtr(quint64 v)
Definition qjsvalue_p.h:181
static QV4::ReturnedValue convertToReturnedValue(QV4::ExecutionEngine *e, const QJSValue &jsval)
Definition qjsvalue_p.h:306
static void adoptPersistentValue(QJSValue *jsval, QV4::Value *v)
Definition qjsvalue_p.h:285
static void setValue(QJSValue *jsval, const QV4::Value &v)
Definition qjsvalue_p.h:290
static quint64 encode(int intValue)
Definition qjsvalue_p.h:105
static quint64 encodeUndefined()
Definition qjsvalue_p.h:89
static void free(QJSValue *jsval)
Definition qjsvalue_p.h:337
static Kind tag(quint64 raw)
Definition qjsvalue_p.h:56
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
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.
Definition qjsvalue.cpp:383
@ RangeError
Definition qjsvalue.h:42
@ SyntaxError
Definition qjsvalue.h:44
@ ReferenceError
Definition qjsvalue.h:43
@ URIError
Definition qjsvalue.h:46
@ GenericError
Definition qjsvalue.h:40
@ EvalError
Definition qjsvalue.h:41
@ TypeError
Definition qjsvalue.h:45
@ NoError
Definition qjsvalue.h:39
bool isCallable() const
Returns true if this QJSValue is a function, otherwise returns false.
Definition qjsvalue.cpp:450
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.
Definition qjsvalue.h:33
@ NullValue
Definition qjsvalue.h:34
QJSValue & operator=(QJSValue &&other)
Move-assigns other to this QJSValue object.
Definition qjsvalue.h:60
bool toBool() const
Returns the boolean value of this QJSValue, using the conversion rules described in \l{ECMA-262} sect...
Definition qjsvalue.cpp:546
QJSValue call(const QJSValueList &args=QJSValueList()) const
Calls this QJSValue as a function, passing args as arguments to the function, and using the globalObj...
Definition qjsvalue.cpp:705
ErrorType errorType() const
Definition qjsvalue.cpp:395
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,...
Definition qjsvalue.cpp:754
QJSValue prototype() const
If this QJSValue is an object, returns the internal prototype ({proto} property) of this object; othe...
Definition qjsvalue.cpp:841
bool isError() const
Returns true if this QJSValue is an object of the Error class; otherwise returns false.
Definition qjsvalue.cpp:371
bool isObject() const
Returns true if this QJSValue is of the Object type; otherwise returns false.
Definition qjsvalue.cpp:439
const QMetaObject * toQMetaObject() const
~QJSValue()
Destroys this QJSValue.
Definition qjsvalue.cpp:282
qint32 toInt() const
Returns the signed 32-bit integer value of this QJSValue, using the conversion rules described in \l{...
Definition qjsvalue.cpp:566
double toNumber() const
Returns the number value of this QJSValue, as defined in \l{ECMA-262} section 9.3,...
Definition qjsvalue.cpp:526
ObjectConversionBehavior
This enum is used to specify how JavaScript objects and symbols without an equivalent native Qt type ...
Definition qjsvalue.h:49
@ ConvertJSObjects
Definition qjsvalue.h:50
@ RetainJSObjects
Definition qjsvalue.h:51
bool isArray() const
Returns true if this QJSValue is an object of the Array class; otherwise returns false.
Definition qjsvalue.cpp:425
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.
Definition qjsvalue.cpp:304
bool isUndefined() const
Returns true if this QJSValue is of the primitive type Undefined or if the managed value has been cle...
Definition qjsvalue.cpp:351
bool isBool() const
Returns true if this QJSValue is of the primitive type Boolean; otherwise returns false.
Definition qjsvalue.cpp:293
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...
Definition qjsvalue.cpp:868
QJSPrimitiveValue toPrimitive() const
Converts the value to a QJSPrimitiveValue.
Definition qjsvalue.cpp:681
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.
Definition qjsvalue.cpp:321
bool isString() const
Returns true if this QJSValue is of the primitive type String; otherwise returns false.
Definition qjsvalue.cpp:332
QString toString() const
Returns the string value of this QJSValue, as defined in \l{ECMA-262} section 9.8,...
Definition qjsvalue.cpp:494
bool equals(const QJSValue &other) const
Returns true if this QJSValue is equal to other, otherwise returns false.
Definition qjsvalue.cpp:998
quint32 toUInt() const
Returns the unsigned 32-bit integer value of this QJSValue, using the conversion rules described in \...
Definition qjsvalue.cpp:586
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...
Definition qjsvalue.cpp:601
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...
Definition qjsvalue.cpp:806
QJSValue(SpecialValue value=UndefinedValue)
Constructs a new QJSValue with a special value.
Definition qjsvalue.cpp:219
Definition qlist.h:75
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
\inmodule QtCore
Definition qmetatype.h:341
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
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.
QDate date
[1]
Combined button and popup list for selecting options.
@ PREFERREDTYPE_HINT
Scoped< String > ScopedString
@ Attr_Invalid
DBusConnection const char DBusError * error
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
T caughtResult(const QJSValue *v, T(QV4::Value::*convert)() const)
Definition qjsvalue.cpp:503
static bool js_equal(const QString &string, const QV4::Value &value)
Definition qjsvalue.cpp:958
QDataStream & operator<<(QDataStream &stream, const QJSValue &jsv)
QDataStream & operator>>(QDataStream &stream, QJSValue &jsv)
#define qWarning
Definition qlogging.h:166
GLsizei const GLfloat * v
[13]
GLfloat GLfloat f
GLuint name
GLdouble s
[6]
Definition qopenglext.h:235
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLsizei const GLchar *const * string
[0]
Definition qopenglext.h:694
static constexpr To convert(const std::array< Mapping, N > &mapping, From Mapping::*from, To Mapping::*to, From value, To defaultValue)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
unsigned int quint32
Definition qtypes.h:50
int qint32
Definition qtypes.h:49
unsigned int uint
Definition qtypes.h:34
#define encode(x)
QSharedPointer< T > other(t)
[5]
QJSValueList args
QJSEngine engine
[0]
\inmodule QtCore
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 &)
int toInt32() const
Definition qv4value_p.h:353
bool toBoolean() const
Definition qv4value_p.h:97
unsigned int toUInt32() const
Definition qv4value_p.h:364
QML_NEARLY_ALWAYS_INLINE String * stringValue() const
Definition qv4value_p.h:55
double toNumber() const
Definition qv4value_p.h:323
static constexpr Value fromReturnedValue(ReturnedValue val)
Definition qv4value_p.h:165
void wrapper()