7#include <private/qjsvalue_p.h>
8#include <private/qqmlbuiltins_p.h>
9#include <private/qv4dateobject_p.h>
10#include <private/qv4errorobject_p.h>
11#include <private/qv4functionobject_p.h>
12#include <private/qv4jscall_p.h>
13#include <private/qv4mm_p.h>
14#include <private/qv4object_p.h>
15#include <private/qv4qmetaobjectwrapper_p.h>
16#include <private/qv4qobjectwrapper_p.h>
17#include <private/qv4regexpobject_p.h>
18#include <private/qv4runtime_p.h>
19#include <private/qv4urlobject_p.h>
20#include <private/qv4value_p.h>
21#include <private/qv4variantassociationobject_p.h>
22#include <private/qv4variantobject_p.h>
24#include <QtQml/qjsprimitivevalue.h>
25#include <QtQml/qjsmanagedvalue.h>
27#include <QtCore/qstring.h>
28#include <QtCore/qvarlengtharray.h>
29#include <QtCore/qdatetime.h>
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
128
129
130
131
132
133
134
135
138
139
140
141
142
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
171
172
173
174
175
176
177
178
179
180
187
188
189QJSValue::QJSValue(
bool value) : d(QJSValuePrivate::encode(value))
194
195
196QJSValue::QJSValue(
int value) : d(QJSValuePrivate::encode(value))
201
202
203QJSValue::QJSValue(uint value) : d(QJSValuePrivate::encode(value))
208
209
210QJSValue::QJSValue(
double value) : d(QJSValuePrivate::encode(value))
215
216
217QJSValue::QJSValue(
const QString &value) : d(QJSValuePrivate::encode(value))
222
223
224QJSValue::QJSValue(SpecialValue value)
225 : d(value == NullValue ? QJSValuePrivate::encodeNull() : QJSValuePrivate::encodeUndefined())
230
231
232QJSValue::QJSValue(
const QLatin1String &value) : d(QJSValuePrivate::encode(value))
237
238
239#ifndef QT_NO_CAST_FROM_ASCII
240QJSValue::QJSValue(
const char *value) : d(QJSValuePrivate::encode(QString::fromUtf8(value)))
246
247
248
249
250
251
252QJSValue::QJSValue(
const QJSValue &other) : d(other.d)
254 switch (QJSValuePrivate::tag(d)) {
255 case QJSValuePrivate::Kind::Undefined:
256 case QJSValuePrivate::Kind::Null:
257 case QJSValuePrivate::Kind::IntValue:
258 case QJSValuePrivate::Kind::BoolValue:
260 case QJSValuePrivate::Kind::DoublePtr:
261 d = QJSValuePrivate::encode(*QJSValuePrivate::doublePtr(d));
263 case QJSValuePrivate::Kind::QV4ValuePtr:
264 d = QJSValuePrivate::encode(*QJSValuePrivate::qv4ValuePtr(d));
266 case QJSValuePrivate::Kind::QStringPtr:
267 d = QJSValuePrivate::encode(*QJSValuePrivate::qStringPtr(d));
273
274
275
276
279
280
281
282
285
286
289 QJSValuePrivate::free(
this);
293
294
295
296
297
298bool QJSValue::isBool()
const
300 return QJSValuePrivate::tag(d) == QJSValuePrivate::Kind::BoolValue;
304
305
306
307
308
309bool QJSValue::isNumber()
const
311 switch (QJSValuePrivate::tag(d)) {
312 case QJSValuePrivate::Kind::IntValue:
313 case QJSValuePrivate::Kind::DoublePtr:
323
324
325
326bool QJSValue::isNull()
const
328 return QJSValuePrivate::tag(d) == QJSValuePrivate::Kind::Null;
332
333
334
335
336
337bool QJSValue::isString()
const
339 switch (QJSValuePrivate::tag(d)) {
340 case QJSValuePrivate::Kind::QStringPtr:
342 case QJSValuePrivate::Kind::QV4ValuePtr: {
343 return QJSValuePrivate::qv4ValuePtr(d)->isString();
353
354
355
356bool QJSValue::isUndefined()
const
358 switch (QJSValuePrivate::tag(d)) {
359 case QJSValuePrivate::Kind::Undefined:
361 case QJSValuePrivate::Kind::QV4ValuePtr:
362 return QJSValuePrivate::qv4ValuePtr(d)->isUndefined();
371
372
373
374
375
376bool QJSValue::isError()
const
378 return QJSValuePrivate::asManagedType<ErrorObject>(
this);
382
383
384
385
386
387
388bool QJSValue::isUrl()
const
390 return QJSValuePrivate::asManagedType<UrlObject>(
this);
394
395
396
397
398
399
400QJSValue::ErrorType QJSValue::errorType()
const
402 const QV4::ErrorObject *error = QJSValuePrivate::asManagedType<ErrorObject>(
this);
405 switch (error->d()->errorType) {
406 case QV4::Heap::ErrorObject::Error:
408 case QV4::Heap::ErrorObject::EvalError:
410 case QV4::Heap::ErrorObject::RangeError:
412 case QV4::Heap::ErrorObject::ReferenceError:
413 return ReferenceError;
414 case QV4::Heap::ErrorObject::SyntaxError:
416 case QV4::Heap::ErrorObject::TypeError:
418 case QV4::Heap::ErrorObject::URIError:
421 Q_UNREACHABLE_RETURN(NoError);
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441bool QJSValue::isArray()
const
443 return QJSValuePrivate::asManagedType<ArrayObject>(
this);
447
448
449
450
451
452
453
454
455bool QJSValue::isObject()
const
457 return QJSValuePrivate::asManagedType<QV4::Object>(
this);
461
462
463
464
465
466bool QJSValue::isCallable()
const
468 return QJSValuePrivate::asManagedType<FunctionObject>(
this);
471#if QT_DEPRECATED_SINCE(6
, 9
)
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487bool QJSValue::isVariant()
const
489 if (QJSValuePrivate::asManagedType<QV4::VariantObject>(
this))
491 if (
auto vt = QJSValuePrivate::asManagedType<QV4::QQmlValueTypeWrapper>(
this))
492 if (vt->metaObject() == &QQmlVarForeign::staticMetaObject)
499
500
501
502
503
504
505
506
507
508
509
510QString QJSValue::toString()
const
512 if (
const QString *string = QJSValuePrivate::asQString(
this))
515 return QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(
this)).toQStringNoThrow();
521 const T result = (QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(v)).*convert)();
522 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(v);
523 if (engine && engine->hasException) {
524 engine->catchException();
531
532
533
534
535
536
537
538
539
540
541
542double QJSValue::toNumber()
const
544 if (
const QString *string = QJSValuePrivate::asQString(
this))
545 return RuntimeHelpers::stringToNumber(*string);
547 return caughtResult<
double>(
this, &QV4::Value::toNumber);
551
552
553
554
555
556
557
558
559
560
561
562bool QJSValue::toBool()
const
564 if (
const QString *string = QJSValuePrivate::asQString(
this))
565 return string->size() > 0;
567 return caughtResult<
bool>(
this, &QV4::Value::toBoolean);
571
572
573
574
575
576
577
578
579
580
581
582qint32 QJSValue::toInt()
const
584 if (
const QString *string = QJSValuePrivate::asQString(
this))
585 return QV4::Value::toInt32(RuntimeHelpers::stringToNumber(*string));
587 return caughtResult<qint32>(
this, &QV4::Value::toInt32);
591
592
593
594
595
596
597
598
599
600
601
602quint32 QJSValue::toUInt()
const
604 if (
const QString *string = QJSValuePrivate::asQString(
this))
605 return QV4::Value::toUInt32(RuntimeHelpers::stringToNumber(*string));
607 return caughtResult<quint32>(
this, &QV4::Value::toUInt32);
611
612
613
614
615
616
617QVariant QJSValue::toVariant()
const
619 return toVariant(ConvertJSObjects);
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655QVariant QJSValue::toVariant(QJSValue::ObjectConversionBehavior behavior)
const
657 if (
const QString *string = QJSValuePrivate::asQString(
this))
658 return QVariant(*string);
660 QV4::Value val = QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(
this));
661 if (val.isUndefined())
664 return QVariant(QMetaType::fromType<std::nullptr_t>(),
nullptr);
666 return QVariant(val.booleanValue());
668 return QVariant(val.integerValue());
670 return QVariant(val.doubleValue());
672 Q_ASSERT(val.isManaged());
675 return QVariant(val.toQString());
677 if (behavior == RetainJSObjects) {
678 return QV4::ExecutionEngine::toVariant(
679 val, QMetaType{},
true);
681 return QV4::ExecutionEngine::toVariantLossy(val);
689
690
691
692
693
694
695
696
697
698
699QJSPrimitiveValue QJSValue::toPrimitive()
const
701 if (
const QString *string = QJSValuePrivate::asQString(
this))
704 const QV4::Value val = QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(
this));
705 return QV4::ExecutionEngine::createPrimitive(&val);
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723QJSValue QJSValue::call(
const QJSValueList &args)
const
725 const FunctionObject *f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
729 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
733 JSCallArguments jsCallData(scope, args.size());
734 *jsCallData.thisObject = engine->globalObject;
735 for (
int i = 0; i < args.size(); ++i) {
736 if (!QJSValuePrivate::checkEngine(engine, args.at(i))) {
737 qWarning(
"QJSValue::call() failed: cannot call function with argument created in a different engine");
740 jsCallData.args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i));
743 ScopedValue result(scope, f->call(jsCallData));
744 if (engine->hasException)
745 result = engine->catchException();
746 if (engine->isInterrupted.loadRelaxed())
747 result = engine->newErrorObject(QStringLiteral(
"Interrupted"));
749 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772QJSValue QJSValue::callWithInstance(
const QJSValue &instance,
const QJSValueList &args)
const
774 const FunctionObject *f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
778 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
782 if (!QJSValuePrivate::checkEngine(engine, instance)) {
783 qWarning(
"QJSValue::call() failed: cannot call function with thisObject created in a different engine");
787 JSCallArguments jsCallData(scope, args.size());
788 *jsCallData.thisObject = QJSValuePrivate::convertToReturnedValue(engine, instance);
789 for (
int i = 0; i < args.size(); ++i) {
790 if (!QJSValuePrivate::checkEngine(engine, args.at(i))) {
791 qWarning(
"QJSValue::call() failed: cannot call function with argument created in a different engine");
794 jsCallData.args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i));
797 ScopedValue result(scope, f->call(jsCallData));
798 if (engine->hasException)
799 result = engine->catchException();
800 if (engine->isInterrupted.loadRelaxed())
801 result = engine->newErrorObject(QStringLiteral(
"Interrupted"));
803 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824QJSValue QJSValue::callAsConstructor(
const QJSValueList &args)
const
826 const FunctionObject *f = QJSValuePrivate::asManagedType<FunctionObject>(
this);
830 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
834 JSCallArguments jsCallData(scope, args.size());
835 for (
int i = 0; i < args.size(); ++i) {
836 if (!QJSValuePrivate::checkEngine(engine, args.at(i))) {
837 qWarning(
"QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine");
840 jsCallData.args[i] = QJSValuePrivate::convertToReturnedValue(engine, args.at(i));
843 ScopedValue result(scope, f->callAsConstructor(jsCallData));
844 if (engine->hasException)
845 result = engine->catchException();
846 if (engine->isInterrupted.loadRelaxed())
847 result = engine->newErrorObject(QStringLiteral(
"Interrupted"));
849 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
853
854
855
856
857
858
859QJSValue QJSValue::prototype()
const
861 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
864 QV4::Scope scope(engine);
865 ScopedObject o(scope, QJSValuePrivate::asManagedType<QV4::Object>(
this));
868 ScopedObject p(scope, o->getPrototypeOf());
870 return QJSValue(NullValue);
871 return QJSValuePrivate::fromReturnedValue(p.asReturnedValue());
875
876
877
878
879
880
881
882
883
884
885
886void QJSValue::setPrototype(
const QJSValue& prototype)
888 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
892 ScopedObject o(scope, QJSValuePrivate::asReturnedValue(
this));
895 QV4::Value val = QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(&prototype));
897 o->setPrototypeOf(
nullptr);
901 ScopedObject p(scope, val);
904 if (o->engine() != p->engine()) {
905 qWarning(
"QJSValue::setPrototype() failed: cannot set a prototype created in a different engine");
908 if (!o->setPrototypeOf(p))
909 qWarning(
"QJSValue::setPrototype() failed: cyclic prototype value");
913
914
915
916
917
918
919QJSValue& QJSValue::operator=(
const QJSValue& other)
924 QJSValuePrivate::free(
this);
927 if (
const QString *string = QJSValuePrivate::asQString(&other))
928 QJSValuePrivate::setString(
this, *string);
931 QJSValuePrivate::setValue(
933 QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(&other)));
938QJSValue::QJSValue(QJSPrimitiveValue &&value)
940 switch (value.type()) {
941 case QJSPrimitiveValue::Undefined:
942 d = QJSValuePrivate::encodeUndefined();
944 case QJSPrimitiveValue::Null:
945 d = QJSValuePrivate::encodeNull();
947 case QJSPrimitiveValue::Boolean:
948 d = QJSValuePrivate::encode(value.asBoolean());
950 case QJSPrimitiveValue::Integer:
951 d = QJSValuePrivate::encode(value.asInteger());
953 case QJSPrimitiveValue::Double:
954 d = QJSValuePrivate::encode(value.asDouble());
956 case QJSPrimitiveValue::String:
957 d = QJSValuePrivate::encode(value.asString());
964QJSValue::QJSValue(QJSManagedValue &&value)
967 d = QV4::Encode::undefined();
968 }
else if (value.d->isManaged()) {
970 QJSValuePrivate::adoptPersistentValue(
this, value.d);
973 d = QJSValuePrivate::encode(*value.d);
974 QV4::PersistentValueStorage::free(value.d);
979static bool js_equal(
const QString &string,
const QV4::Value &value)
981 if (String *s = value.stringValue())
982 return string == s->toQString();
983 if (value.isNumber())
984 return RuntimeHelpers::stringToNumber(string) == value.asDouble();
985 if (value.isBoolean())
986 return RuntimeHelpers::stringToNumber(string) ==
double(value.booleanValue());
987 if (QV4::Object *o = value.objectValue()) {
988 Scope scope(o->engine());
989 ScopedValue p(scope, RuntimeHelpers::toPrimitive(value, PREFERREDTYPE_HINT));
990 return js_equal(string, p);
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019bool QJSValue::equals(
const QJSValue& other)
const
1023 if (
const QString *string = QJSValuePrivate::asQString(
this)) {
1024 if (
const QString *otherString = QJSValuePrivate::asQString(&other))
1025 return *string == *otherString;
1026 return js_equal(*string, Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(&other)));
1029 if (
const QString *otherString = QJSValuePrivate::asQString(&other))
1030 return js_equal(*otherString, Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(
this)));
1032 return Runtime::CompareEqual::call(Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(
this)),
1033 Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(&other)));
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058bool QJSValue::strictlyEquals(
const QJSValue& other)
const
1060 if (
const QString *string = QJSValuePrivate::asQString(
this)) {
1061 if (
const QString *otherString = QJSValuePrivate::asQString(&other))
1062 return *string == *otherString;
1063 if (
const String *s = QJSValuePrivate::asManagedType<String>(&other))
1064 return *string == s->toQString();
1068 if (
const QString *otherString = QJSValuePrivate::asQString(&other)) {
1069 if (
const String *s = QJSValuePrivate::asManagedType<String>(
this))
1070 return *otherString == s->toQString();
1076 return RuntimeHelpers::strictEqual(Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(
this)),
1077 Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(&other)));
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097QJSValue QJSValue::property(
const QString& name)
const
1099 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1103 QV4::Scope scope(engine);
1104 ScopedObject o(scope, QJSValuePrivate::asReturnedValue(
this));
1108 ScopedString s(scope, engine->newString(name));
1109 QV4::ScopedValue result(scope, o->get(s->toPropertyKey()));
1110 if (engine->hasException)
1111 result = engine->catchException();
1113 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145QJSValue QJSValue::property(quint32 arrayIndex)
const
1147 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1151 QV4::Scope scope(engine);
1152 ScopedObject o(scope, QJSValuePrivate::asReturnedValue(
this));
1156 QV4::ScopedValue result(scope, arrayIndex == UINT_MAX ? o->get(engine->id_uintMax()) : o->get(arrayIndex));
1157 if (engine->hasException)
1158 engine->catchException();
1159 return QJSValuePrivate::fromReturnedValue(result->asReturnedValue());
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177void QJSValue::setProperty(
const QString& name,
const QJSValue& value)
1179 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1182 Scope scope(engine);
1184 ScopedObject o(scope, QJSValuePrivate::asReturnedValue(
this));
1188 if (!QJSValuePrivate::checkEngine(engine, value)) {
1189 qWarning(
"QJSValue::setProperty(%s) failed: cannot set value created in a different engine", name.toUtf8().constData());
1193 ScopedString s(scope, engine->newString(name));
1194 QV4::ScopedValue v(scope, QJSValuePrivate::convertToReturnedValue(engine, value));
1195 o->put(s->toPropertyKey(), v);
1196 if (engine->hasException)
1197 engine->catchException();
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231void QJSValue::setProperty(quint32 arrayIndex,
const QJSValue& value)
1233 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1236 Scope scope(engine);
1238 ScopedObject o(scope, QJSValuePrivate::asReturnedValue(
this));
1242 if (!QJSValuePrivate::checkEngine(engine, value)) {
1243 qWarning(
"QJSValue::setProperty(%d) failed: cannot set value created in a different engine", arrayIndex);
1247 QV4::ScopedValue v(scope, QJSValuePrivate::convertToReturnedValue(engine, value));
1248 PropertyKey id = arrayIndex != UINT_MAX ? PropertyKey::fromArrayIndex(arrayIndex) : engine->id_uintMax()->propertyKey();
1250 if (engine->hasException)
1251 engine->catchException();
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274bool QJSValue::deleteProperty(
const QString &name)
1276 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1280 Scope scope(engine);
1281 ScopedObject o(scope, QJSValuePrivate::asReturnedValue(
this));
1285 ScopedString s(scope, engine->newString(name));
1286 return o->deleteProperty(s->toPropertyKey());
1290
1291
1292
1293
1294
1295bool QJSValue::hasProperty(
const QString &name)
const
1297 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1301 Scope scope(engine);
1302 ScopedObject o(scope, QJSValuePrivate::asReturnedValue(
this));
1306 ScopedString s(scope, engine->newString(name));
1307 return o->hasProperty(s->toPropertyKey());
1311
1312
1313
1314
1315
1316bool QJSValue::hasOwnProperty(
const QString &name)
const
1318 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1322 Scope scope(engine);
1323 ScopedObject o(scope, QJSValuePrivate::asReturnedValue(
this));
1327 ScopedString s(scope, engine->newIdentifier(name));
1328 return o->getOwnProperty(s->propertyKey()) != Attr_Invalid;
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341QObject *QJSValue::toQObject()
const
1343 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1346 QV4::Scope scope(engine);
1347 QV4::Scoped<QV4::QObjectWrapper> wrapper(scope, QJSValuePrivate::asReturnedValue(
this));
1351 return wrapper->object();
1355
1356
1357
1358
1359
1360
1361
1362const QMetaObject *QJSValue::toQMetaObject()
const
1364 QV4::ExecutionEngine *engine = QJSValuePrivate::engine(
this);
1367 QV4::Scope scope(engine);
1368 QV4::Scoped<QV4::QMetaObjectWrapper> wrapper(scope, QJSValuePrivate::asReturnedValue(
this));
1372 return wrapper->metaObject();
1377
1378
1379
1380
1381
1382
1383QDateTime QJSValue::toDateTime()
const
1385 if (
const QV4::DateObject *date = QJSValuePrivate::asManagedType<DateObject>(
this))
1386 return date->toQDateTime();
1391
1392
1393
1394bool QJSValue::isDate()
const
1396 return QJSValuePrivate::asManagedType<DateObject>(
this);
1400
1401
1402
1403bool QJSValue::isRegExp()
const
1405 return QJSValuePrivate::asManagedType<RegExpObject>(
this);
1409
1410
1411
1412
1413
1414
1415
1416
1417bool QJSValue::isQObject()
const
1419 return QJSValuePrivate::asManagedType<QV4::QObjectWrapper>(
this);
1423
1424
1425
1426
1427
1428
1429
1430bool QJSValue::isQMetaObject()
const
1432 return QJSValuePrivate::asManagedType<QV4::QMetaObjectWrapper>(
this);
1435#ifndef QT_NO_DATASTREAM
1438 quint32 isNullOrUndefined = 0;
1440 isNullOrUndefined |= 0x1;
1441 if (jsv.isUndefined())
1442 isNullOrUndefined |= 0x2;
1443 stream << isNullOrUndefined;
1444 if (!isNullOrUndefined) {
1445 const QVariant v = jsv.toVariant();
1446 switch (v.userType()) {
1447 case QMetaType::Bool:
1448 case QMetaType::Double:
1449 case QMetaType::Int:
1450 case QMetaType::QString:
1454 qWarning() <<
"QDataStream::operator<< was to save a non-trivial QJSValue."
1455 <<
"This is not supported anymore, please stream a QVariant instead.";
1456 QVariant().save(stream);
1466 quint32 isNullOrUndefined;
1467 stream >> isNullOrUndefined;
1469 if (isNullOrUndefined & 0x1) {
1470 jsv = QJSValue(QJSValue::NullValue);
1471 }
else if (isNullOrUndefined & 0x2) {
1477 switch (v.userType()) {
1478 case QMetaType::Bool:
1479 jsv = QJSValue(v.toBool());
1481 case QMetaType::Double:
1482 jsv = QJSValue(v.toDouble());
1484 case QMetaType::Int:
1485 jsv = QJSValue(v.toInt());
1487 case QMetaType::QString:
1488 jsv = QJSValue(v.toString());
1491 qWarning() <<
"QDataStream::operator>> to restore a non-trivial QJSValue."
1492 <<
"This is not supported anymore, please stream a QVariant instead.";
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)