Convert putIndexed()
authorLars Knoll <lars.knoll@digia.com>
Thu, 19 Sep 2013 07:10:42 +0000 (09:10 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 21 Sep 2013 23:06:20 +0000 (01:06 +0200)
Change-Id: I7d02b0fdf45079d0f7afcfb6d3158dd60cb09f33
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
17 files changed:
src/particles/qquickcustomaffector.cpp
src/particles/qquickparticleemitter.cpp
src/particles/qquicktrailemitter.cpp
src/qml/jsruntime/qv4global_p.h
src/qml/jsruntime/qv4managed.cpp
src/qml/jsruntime/qv4managed_p.h
src/qml/jsruntime/qv4object.cpp
src/qml/jsruntime/qv4object_p.h
src/qml/jsruntime/qv4regexp.cpp
src/qml/jsruntime/qv4regexp_p.h
src/qml/jsruntime/qv4runtime.cpp
src/qml/jsruntime/qv4sequenceobject.cpp
src/qml/jsruntime/qv4string.cpp
src/qml/jsruntime/qv4string_p.h
src/qml/qml/qqmlvmemetaobject.cpp
src/qml/qml/v8/qqmlbuiltinfunctions.cpp
src/quick/items/context2d/qquickcontext2d.cpp

index 09f8967..583e3b6 100644 (file)
@@ -148,8 +148,9 @@ void QQuickCustomAffector::affectSystem(qreal dt)
 
     QV4::Scope scope(v4);
     QV4::Scoped<QV4::ArrayObject> array(scope, v4->newArrayObject(toAffect.size()));
+    QV4::ScopedValue v(scope);
     for (int i=0; i<toAffect.size(); i++)
-        array->putIndexed(i, toAffect[i]->v4Value().toValue());
+        array->putIndexed(i, (v = toAffect[i]->v4Value().toValue()));
 
     if (dt >= simulationCutoff || dt <= simulationDelta) {
         affectProperties(toAffect, dt);
index 404554c..d42c923 100644 (file)
@@ -486,8 +486,9 @@ void QQuickParticleEmitter::emitWindow(int timeStamp)
         //Done after emitParticle so that the Painter::load is done first, this allows you to customize its static variables
         //We then don't need to request another reload, because the first reload isn't scheduled until we get back to the render thread
         QV4::Scoped<QV4::ArrayObject> array(scope, v4->newArrayObject(toEmit.size()));
+        QV4::ScopedValue v(scope);
         for (int i=0; i<toEmit.size(); i++)
-            array->putIndexed(i, toEmit[i]->v4Value().toValue());
+            array->putIndexed(i, (v = toEmit[i]->v4Value().toValue()));
 
         emitParticles(QQmlV4Handle(array.asValue()));//A chance for arbitrary JS changes
     }
index 84caebf..b78745f 100644 (file)
@@ -274,8 +274,9 @@ void QQuickTrailEmitter::emitWindow(int timeStamp)
 
             QV4::Scope scope(v4);
             QV4::Scoped<QV4::ArrayObject> array(scope, v4->newArrayObject(toEmit.size()));
+            QV4::ScopedValue v(scope);
             for (int i=0; i<toEmit.size(); i++)
-                array->putIndexed(i, toEmit[i]->v4Value().toValue());
+                array->putIndexed(i, (v = toEmit[i]->v4Value().toValue()));
 
             if (isEmitFollowConnected())
                 emitFollowParticles(QQmlV4Handle(array.asValue()), d->v4Value());//A chance for many arbitrary JS changes
index 9f963f3..f0a5e30 100644 (file)
@@ -111,12 +111,14 @@ struct ValueRef;
 template<typename T> struct Scoped;
 typedef Scoped<String> ScopedString;
 typedef Scoped<Object> ScopedObject;
+typedef Scoped<ArrayObject> ScopedArrayObject;
 typedef Scoped<FunctionObject> ScopedFunctionObject;
 template<typename T> struct Returned;
 typedef Returned<String> ReturnedString;
 typedef Returned<Object> ReturnedObject;
 typedef Returned<FunctionObject> ReturnedFunctionObject;
 template<typename T> struct Referenced;
+typedef Referenced<Managed> ManagedRef;
 typedef Referenced<String> StringRef;
 typedef Referenced<Object> ObjectRef;
 typedef Referenced<FunctionObject> FunctionObjectRef;
index c469293..7b0d405 100644 (file)
@@ -221,3 +221,8 @@ void Managed::setLookup(Lookup *l, const ValueRef v)
 {
     vtbl->setLookup(this, l, v);
 }
+
+void Managed::putIndexed(uint index, const ValueRef value)
+{
+    vtbl->putIndexed(this, index, value);
+}
index 00ad52a..c91b945 100644 (file)
@@ -100,7 +100,7 @@ struct ManagedVTable
     ReturnedValue (*get)(Managed *, const StringRef name, bool *hasProperty);
     ReturnedValue (*getIndexed)(Managed *, uint index, bool *hasProperty);
     void (*put)(Managed *, const StringRef name, const ValueRef value);
-    void (*putIndexed)(Managed *, uint index, const Value &value);
+    void (*putIndexed)(Managed *, uint index, const ValueRef value);
     PropertyAttributes (*query)(const Managed *, String *name);
     PropertyAttributes (*queryIndexed)(const Managed *, uint index);
     bool (*deleteProperty)(Managed *m, String *name);
@@ -266,8 +266,7 @@ public:
     ReturnedValue get(const StringRef name, bool *hasProperty = 0);
     ReturnedValue getIndexed(uint index, bool *hasProperty = 0);
     void put(const StringRef name, const ValueRef value);
-    void putIndexed(uint index, const Value &value)
-    { vtbl->putIndexed(this, index, value); }
+    void putIndexed(uint index, const ValueRef value);
     PropertyAttributes query(String *name) const
     { return vtbl->query(this, name); }
     PropertyAttributes queryIndexed(uint index) const
index 44c248d..2a36371 100644 (file)
@@ -472,7 +472,7 @@ void Object::put(Managed *m, const StringRef name, const ValueRef value)
     static_cast<Object *>(m)->internalPut(name, value);
 }
 
-void Object::putIndexed(Managed *m, uint index, const Value &value)
+void Object::putIndexed(Managed *m, uint index, const ValueRef value)
 {
     static_cast<Object *>(m)->internalPutIndexed(index, value);
 }
@@ -723,7 +723,7 @@ void Object::internalPut(const StringRef name, const ValueRef value)
 {
     uint idx = name->asArrayIndex();
     if (idx != UINT_MAX)
-        return putIndexed(idx, *value);
+        return putIndexed(idx, value);
 
     name->makeIdentifier();
 
@@ -801,7 +801,7 @@ void Object::internalPut(const StringRef name, const ValueRef value)
     }
 }
 
-void Object::internalPutIndexed(uint index, const Value &value)
+void Object::internalPutIndexed(uint index, const ValueRef value)
 {
     Property *pd = 0;
     PropertyAttributes attrs;
@@ -832,7 +832,7 @@ void Object::internalPutIndexed(uint index, const Value &value)
         } else if (!attrs.isWritable())
             goto reject;
         else
-            pd->value = value;
+            pd->value = *value;
         return;
     } else if (!prototype()) {
         if (!extensible)
@@ -859,13 +859,13 @@ void Object::internalPutIndexed(uint index, const Value &value)
 
         Scope scope(engine());
         ScopedCallData callData(scope, 1);
-        callData->args[0] = value;
+        callData->args[0] = *value;
         callData->thisObject = Value::fromObject(this);
         pd->setter()->call(callData);
         return;
     }
 
-    arraySet(index, value);
+    arraySet(index, *value);
     return;
 
   reject:
index dd75187..99fbd8c 100644 (file)
@@ -294,7 +294,7 @@ public:
     { return vtbl->getIndexed(this, idx, hasProperty); }
     inline void put(const StringRef name, const ValueRef v)
     { vtbl->put(this, name, v); }
-    inline void putIndexed(uint idx, const Value &v)
+    inline void putIndexed(uint idx, const ValueRef v)
     { vtbl->putIndexed(this, idx, v); }
     using Managed::get;
     using Managed::getIndexed;
@@ -313,7 +313,7 @@ protected:
     static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty);
     static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
     static void put(Managed *m, const StringRef name, const ValueRef value);
-    static void putIndexed(Managed *m, uint index, const Value &value);
+    static void putIndexed(Managed *m, uint index, const ValueRef value);
     static PropertyAttributes query(const Managed *m, String *name);
     static PropertyAttributes queryIndexed(const Managed *m, uint index);
     static bool deleteProperty(Managed *m, String *name);
@@ -327,7 +327,7 @@ private:
     ReturnedValue internalGet(const StringRef name, bool *hasProperty);
     ReturnedValue internalGetIndexed(uint index, bool *hasProperty);
     void internalPut(const StringRef name, const ValueRef value);
-    void internalPutIndexed(uint index, const Value &value);
+    void internalPutIndexed(uint index, const ValueRef value);
     bool internalDeleteProperty(String *name);
     bool internalDeleteIndexedProperty(uint index);
 
index 076bd72..ac7b122 100644 (file)
@@ -150,7 +150,7 @@ void RegExp::put(Managed *m, const StringRef name, const ValueRef value)
 {
 }
 
-void RegExp::putIndexed(Managed *m, uint index, const Value &value)
+void RegExp::putIndexed(Managed *m, uint index, const ValueRef value)
 {
 }
 
index 2600cac..cbc60d9 100644 (file)
@@ -114,7 +114,7 @@ protected:
     static ReturnedValue get(Managed *, const StringRef, bool *);
     static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
     static void put(Managed *m, const StringRef name, const ValueRef value);
-    static void putIndexed(Managed *m, uint index, const Value &value);
+    static void putIndexed(Managed *m, uint index, const ValueRef value);
     static PropertyAttributes query(const Managed *m, String *name);
     static PropertyAttributes queryIndexed(const Managed *m, uint index);
     static bool deleteProperty(Managed *, String *);
index 9ecb1bf..63050c7 100644 (file)
@@ -727,7 +727,7 @@ void __qmljs_set_element(ExecutionContext *ctx, const ValueRef object, const Val
                 return;
             }
         }
-        o->putIndexed(idx, *value);
+        o->putIndexed(idx, value);
         return;
     }
 
index 9b414b5..f0a71a8 100644 (file)
@@ -134,31 +134,31 @@ static QString convertElementToString(bool element)
         return QStringLiteral("false");
 }
 
-template <typename ElementType> ElementType convertValueToElement(const QV4::Value &value);
+template <typename ElementType> ElementType convertValueToElement(const QV4::ValueRef value);
 
-template <> QString convertValueToElement(const QV4::Value &value)
+template <> QString convertValueToElement(const QV4::ValueRef value)
 {
-    return value.toQStringNoThrow();
+    return value->toQString();
 }
 
-template <> int convertValueToElement(const QV4::Value &value)
+template <> int convertValueToElement(const QV4::ValueRef value)
 {
-    return value.toInt32();
+    return value->toInt32();
 }
 
-template <> QUrl convertValueToElement(const QV4::Value &value)
+template <> QUrl convertValueToElement(const QV4::ValueRef value)
 {
-    return QUrl(value.toQStringNoThrow());
+    return QUrl(value->toQString());
 }
 
-template <> qreal convertValueToElement(const QV4::Value &value)
+template <> qreal convertValueToElement(const QV4::ValueRef value)
 {
-    return value.toNumber();
+    return value->toNumber();
 }
 
-template <> bool convertValueToElement(const QV4::Value &value)
+template <> bool convertValueToElement(const ValueRef value)
 {
-    return value.toBoolean();
+    return value->toBoolean();
 }
 
 template <typename Container>
@@ -223,7 +223,7 @@ public:
         return QV4::Value::undefinedValue();
     }
 
-    void containerPutIndexed(uint index, const QV4::Value &value)
+    void containerPutIndexed(uint index, const QV4::ValueRef value)
     {
         /* Qt containers have int (rather than uint) allowable indexes. */
         if (index > INT_MAX) {
@@ -455,10 +455,12 @@ public:
 
     static QVariant toVariant(QV4::ArrayObject *array)
     {
+        QV4::Scope scope(array->engine());
         Container result;
         quint32 length = array->arrayLength();
+        QV4::ScopedValue v(scope);
         for (quint32 i = 0; i < length; ++i)
-            result << convertValueToElement<typename Container::value_type>(QV4::Value::fromReturnedValue(array->getIndexed(i)));
+            result << convertValueToElement<typename Container::value_type>((v = array->getIndexed(i)));
         return QVariant::fromValue(result);
     }
 
@@ -488,7 +490,7 @@ private:
 
     static QV4::ReturnedValue getIndexed(QV4::Managed *that, uint index, bool *hasProperty)
     { return static_cast<QQmlSequence<Container> *>(that)->containerGetIndexed(index, hasProperty).asReturnedValue(); }
-    static void putIndexed(Managed *that, uint index, const QV4::Value &value)
+    static void putIndexed(Managed *that, uint index, const QV4::ValueRef value)
     { static_cast<QQmlSequence<Container> *>(that)->containerPutIndexed(index, value); }
     static QV4::PropertyAttributes queryIndexed(const QV4::Managed *that, uint index)
     { return static_cast<const QQmlSequence<Container> *>(that)->containerQueryIndexed(index); }
index 73e55a0..cff0d7a 100644 (file)
@@ -181,7 +181,7 @@ void String::put(Managed *m, const StringRef name, const ValueRef value)
     o->put(name, value);
 }
 
-void String::putIndexed(Managed *m, uint index, const Value &value)
+void String::putIndexed(Managed *m, uint index, const ValueRef value)
 {
     Scope scope(m->engine());
     String *that = static_cast<String *>(m);
index 4289725..5cfe0c4 100644 (file)
@@ -130,7 +130,7 @@ protected:
     static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty);
     static ReturnedValue getIndexed(Managed *m, uint index, bool *hasProperty);
     static void put(Managed *m, const StringRef name, const ValueRef value);
-    static void putIndexed(Managed *m, uint index, const Value &value);
+    static void putIndexed(Managed *m, uint index, const ValueRef value);
     static PropertyAttributes query(const Managed *m, String *name);
     static PropertyAttributes queryIndexed(const Managed *m, uint index);
     static bool deleteProperty(Managed *, String *);
index e3a6621..d70df51 100644 (file)
@@ -73,9 +73,13 @@ void QQmlVMEVariantQObjectPtr::objectDestroyed(QObject *)
     if (m_target && m_index >= 0) {
         if (m_isVar && m_target->varPropertiesInitialized && !m_target->varProperties.isUndefined()) {
             // Set the var property to NULL
-            QV4::ArrayObject *a = m_target->varProperties.value().asArrayObject();
-            if (a)
-                a->putIndexed(m_index - m_target->firstVarPropertyIndex, QV4::Value::nullValue());
+            QV4::ExecutionEngine *v4 = m_target->varProperties.engine();
+            if (v4) {
+                QV4::Scope scope(v4);
+                QV4::ScopedArrayObject a(scope, m_target->varProperties.value().asArrayObject());
+                if (a)
+                    a->putIndexed(m_index - m_target->firstVarPropertyIndex, QV4::ScopedValue(scope, QV4::Value::nullValue()));
+            }
         }
 
         m_target->activate(m_target->object, m_target->methodOffset() + m_index, 0);
@@ -1029,7 +1033,9 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value)
     QObject *valueObject = 0;
     QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id);
 
-    if (QV4::Object *o = value.asObject()) {
+    QV4::ScopedValue v(scope, value);
+    QV4::ScopedObject o(scope, v);
+    if (o) {
         // And, if the new value is a scarce resource, we need to ensure that it does not get
         // automatically released by the engine until no other references to it exist.
         if (QV4::VariantObject *v = o->as<QV4::VariantObject>()) {
@@ -1051,7 +1057,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value)
     }
 
     // Write the value and emit change signal as appropriate.
-    varProperties.value().asObject()->putIndexed(id - firstVarPropertyIndex, value);
+    varProperties.value().asObject()->putIndexed(id - firstVarPropertyIndex, v);
     activate(object, methodOffset() + id, 0);
 }
 
index c5cba16..a83b2d7 100644 (file)
@@ -959,7 +959,7 @@ ReturnedValue QtObject::method_createQmlObject(SimpleCallContext *ctx)
                 qmlerror->put((s = v4->newString("columnNumber")), (v = QV4::Value::fromInt32(error.column())));
                 qmlerror->put((s = v4->newString("fileName")), (v = Value::fromString(v4->newString(error.url().toString()))));
                 qmlerror->put((s = v4->newString("message")), (v = Value::fromString(v4->newString(error.description()))));
-                qmlerrors->putIndexed(ii, qmlerror.asValue());
+                qmlerrors->putIndexed(ii, qmlerror);
             }
 
             Scoped<Object> errorObject(scope, v4->newErrorObject(Value::fromString(v4->newString(errorstr))));
index 2e0657d..48456f8 100644 (file)
@@ -874,7 +874,7 @@ struct QQuickJSContext2DPixelData : public QV4::Object
         static_cast<QQuickJSContext2DPixelData *>(that)->~QQuickJSContext2DPixelData();
     }
     static QV4::ReturnedValue getIndexed(QV4::Managed *m, uint index, bool *hasProperty);
-    static void putIndexed(QV4::Managed *m, uint index, const QV4::Value &value);
+    static void putIndexed(QV4::Managed *m, uint index, const QV4::ValueRef value);
 
     static QV4::ReturnedValue proto_get_length(QV4::SimpleCallContext *ctx);
 
@@ -3169,15 +3169,15 @@ QV4::ReturnedValue QQuickJSContext2DPixelData::getIndexed(QV4::Managed *m, uint
     return QV4::Encode::undefined();
 }
 
-void QQuickJSContext2DPixelData::putIndexed(QV4::Managed *m, uint index, const QV4::Value &value)
+void QQuickJSContext2DPixelData::putIndexed(QV4::Managed *m, uint index, const QV4::ValueRef value)
 {
     QV4::ExecutionEngine *v4 = m->engine();
     QV4::Scope scope(v4);
-    QQuickJSContext2DPixelData *r = m->as<QQuickJSContext2DPixelData>();
+    QV4::Scoped<QQuickJSContext2DPixelData> r(scope, m->as<QQuickJSContext2DPixelData>());
     if (!r)
         m->engine()->current->throwTypeError();
 
-    const int v = value.toInt32();
+    const int v = value->toInt32();
     if (r && index < static_cast<quint32>(r->image.width() * r->image.height() * 4) && v >= 0 && v <= 255) {
         const quint32 w = r->image.width();
         const quint32 row = (index / 4) / w;