diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-04 16:46:42 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-18 16:35:02 +0100 |
commit | 748411fa64412db1650e04ee7b4405b8fbc53d42 (patch) | |
tree | a3c94175c04a8465cb602d4d4deb557a37c1923d /src/particles | |
parent | 7230005ef66f22a7ee3addff95b1e8d9060dc5a1 (diff) |
Store a QV4::ReturnedValue in QJSValue
Being careful, we can now save primitive values inline. We use the heap
pointer of QV4::Value as either QString* or QV4::Value* for complex
types. We cannot store persistent managed QV4::Value without the double
indirection as those need to be allocated in a special place.
The generic QVariant case is not supported anymore. The only place where
it was actually needed were the stream operators for QJSValue. Those
were fundamentally broken:
* A managed QJSValue saved and loaded from a stream was converted to a
QVariant-type QJSValue
* QVariant-type QJSValues were not callable, could not be objects or
arrays, or any of the special types.
* Cyclic references were forcibly broken when saving to a data stream.
In general the support for saving and loading of managed types to/from
a data stream was so abysmally bad that we don't lose much by dropping
it.
[ChangeLog][QML][Important Behavior Changes] When saving a QJSValue to a
QDataStream only primitive values or strings will be retained. Support
for objects and arrays was incomplete and unreliable already before. It
cannot work correctly as we don't necessarily have a JavaScript heap
when loading a QJSValue from a stream. Therefore, we don't have a proper
place to keep any managed values. Using QVariant to keep them instead is
a bad idea because QVariant cannot represent everything a QJSValue can
contain.
Fixes: QTBUG-75174
Change-Id: I75697670639bca8d4b1668763d7020c4cf871bda
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/particles')
-rw-r--r-- | src/particles/qquickcustomaffector.cpp | 2 | ||||
-rw-r--r-- | src/particles/qquickparticleemitter.cpp | 2 | ||||
-rw-r--r-- | src/particles/qquicktrailemitter.cpp | 11 |
3 files changed, 9 insertions, 6 deletions
diff --git a/src/particles/qquickcustomaffector.cpp b/src/particles/qquickcustomaffector.cpp index aa2617e64c..67f2922423 100644 --- a/src/particles/qquickcustomaffector.cpp +++ b/src/particles/qquickcustomaffector.cpp @@ -157,7 +157,7 @@ void QQuickCustomAffector::affectSystem(qreal dt) const auto doAffect = [&](qreal dt) { affectProperties(toAffect, dt); QJSValue particles; - QJSValuePrivate::setValue(&particles, v4, array); + QJSValuePrivate::setValue(&particles, array); emit affectParticles(particles, dt); }; diff --git a/src/particles/qquickparticleemitter.cpp b/src/particles/qquickparticleemitter.cpp index 3e9d7c02a9..62bf83994f 100644 --- a/src/particles/qquickparticleemitter.cpp +++ b/src/particles/qquickparticleemitter.cpp @@ -497,7 +497,7 @@ void QQuickParticleEmitter::emitWindow(int timeStamp) array->put(i, (v = toEmit[i]->v4Value(m_system))); QJSValue particles; - QJSValuePrivate::setValue(&particles, v4, array); + QJSValuePrivate::setValue(&particles, array); emit emitParticles(particles);//A chance for arbitrary JS changes } diff --git a/src/particles/qquicktrailemitter.cpp b/src/particles/qquicktrailemitter.cpp index 5720460bae..05afdf9d1f 100644 --- a/src/particles/qquicktrailemitter.cpp +++ b/src/particles/qquicktrailemitter.cpp @@ -278,11 +278,14 @@ void QQuickTrailEmitter::emitWindow(int timeStamp) array->put(i, (v = toEmit[i]->v4Value(m_system))); QJSValue particles; - QJSValuePrivate::setValue(&particles, v4, array); - if (isEmitFollowConnected()) - emit emitFollowParticles(particles, QJSValue(v4, d->v4Value(m_system)));//A chance for many arbitrary JS changes - else if (isEmitConnected()) + QJSValuePrivate::setValue(&particles, array); + if (isEmitFollowConnected()) { + //A chance for many arbitrary JS changes + emit emitFollowParticles( + particles, QJSValuePrivate::fromReturnedValue(d->v4Value(m_system))); + } else if (isEmitConnected()) { emit emitParticles(particles);//A chance for arbitrary JS changes + } } m_lastEmission[d->index] = pt; } |