Remove the remaining uses of Returned<T>
authorSimon Hausmann <simon.hausmann@theqtcompany.com>
Tue, 11 Nov 2014 22:30:54 +0000 (23:30 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 14 Nov 2014 23:32:59 +0000 (00:32 +0100)
Change-Id: I493b75365d3c6fbf6965986d73e7aa0b659ded67
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/jsapi/qjsvalue.cpp
src/qml/jsruntime/qv4arraydata_p.h
src/qml/jsruntime/qv4context.cpp
src/qml/jsruntime/qv4context_p.h
src/qml/jsruntime/qv4global_p.h
src/qml/jsruntime/qv4managed_p.h
src/qml/jsruntime/qv4mm.cpp
src/qml/jsruntime/qv4persistent_p.h
src/qml/jsruntime/qv4scopedvalue_p.h
src/qml/jsruntime/qv4value_p.h

index 47a764e..5f76ba2 100644 (file)
@@ -1091,11 +1091,14 @@ bool QJSValue::hasOwnProperty(const QString &name) const
  */
 QObject *QJSValue::toQObject() const
 {
-    Returned<QV4::QObjectWrapper> *o = d->value.as<QV4::QObjectWrapper>();
-    if (!o)
+    if (!d->engine)
+        return 0;
+    QV4::Scope scope(d->engine);
+    QV4::Scoped<QV4::QObjectWrapper> wrapper(scope, d->value);
+    if (!wrapper)
         return 0;
 
-    return o->getPointer()->object();
+    return wrapper->object();
 }
 
 /*!
index 9393780..581f31a 100644 (file)
@@ -47,8 +47,6 @@ namespace QV4 {
         Q_MANAGED_CHECK \
         static const QV4::ArrayVTable static_vtbl; \
         static inline const QV4::ManagedVTable *staticVTable() { return &static_vtbl.managedVTable; } \
-        template <typename T> \
-        QV4::Returned<T> *asReturned() { return QV4::Returned<T>::create(this); } \
         V4_MANAGED_SIZE_TEST \
         const QV4::Heap::Data *d() const { return &static_cast<const QV4::Heap::Data &>(Managed::data); } \
         QV4::Heap::Data *d() { return &static_cast<QV4::Heap::Data &>(Managed::data); }
index 603b766..d3901f4 100644 (file)
@@ -48,7 +48,7 @@ DEFINE_MANAGED_VTABLE(CallContext);
 DEFINE_MANAGED_VTABLE(WithContext);
 DEFINE_MANAGED_VTABLE(GlobalContext);
 
-Returned<CallContext> *ExecutionContext::newCallContext(FunctionObject *function, CallData *callData)
+Heap::CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData *callData)
 {
     Q_ASSERT(function->function());
 
@@ -78,7 +78,7 @@ Returned<CallContext> *ExecutionContext::newCallContext(FunctionObject *function
         std::fill(c->callData->args + c->callData->argc, c->callData->args + compiledFunction->nFormals, Primitive::undefinedValue());
     c->callData->argc = qMax((uint)callData->argc, compiledFunction->nFormals);
 
-    return Returned<CallContext>::create(c);
+    return c;
 }
 
 Heap::WithContext *ExecutionContext::newWithContext(Object *with)
index 9b5c4b0..30b578e 100644 (file)
@@ -130,7 +130,7 @@ struct Q_QML_EXPORT ExecutionContext : public Managed
     V4_MANAGED(ExecutionContext, Managed)
     Q_MANAGED_TYPE(ExecutionContext)
 
-    Returned<CallContext> *newCallContext(FunctionObject *f, CallData *callData);
+    Heap::CallContext *newCallContext(FunctionObject *f, CallData *callData);
     Heap::WithContext *newWithContext(Object *with);
     Heap::CatchContext *newCatchContext(String *exceptionVarName, const ValueRef exceptionValue);
     Heap::CallContext *newQmlContext(FunctionObject *f, Object *qml);
index 1c2b8af..6119bed 100644 (file)
@@ -191,10 +191,6 @@ typedef Scoped<Object> ScopedObject;
 typedef Scoped<ArrayObject> ScopedArrayObject;
 typedef Scoped<FunctionObject> ScopedFunctionObject;
 typedef Scoped<ExecutionContext> ScopedContext;
-template<typename T> struct Returned;
-typedef Returned<String> ReturnedString;
-typedef Returned<Object> ReturnedObject;
-typedef Returned<FunctionObject> ReturnedFunctionObject;
 
 struct PersistentValuePrivate;
 class PersistentValue;
index 116be86..5b9668b 100644 (file)
@@ -64,8 +64,6 @@ inline void qYouForgotTheQ_MANAGED_Macro(T1, T2) {}
         typedef superClass SuperClass; \
         static const QV4::ManagedVTable static_vtbl; \
         static inline const QV4::ManagedVTable *staticVTable() { return &static_vtbl; } \
-        template <typename _T> \
-        QV4::Returned<_T> *asReturned() { return QV4::Returned<_T>::create(this); } \
         V4_MANAGED_SIZE_TEST \
         const QV4::Heap::DataClass *d() const { return &static_cast<const QV4::Heap::DataClass &>(Managed::data); } \
         QV4::Heap::DataClass *d() { return &static_cast<QV4::Heap::DataClass &>(Managed::data); }
@@ -76,8 +74,6 @@ inline void qYouForgotTheQ_MANAGED_Macro(T1, T2) {}
         typedef superClass SuperClass; \
         static const QV4::ObjectVTable static_vtbl; \
         static inline const QV4::ManagedVTable *staticVTable() { return &static_vtbl.managedVTable; } \
-        template <typename _T> \
-        QV4::Returned<_T> *asReturned() { return QV4::Returned<_T>::create(this); } \
         V4_MANAGED_SIZE_TEST \
         const Data *d() const { return &static_cast<const Data &>(Managed::data); } \
         Data *d() { return &static_cast<Data &>(Managed::data); }
@@ -89,8 +85,6 @@ inline void qYouForgotTheQ_MANAGED_Macro(T1, T2) {}
         typedef superClass SuperClass; \
         static const QV4::ObjectVTable static_vtbl; \
         static inline const QV4::ManagedVTable *staticVTable() { return &static_vtbl.managedVTable; } \
-        template <typename _T> \
-        QV4::Returned<_T> *asReturned() { return QV4::Returned<_T>::create(this); } \
         V4_MANAGED_SIZE_TEST \
         const QV4::Heap::DataClass *d() const { return &static_cast<const QV4::Heap::DataClass &>(Managed::data); } \
         QV4::Heap::DataClass *d() { return &static_cast<QV4::Heap::DataClass &>(Managed::data); }
index 2e15c24..cfaa604 100644 (file)
@@ -301,12 +301,12 @@ void MemoryManager::mark()
     // managed objects in the loop down there doesn't make then end up as leftovers
     // on the stack and thus always get collected.
     for (PersistentValuePrivate *weak = m_weakValues; weak; weak = weak->next) {
-        if (!weak->refcount)
+        if (!weak->refcount || !weak->value.isManaged())
             continue;
-        Returned<QObjectWrapper> *qobjectWrapper = weak->value.as<QObjectWrapper>();
+        QObjectWrapper *qobjectWrapper = weak->value.managed()->as<QObjectWrapper>();
         if (!qobjectWrapper)
             continue;
-        QObject *qobject = qobjectWrapper->getPointer()->object();
+        QObject *qobject = qobjectWrapper->object();
         if (!qobject)
             continue;
         bool keepAlive = QQmlData::keepAliveDuringGarbageCollection(qobject);
@@ -321,7 +321,7 @@ void MemoryManager::mark()
         }
 
         if (keepAlive)
-            qobjectWrapper->getPointer()->mark(m_d->engine);
+            qobjectWrapper->mark(m_d->engine);
 
         if (m_d->engine->jsStackTop >= m_d->engine->jsStackLimit)
             drainMarkStack(m_d->engine, markBase);
index 43d1b6e..9ccab91 100644 (file)
@@ -74,13 +74,9 @@ public:
 
     PersistentValue(const ValueRef val);
     PersistentValue(ReturnedValue val);
-    template<typename T>
-    PersistentValue(Returned<T> *obj);
     PersistentValue &operator=(const ValueRef other);
     PersistentValue &operator=(const ScopedValue &other);
     PersistentValue &operator =(ReturnedValue other);
-    template<typename T>
-    PersistentValue &operator=(Returned<T> *obj);
     PersistentValue &operator=(Heap::Base *obj);
     ~PersistentValue();
 
@@ -120,13 +116,9 @@ public:
     WeakValue(const ValueRef val);
     WeakValue(const WeakValue &other);
     WeakValue(ReturnedValue val);
-    template<typename T>
-    WeakValue(Returned<T> *obj);
     WeakValue &operator=(const WeakValue &other);
     WeakValue &operator=(const ValueRef other);
     WeakValue &operator =(const ReturnedValue &other);
-    template<typename T>
-    WeakValue &operator=(Returned<T> *obj);
 
     ~WeakValue();
 
index 85ffd81..f572934 100644 (file)
@@ -140,16 +140,6 @@ struct ScopedValue
 #endif
     }
 
-    template<typename T>
-    ScopedValue(const Scope &scope, Returned<T> *t)
-    {
-        ptr = scope.engine->jsStackTop++;
-        *ptr = t->getPointer() ? Value::fromManaged(t->getPointer()) : Primitive::undefinedValue();
-#ifndef QT_NO_DEBUG
-        ++scope.size;
-#endif
-    }
-
     ScopedValue &operator=(const Value &v) {
         *ptr = v;
         return *this;
@@ -173,12 +163,6 @@ struct ScopedValue
         return *this;
     }
 
-    template<typename T>
-    ScopedValue &operator=(Returned<T> *t) {
-        *ptr = t->getPointer() ? Value::fromManaged(t->getPointer()) : Primitive::undefinedValue();
-        return *this;
-    }
-
     ScopedValue &operator=(const ScopedValue &other) {
         *ptr = *other.ptr;
         return *this;
@@ -287,26 +271,6 @@ struct Scoped
 #endif
     }
 
-    template<typename X>
-    Scoped(const Scope &scope, Returned<X> *x)
-    {
-        ptr = scope.engine->jsStackTop++;
-        setPointer(Returned<T>::getPointer(x));
-#ifndef QT_NO_DEBUG
-        ++scope.size;
-#endif
-    }
-
-    template<typename X>
-    Scoped(const Scope &scope, Returned<X> *x, _Cast)
-    {
-        ptr = scope.engine->jsStackTop++;
-        setPointer(managed_cast<T>(x->getPointer()));
-#ifndef QT_NO_DEBUG
-        ++scope.size;
-#endif
-    }
-
     Scoped(const Scope &scope, const ReturnedValue &v)
     {
         ptr = scope.engine->jsStackTop++;
@@ -359,12 +323,6 @@ struct Scoped
         return *this;
     }
 
-    template<typename X>
-    Scoped<T> &operator=(Returned<X> *x) {
-        setPointer(Returned<T>::getPointer(x));
-        return *this;
-    }
-
     operator T *() {
         return static_cast<T *>(ptr->managed());
     }
@@ -392,8 +350,6 @@ struct Scoped
 #endif
     }
 
-    Returned<T> *asReturned() const { return Returned<T>::create(static_cast<typename T::Data*>(ptr->heapObject())); }
-
     Value *ptr;
 };
 
@@ -458,13 +414,6 @@ inline Scoped<T> &Scoped<T>::operator=(const ValueRef &v)
     return *this;
 }
 
-template <typename T>
-inline Value &Value::operator=(Returned<T> *t)
-{
-    val = t->getPointer()->asReturnedValue();
-    return *this;
-}
-
 inline Value &Value::operator =(const ScopedValue &v)
 {
     val = v.ptr->val;
@@ -485,12 +434,6 @@ inline Value &Value::operator=(const ValueRef v)
 }
 
 template<typename T>
-inline Returned<T> *Value::as()
-{
-    return Returned<T>::create(value_cast<T>(*this));
-}
-
-template<typename T>
 inline TypedValue<T> &TypedValue<T>::operator =(T *t)
 {
     m = t ? &t->data : 0;
@@ -510,13 +453,6 @@ inline TypedValue<T> &TypedValue<T>::operator =(const Scoped<T> &v)
     return *this;
 }
 
-template<typename T>
-inline TypedValue<T> &TypedValue<T>::operator=(Returned<T> *t)
-{
-    val = t->getPointer()->asReturnedValue();
-    return *this;
-}
-
 //template<typename T>
 //inline TypedValue<T> &TypedValue<T>::operator =(const ManagedRef<T> &v)
 //{
@@ -531,47 +467,16 @@ inline TypedValue<T> &TypedValue<T>::operator=(const TypedValue<T> &t)
     return *this;
 }
 
-template<typename T>
-inline Returned<T> * TypedValue<T>::ret() const
-{
-    return Returned<T>::create(static_cast<typename T::Data *>(heapObject()));
-}
-
 inline Primitive::operator ValueRef()
 {
     return ValueRef(this);
 }
 
-
-template<typename T>
-PersistentValue::PersistentValue(Returned<T> *obj)
-    : d(new PersistentValuePrivate(QV4::Value::fromManaged(obj->getPointer())))
-{
-}
-
-template<typename T>
-inline PersistentValue &PersistentValue::operator=(Returned<T> *obj)
-{
-    return operator=(QV4::Value::fromManaged(obj->getPointer()).asReturnedValue());
-}
-
 inline PersistentValue &PersistentValue::operator=(const ScopedValue &other)
 {
     return operator=(other.asReturnedValue());
 }
 
-template<typename T>
-inline WeakValue::WeakValue(Returned<T> *obj)
-    : d(new PersistentValuePrivate(QV4::Value::fromManaged(obj->getPointer()), /*engine*/0, /*weak*/true))
-{
-}
-
-template<typename T>
-inline WeakValue &WeakValue::operator=(Returned<T> *obj)
-{
-    return operator=(QV4::Value::fromManaged(obj->getPointer()).asReturnedValue());
-}
-
 inline ValueRef::ValueRef(const ScopedValue &v)
     : ptr(v.ptr)
 {}
index a3b08ba..71b712b 100644 (file)
@@ -83,20 +83,6 @@ struct Q_QML_EXPORT Base {
 
 }
 
-template <typename T>
-struct Returned : private Heap::Base
-{
-    static Returned<T> *create(T *t) { Q_ASSERT((void *)&t->data == (void *)t); return static_cast<Returned<T> *>(static_cast<Heap::Base*>(t ? &t->data : 0)); }
-    static Returned<T> *create(typename T::Data *t) { return static_cast<Returned<T> *>(static_cast<Heap::Base*>(t)); }
-    T *getPointer() { return reinterpret_cast<T *>(this); }
-    template<typename X>
-    static T *getPointer(Returned<X> *x) { return x->getPointer(); }
-    template<typename X>
-    Returned<X> *as() { return Returned<X>::create(Returned<X>::getPointer(this)); }
-
-    inline ReturnedValue asReturnedValue();
-};
-
 struct Q_QML_PRIVATE_EXPORT Value
 {
     /*
@@ -390,8 +376,6 @@ struct Q_QML_PRIVATE_EXPORT Value
     Value &operator =(const ScopedValue &v);
     Value &operator=(ReturnedValue v) { val = v; return *this; }
     template<typename T>
-    Value &operator=(Returned<T> *t);
-    template<typename T>
     Value &operator=(T *t) {
         val = Value::fromManaged(t).val;
         return *this;
@@ -408,8 +392,6 @@ struct Q_QML_PRIVATE_EXPORT Value
         val = v.val;
         return *this;
     }
-    template<typename T>
-    inline Returned<T> *as();
 };
 
 inline Managed *Value::asManaged() const
@@ -471,7 +453,6 @@ struct TypedValue : public Value
     TypedValue &operator =(T *t);
     TypedValue &operator =(const Scoped<T> &v);
 //    TypedValue &operator =(const ManagedRef<T> &v);
-    TypedValue &operator =(Returned<T> *t);
 
     TypedValue &operator =(const TypedValue<T> &t);
 
@@ -481,7 +462,6 @@ struct TypedValue : public Value
     T *operator->() { return static_cast<T *>(managed()); }
     const T *operator->() const { return static_cast<T *>(managed()); }
     T *getPointer() const { return static_cast<T *>(managed()); }
-    Returned<T> *ret() const;
 
     void mark(ExecutionEngine *e) { if (managed()) managed()->mark(e); }
 };
@@ -520,11 +500,6 @@ struct Encode {
         val = v;
     }
 
-    template<typename T>
-    Encode(Returned<T> *t) {
-        val = t->getPointer()->asReturnedValue();
-    }
-
     Encode(Heap::Base *o) {
         Q_ASSERT(o);
         val = Value::fromHeapObject(o).asReturnedValue();
@@ -556,11 +531,6 @@ struct ValueRef {
         ptr->val = v;
         return *this;
     }
-    template <typename T>
-    ValueRef &operator=(Returned<T> *v) {
-        ptr->val = v->asReturnedValue();
-        return *this;
-    }
 
     operator const Value *() const {
         return ptr;
@@ -607,9 +577,6 @@ T *value_cast(const Value &v)
 template<typename T>
 ReturnedValue value_convert(ExecutionEngine *e, const Value &v);
 
-template <typename T>
-ReturnedValue Returned<T>::asReturnedValue() { return Value::fromHeapObject(this).asReturnedValue(); }
-
 }
 
 QT_END_NAMESPACE