Introduce a Heap::Pointer class
authorLars Knoll <lars.knoll@theqtcompany.com>
Thu, 12 Feb 2015 20:03:53 +0000 (21:03 +0100)
committerSimon Hausmann <simon.hausmann@theqtcompany.com>
Mon, 2 Mar 2015 16:34:09 +0000 (16:34 +0000)
This is required to properly mark pointers to other heap
objects, as well as to have a single point where to implement
a write barrier later on.

Change-Id: I7d57044f1a306ca8da8183793635ed49a3637146
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/jsruntime/qv4object_p.h
src/qml/jsruntime/qv4value_p.h

index 71a997e..a8bd97b 100644 (file)
@@ -55,7 +55,7 @@ struct Object : Base {
     Property *propertyAt(uint index) { return reinterpret_cast<Property *>(memberData->data + index); }
 
     InternalClass *internalClass;
-    Heap::Object *prototype;
+    Pointer<Object> prototype;
     MemberData *memberData;
     ArrayData *arrayData;
 };
index 5159ad8..93cbe9b 100644 (file)
@@ -90,6 +90,20 @@ struct Q_QML_EXPORT Base {
     void operator delete(void *, Heap::Base *) {}
 };
 
+template <typename T>
+struct Pointer {
+    Pointer() {}
+    Pointer(T *t) : ptr(t) {}
+
+    T *operator->() const { return static_cast<T *>(ptr); }
+    operator T *() const { return static_cast<T *>(ptr); }
+
+    Pointer &operator =(T *t) { ptr = t; return *this; }
+
+    // Use Base, not T here, to ensure T inherits from ptr
+    Base *ptr;
+};
+
 }
 
 struct Q_QML_PRIVATE_EXPORT Value