History

Continued tightening and testing of the scripting engine "glue" logic - QObject wrappers will now be reused when asked to wrap the same QObject multiple times - improved error reporting when we can't form a native call from script - dropped support for having the existing QtScript logic handle Qt object transformations - assuming that our code will handle all calls into native objects - changing timer functions to use CTimer* publicly rather than casted QObject*

Heather Anderson committed 4 years ago

Commit 55b5a2c1 parent 742fa2211 files · +262 −382Browse files

Showing the changes to libraries/script-engine/src/qtscript/ScriptEngineQtScript_cast.cpp (1 of 11 files). Show all

Unified · Split

libraries/script-engine/src/qtscript/ScriptEngineQtScript_cast.cpp+92−183
@@ -16,64 +16,16 @@ · 15 unmodified lines
1616 #include <QtCore/QJsonValue>
1717 #include <QtScript/QScriptEngine>
1818
19+#include "../ScriptEngineCast.h"
1920 #include "../ScriptValueIterator.h"
2021
2122 #include "ScriptObjectQtProxy.h"
2223 #include "ScriptValueQtWrapper.h"
2324
24−template <int i>
25−class CustomTypeInstance {
26−public:
27− static ScriptEngine::MarshalFunction marshalFunc;
28− static ScriptEngine::DemarshalFunction demarshalFunc;
29−
30− static QScriptValue internalMarshalFunc(QScriptEngine* engine, const void* src) {
31− ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(engine);
32− ScriptValue dest = marshalFunc(unwrappedEngine, src);
33− return ScriptValueQtWrapper::fullUnwrap(unwrappedEngine, dest);
34− }
35−
36− static void internalDemarshalFunc(const QScriptValue& src, void* dest) {
37− ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(src.engine());
38− ScriptValue wrappedSrc(new ScriptValueQtWrapper(unwrappedEngine, src));
39− demarshalFunc(wrappedSrc, dest);
40− }
41−};
42−template <int i>
43−ScriptEngine::MarshalFunction CustomTypeInstance<i>::marshalFunc;
44−template <int i>
45−ScriptEngine::DemarshalFunction CustomTypeInstance<i>::demarshalFunc;
46−
47−// I would *LOVE* it if there was a different way to do this, jeez!
48−// Qt requires two functions that have no parameters that give any context,
49−// one of the must return a QScriptValue (so we can't void* them into generics and stick them in the templates).
50−// This *has* to be done via templates but the whole point of this is to avoid leaking types into the rest of
51−// the system that would require anyone other than us to have a dependency on QtScript
52−#define CUSTOM_TYPE_ENTRY(idx) \
53− case idx: \
54− CustomTypeInstance<idx>::marshalFunc = marshalFunc; \
55− CustomTypeInstance<idx>::demarshalFunc = demarshalFunc; \
56− internalMarshalFunc = CustomTypeInstance<idx>::internalMarshalFunc; \
57− internalDemarshalFunc = CustomTypeInstance<idx>::internalDemarshalFunc; \
58− break;
59−#define CUSTOM_TYPE_ENTRY_10(idx) \
60− CUSTOM_TYPE_ENTRY((idx * 10)); \
61− CUSTOM_TYPE_ENTRY((idx * 10) + 1); \
62− CUSTOM_TYPE_ENTRY((idx * 10) + 2); \
63− CUSTOM_TYPE_ENTRY((idx * 10) + 3); \
64− CUSTOM_TYPE_ENTRY((idx * 10) + 4); \
65− CUSTOM_TYPE_ENTRY((idx * 10) + 5); \
66− CUSTOM_TYPE_ENTRY((idx * 10) + 6); \
67− CUSTOM_TYPE_ENTRY((idx * 10) + 7); \
68− CUSTOM_TYPE_ENTRY((idx * 10) + 8); \
69− CUSTOM_TYPE_ENTRY((idx * 10) + 9);
70−
7125 void ScriptEngineQtScript::setDefaultPrototype(int metaTypeId, const ScriptValue& prototype) {
7226 ScriptValueQtWrapper* unwrappedPrototype = ScriptValueQtWrapper::unwrap(prototype);
7327 if (unwrappedPrototype) {
7428 const QScriptValue& scriptPrototype = unwrappedPrototype->toQtValue();
75− QScriptEngine::setDefaultPrototype(metaTypeId, scriptPrototype);
76−
7729 QMutexLocker guard(&_customTypeProtect);
7830 _customPrototypes.insert(metaTypeId, scriptPrototype);
7931 }
@@ -83,59 +35,12 @@ void ScriptEngineQtScript::registerCustomType(int type, · 3 unmodified lines
8335 ScriptEngine::MarshalFunction marshalFunc,
8436 ScriptEngine::DemarshalFunction demarshalFunc)
8537 {
86− QScriptEngine::MarshalFunction internalMarshalFunc;
87− QScriptEngine::DemarshalFunction internalDemarshalFunc;
88−
89− {
90− QMutexLocker guard(&_customTypeProtect);
91−
92− // storing it in a map for our own benefit
93− CustomMarshal& customType = _customTypes.insert(type, CustomMarshal()).value();
94− customType.demarshalFunc = demarshalFunc;
95− customType.marshalFunc = marshalFunc;
96−
97− // creating a conversion for QtScript's benefit
98− if (_nextCustomType >= 300) { // have we ran out of translators?
99− Q_ASSERT(false);
100− return;
101− }
102−
103− switch (_nextCustomType++) {
104− CUSTOM_TYPE_ENTRY_10(0);
105− CUSTOM_TYPE_ENTRY_10(1);
106− CUSTOM_TYPE_ENTRY_10(2);
107− CUSTOM_TYPE_ENTRY_10(3);
108− CUSTOM_TYPE_ENTRY_10(4);
109− CUSTOM_TYPE_ENTRY_10(5);
110− CUSTOM_TYPE_ENTRY_10(6);
111− CUSTOM_TYPE_ENTRY_10(7);
112− CUSTOM_TYPE_ENTRY_10(8);
113− CUSTOM_TYPE_ENTRY_10(9);
114− CUSTOM_TYPE_ENTRY_10(10);
115− CUSTOM_TYPE_ENTRY_10(11);
116− CUSTOM_TYPE_ENTRY_10(12);
117− CUSTOM_TYPE_ENTRY_10(13);
118− CUSTOM_TYPE_ENTRY_10(14);
119− CUSTOM_TYPE_ENTRY_10(15);
120− CUSTOM_TYPE_ENTRY_10(16);
121− CUSTOM_TYPE_ENTRY_10(17);
122− CUSTOM_TYPE_ENTRY_10(18);
123− CUSTOM_TYPE_ENTRY_10(19);
124− CUSTOM_TYPE_ENTRY_10(20);
125− CUSTOM_TYPE_ENTRY_10(21);
126− CUSTOM_TYPE_ENTRY_10(22);
127− CUSTOM_TYPE_ENTRY_10(23);
128− CUSTOM_TYPE_ENTRY_10(24);
129− CUSTOM_TYPE_ENTRY_10(25);
130− CUSTOM_TYPE_ENTRY_10(26);
131− CUSTOM_TYPE_ENTRY_10(27);
132− CUSTOM_TYPE_ENTRY_10(28);
133− CUSTOM_TYPE_ENTRY_10(29);
134− CUSTOM_TYPE_ENTRY_10(30);
135− }
136− }
38+ QMutexLocker guard(&_customTypeProtect);
13739
138− qScriptRegisterMetaType_helper(this, type, internalMarshalFunc, internalDemarshalFunc, QScriptValue());
40+ // storing it in a map for our own benefit
41+ CustomMarshal& customType = _customTypes.insert(type, CustomMarshal()).value();
42+ customType.demarshalFunc = demarshalFunc;
43+ customType.marshalFunc = marshalFunc;
13944 }
14045
14146 Q_DECLARE_METATYPE(ScriptValue);
@@ -149,8 +54,7 @@ static void ScriptValueFromQScriptValue(const QScriptValue& src, ScriptValue& de · 7 unmodified lines
14954 dest = ScriptValue(new ScriptValueQtWrapper(engine, src));
15055 }
15156
152−static ScriptValue StringListToScriptValue(ScriptEngine* engine, const void* pSrc) {
153− const QStringList& src = *reinterpret_cast<const QStringList*>(pSrc);
57+static ScriptValue StringListToScriptValue(ScriptEngine* engine, const QStringList& src) {
15458 int len = src.length();
15559 ScriptValue dest = engine->newArray(len);
15660 for (int idx = 0; idx < len; ++idx) {
@@ -159,9 +63,8 @@ static ScriptValue StringListToScriptValue(ScriptEngine* engine, const void* pSr · 2 unmodified lines
15963 return dest;
16064 }
16165
162−static bool StringListFromScriptValue(const ScriptValue& src, void* pDest) {
66+static bool StringListFromScriptValue(const ScriptValue& src, QStringList& dest) {
16367 if(!src.isArray()) return false;
164− QStringList& dest = *reinterpret_cast<QStringList*>(pDest);
16568 int len = src.property("length").toInteger();
16669 dest.clear();
16770 for (int idx = 0; idx < len; ++idx) {
@@ -170,8 +73,7 @@ static bool StringListFromScriptValue(const ScriptValue& src, void* pDest) { · 2 unmodified lines
17073 return true;
17174 }
17275
173−static ScriptValue VariantListToScriptValue(ScriptEngine* engine, const void* pSrc) {
174− const QVariantList& src = *reinterpret_cast<const QVariantList*>(pSrc);
76+static ScriptValue VariantListToScriptValue(ScriptEngine* engine, const QVariantList& src) {
17577 int len = src.length();
17678 ScriptValue dest = engine->newArray(len);
17779 for (int idx = 0; idx < len; ++idx) {
@@ -180,9 +82,8 @@ static ScriptValue VariantListToScriptValue(ScriptEngine* engine, const void* pS · 2 unmodified lines
18082 return dest;
18183 }
18284
183−static bool VariantListFromScriptValue(const ScriptValue& src, void* pDest) {
85+static bool VariantListFromScriptValue(const ScriptValue& src, QVariantList& dest) {
18486 if(!src.isArray()) return false;
185− QVariantList& dest = *reinterpret_cast<QVariantList*>(pDest);
18687 int len = src.property("length").toInteger();
18788 dest.clear();
18889 for (int idx = 0; idx < len; ++idx) {
@@ -191,8 +92,7 @@ static bool VariantListFromScriptValue(const ScriptValue& src, void* pDest) { · 2 unmodified lines
19192 return true;
19293 }
19394
194−static ScriptValue VariantMapToScriptValue(ScriptEngine* engine, const void* pSrc) {
195− const QVariantMap& src = *reinterpret_cast<const QVariantMap*>(pSrc);
95+static ScriptValue VariantMapToScriptValue(ScriptEngine* engine, const QVariantMap& src) {
19696 ScriptValue dest = engine->newObject();
19797 for (QVariantMap::const_iterator iter = src.cbegin(); iter != src.cend(); ++iter) {
19898 dest.setProperty(iter.key(), engine->newVariant(iter.value()));
@@ -200,8 +100,7 @@ static ScriptValue VariantMapToScriptValue(ScriptEngine* engine, const void* pSr · 1 unmodified line
200100 return dest;
201101 }
202102
203−static bool VariantMapFromScriptValue(const ScriptValue& src, void* pDest) {
204− QVariantMap& dest = *reinterpret_cast<QVariantMap*>(pDest);
103+static bool VariantMapFromScriptValue(const ScriptValue& src, QVariantMap& dest) {
205104 dest.clear();
206105 ScriptValueIteratorPointer iter = src.newIterator();
207106 while (iter->hasNext()) {
@@ -211,8 +110,7 @@ static bool VariantMapFromScriptValue(const ScriptValue& src, void* pDest) { · 3 unmodified lines
211110 return true;
212111 }
213112
214−static ScriptValue VariantHashToScriptValue(ScriptEngine* engine, const void* pSrc) {
215− const QVariantHash& src = *reinterpret_cast<const QVariantHash*>(pSrc);
113+static ScriptValue VariantHashToScriptValue(ScriptEngine* engine, const QVariantHash& src) {
216114 ScriptValue dest = engine->newObject();
217115 for (QVariantHash::const_iterator iter = src.cbegin(); iter != src.cend(); ++iter) {
218116 dest.setProperty(iter.key(), engine->newVariant(iter.value()));
@@ -220,8 +118,7 @@ static ScriptValue VariantHashToScriptValue(ScriptEngine* engine, const void* pS · 1 unmodified line
220118 return dest;
221119 }
222120
223−static bool VariantHashFromScriptValue(const ScriptValue& src, void* pDest) {
224− QVariantHash& dest = *reinterpret_cast<QVariantHash*>(pDest);
121+static bool VariantHashFromScriptValue(const ScriptValue& src, QVariantHash& dest) {
225122 dest.clear();
226123 ScriptValueIteratorPointer iter = src.newIterator();
227124 while (iter->hasNext()) {
@@ -231,19 +128,16 @@ static bool VariantHashFromScriptValue(const ScriptValue& src, void* pDest) { · 3 unmodified lines
231128 return true;
232129 }
233130
234−static ScriptValue JsonValueToScriptValue(ScriptEngine* engine, const void* pSrc) {
235− const QJsonValue& src = *reinterpret_cast<const QJsonValue*>(pSrc);
131+static ScriptValue JsonValueToScriptValue(ScriptEngine* engine, const QJsonValue& src) {
236132 return engine->newVariant(src.toVariant());
237133 }
238134
239−static bool JsonValueFromScriptValue(const ScriptValue& src, void* pDest) {
240− QJsonValue& dest = *reinterpret_cast<QJsonValue*>(pDest);
135+static bool JsonValueFromScriptValue(const ScriptValue& src, QJsonValue& dest) {
241136 dest = QJsonValue::fromVariant(src.toVariant());
242137 return true;
243138 }
244139
245−static ScriptValue JsonObjectToScriptValue(ScriptEngine* engine, const void* pSrc) {
246− const QJsonObject& src = *reinterpret_cast<const QJsonObject*>(pSrc);
140+static ScriptValue JsonObjectToScriptValue(ScriptEngine* engine, const QJsonObject& src) {
247141 QVariantMap map = src.toVariantMap();
248142 ScriptValue dest = engine->newObject();
249143 for (QVariantMap::const_iterator iter = map.cbegin(); iter != map.cend(); ++iter) {
@@ -252,8 +146,7 @@ static ScriptValue JsonObjectToScriptValue(ScriptEngine* engine, const void* pSr · 2 unmodified lines
252146 return dest;
253147 }
254148
255−static bool JsonObjectFromScriptValue(const ScriptValue& src, void* pDest) {
256− QJsonObject& dest = *reinterpret_cast<QJsonObject*>(pDest);
149+static bool JsonObjectFromScriptValue(const ScriptValue& src, QJsonObject& dest) {
257150 QVariantMap map;
258151 ScriptValueIteratorPointer iter = src.newIterator();
259152 while (iter->hasNext()) {
@@ -264,8 +157,7 @@ static bool JsonObjectFromScriptValue(const ScriptValue& src, void* pDest) { · 4 unmodified lines
264157 return true;
265158 }
266159
267−static ScriptValue JsonArrayToScriptValue(ScriptEngine* engine, const void* pSrc) {
268− const QJsonArray& src = *reinterpret_cast<const QJsonArray*>(pSrc);
160+static ScriptValue JsonArrayToScriptValue(ScriptEngine* engine, const QJsonArray& src) {
269161 QVariantList list = src.toVariantList();
270162 int len = list.length();
271163 ScriptValue dest = engine->newArray(len);
@@ -275,9 +167,8 @@ static ScriptValue JsonArrayToScriptValue(ScriptEngine* engine, const void* pSrc · 3 unmodified lines
275167 return dest;
276168 }
277169
278−static bool JsonArrayFromScriptValue(const ScriptValue& src, void* pDest) {
170+static bool JsonArrayFromScriptValue(const ScriptValue& src, QJsonArray& dest) {
279171 if(!src.isArray()) return false;
280− QJsonArray& dest = *reinterpret_cast<QJsonArray*>(pDest);
281172 QVariantList list;
282173 int len = src.property("length").toInteger();
283174 for (int idx = 0; idx < len; ++idx) {
@@ -292,63 +183,33 @@ static bool JsonArrayFromScriptValue(const ScriptValue& src, void* pDest) { · 8 unmodified lines
292183 void ScriptEngineQtScript::registerSystemTypes() {
293184 qScriptRegisterMetaType(this, ScriptValueToQScriptValue, ScriptValueFromQScriptValue);
294185
295− QMutexLocker guard(&_customTypeProtect);
296−
297− {
298− CustomMarshal& customType = _customTypes.insert(QMetaType::QStringList, CustomMarshal()).value();
299− customType.demarshalFunc = StringListFromScriptValue;
300− customType.marshalFunc = StringListToScriptValue;
301− }
302− {
303− CustomMarshal& customType = _customTypes.insert(QMetaType::QVariantList, CustomMarshal()).value();
304− customType.demarshalFunc = VariantListFromScriptValue;
305− customType.marshalFunc = VariantListToScriptValue;
306− }
307− {
308− CustomMarshal& customType = _customTypes.insert(QMetaType::QVariantMap, CustomMarshal()).value();
309− customType.demarshalFunc = VariantMapFromScriptValue;
310− customType.marshalFunc = VariantMapToScriptValue;
311− }
312− {
313− CustomMarshal& customType = _customTypes.insert(QMetaType::QVariantHash, CustomMarshal()).value();
314− customType.demarshalFunc = VariantHashFromScriptValue;
315− customType.marshalFunc = VariantHashToScriptValue;
316− }
317− {
318− CustomMarshal& customType = _customTypes.insert(QMetaType::QJsonValue, CustomMarshal()).value();
319− customType.demarshalFunc = JsonValueFromScriptValue;
320− customType.marshalFunc = JsonValueToScriptValue;
321− }
322− {
323− CustomMarshal& customType = _customTypes.insert(QMetaType::QJsonObject, CustomMarshal()).value();
324− customType.demarshalFunc = JsonObjectFromScriptValue;
325− customType.marshalFunc = JsonObjectToScriptValue;
326− }
327− {
328− CustomMarshal& customType = _customTypes.insert(QMetaType::QJsonArray, CustomMarshal()).value();
329− customType.demarshalFunc = JsonArrayFromScriptValue;
330− customType.marshalFunc = JsonArrayToScriptValue;
331− }
186+ scriptRegisterMetaType(this, StringListToScriptValue, StringListFromScriptValue);
187+ scriptRegisterMetaType(this, VariantListToScriptValue, VariantListFromScriptValue);
188+ scriptRegisterMetaType(this, VariantMapToScriptValue, VariantMapFromScriptValue);
189+ scriptRegisterMetaType(this, VariantHashToScriptValue, VariantHashFromScriptValue);
190+ scriptRegisterMetaType(this, JsonValueToScriptValue, JsonValueFromScriptValue);
191+ scriptRegisterMetaType(this, JsonObjectToScriptValue, JsonObjectFromScriptValue);
192+ scriptRegisterMetaType(this, JsonArrayToScriptValue, JsonArrayFromScriptValue);
332193 }
333194
334−bool ScriptEngineQtScript::castValueToVariant(const QScriptValue& val, QVariant& dest, int destType) {
195+bool ScriptEngineQtScript::castValueToVariant(const QScriptValue& val, QVariant& dest, int destTypeId) {
335196
336197 // if we're not particularly interested in a specific type, try to detect if we're dealing with a registered type
337− if (destType == QMetaType::UnknownType) {
198+ if (destTypeId == QMetaType::UnknownType) {
338199 QObject* obj = ScriptObjectQtProxy::unwrap(val);
339200 if (obj) {
340201 for (const QMetaObject* metaObject = obj->metaObject(); metaObject; metaObject = metaObject->superClass()) {
341202 QByteArray typeName = QByteArray(metaObject->className()) + "*";
342203 int typeId = QMetaType::type(typeName.constData());
343204 if (typeId != QMetaType::UnknownType) {
344− destType = typeId;
205+ destTypeId = typeId;
345206 break;
346207 }
347208 }
348209 }
349210 }
350211
351− if (destType == qMetaTypeId<ScriptValue>()) {
212+ if (destTypeId == qMetaTypeId<ScriptValue>()) {
352213 dest = QVariant::fromValue(ScriptValue(new ScriptValueQtWrapper(this, val)));
353214 return true;
354215 }
@@ -357,20 +218,19 @@ bool ScriptEngineQtScript::castValueToVariant(const QScriptValue& val, QVariant& · 2 unmodified lines
357218 ScriptEngine::DemarshalFunction demarshalFunc = nullptr;
358219 {
359220 QMutexLocker guard(&_customTypeProtect);
360− CustomMarshalMap::const_iterator lookup = _customTypes.find(destType);
221+ CustomMarshalMap::const_iterator lookup = _customTypes.find(destTypeId);
361222 if (lookup != _customTypes.cend()) {
362223 demarshalFunc = lookup.value().demarshalFunc;
363224 }
364225 }
365226 if (demarshalFunc) {
366− void* destStorage = QMetaType::create(destType);
227+ dest = QVariant(destTypeId, static_cast<void*>(NULL));
367228 ScriptValue wrappedVal(new ScriptValueQtWrapper(this, val));
368− bool success = demarshalFunc(wrappedVal, destStorage);
369− dest = success ? QVariant(destType, destStorage) : QVariant();
370− QMetaType::destroy(destType, destStorage);
229+ bool success = demarshalFunc(wrappedVal, const_cast<void*>(dest.constData()));
230+ if(!success) dest = QVariant();
371231 return success;
372232 } else {
373− switch (destType) {
233+ switch (destTypeId) {
374234 case QMetaType::UnknownType:
375235 if (val.isUndefined()) {
376236 dest = QVariant();
@@ -443,8 +303,19 @@ bool ScriptEngineQtScript::castValueToVariant(const QScriptValue& val, QVariant& · 66 unmodified lines
443303 break;
444304 default:
445305 // check to see if this is a pointer to a QObject-derived object
446− if (QMetaType::typeFlags(destType) & QMetaType::PointerToQObject) {
447− dest = QVariant::fromValue(ScriptObjectQtProxy::unwrap(val));
306+ if (QMetaType::typeFlags(destTypeId) & (QMetaType::PointerToQObject | QMetaType::TrackingPointerToQObject)) {
307+ /* Do we really want to permit regular passing of nullptr to native functions?
308+ if (!val.isValid() || val.isUndefined() || val.isNull()) {
309+ dest = QVariant::fromValue(nullptr);
310+ break;
311+ }*/
312+ QObject* obj = ScriptObjectQtProxy::unwrap(val);
313+ if (!obj) return false;
314+ const QMetaObject* destMeta = QMetaType::metaObjectForType(destTypeId);
315+ Q_ASSERT(destMeta);
316+ obj = destMeta->cast(obj);
317+ if (!obj) return false;
318+ dest = QVariant::fromValue(obj);
448319 break;
449320 }
450321 // check to see if we have a registered prototype
@@ -461,7 +332,40 @@ bool ScriptEngineQtScript::castValueToVariant(const QScriptValue& val, QVariant& · 10 unmodified lines
461332 }
462333 }
463334
464− return destType == QMetaType::UnknownType || dest.userType() == destType || dest.convert(destType);
335+ return destTypeId == QMetaType::UnknownType || dest.userType() == destTypeId || dest.convert(destTypeId);
336+}
337+
338+QString ScriptEngineQtScript::valueType(const QScriptValue& val) {
339+ if (val.isUndefined()) {
340+ return "undefined";
341+ }
342+ if (val.isNull()) {
343+ return "null";
344+ }
345+ if (val.isBool()) {
346+ return "boolean";
347+ }
348+ if (val.isString()) {
349+ return "string";
350+ }
351+ if (val.isNumber()) {
352+ return "number";
353+ }
354+ {
355+ QObject* obj = ScriptObjectQtProxy::unwrap(val);
356+ if (obj) {
357+ QString objectName = obj->objectName();
358+ if (!objectName.isEmpty()) return objectName;
359+ return obj->metaObject()->className();
360+ }
361+ }
362+ {
363+ QVariant var = ScriptVariantQtProxy::unwrap(val);
364+ if (var.isValid()) {
365+ return var.typeName();
366+ }
367+ }
368+ return val.toVariant().typeName();
465369 }
466370
467371 QScriptValue ScriptEngineQtScript::castVariantToValue(const QVariant& val) {
@@ -513,16 +417,21 @@ QScriptValue ScriptEngineQtScript::castVariantToValue(const QVariant& val) { · 45 unmodified lines
513417 return QScriptValue(this, val.toString());
514418 case QMetaType::QVariant:
515419 return castVariantToValue(val.value<QVariant>());
516− case QMetaType::QObjectStar:
517− return ScriptObjectQtProxy::newQObject(this, val.value<QObject*>(), ScriptEngine::QtOwnership);
420+ case QMetaType::QObjectStar: {
421+ QObject* obj = val.value<QObject*>();
422+ if (obj == nullptr) return QScriptValue(this, QScriptValue::NullValue);
423+ return ScriptObjectQtProxy::newQObject(this, obj);
424+ }
518425 case QMetaType::QDateTime:
519426 return static_cast<QScriptEngine*>(this)->newDate(val.value<QDateTime>());
520427 case QMetaType::QDate:
521428 return static_cast<QScriptEngine*>(this)->newDate(val.value<QDate>().startOfDay());
522429 default:
523430 // check to see if this is a pointer to a QObject-derived object
524− if (QMetaType::typeFlags(valTypeId) & QMetaType::PointerToQObject) {
525− return ScriptObjectQtProxy::newQObject(this, val.value<QObject*>(), ScriptEngine::QtOwnership);
431+ if (QMetaType::typeFlags(valTypeId) & (QMetaType::PointerToQObject | QMetaType::TrackingPointerToQObject)) {
432+ QObject* obj = val.value<QObject*>();
433+ if (obj == nullptr) return QScriptValue(this, QScriptValue::NullValue);
434+ return ScriptObjectQtProxy::newQObject(this, obj);
526435 }
527436 // have we set a prototype'd variant?
528437 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t