From db7b7d4161048ec481d80deaac5ff8cfa9487626 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 3 Dec 2014 10:42:07 +0100 Subject: Return a Heap object from the getter()/setter() methods of Property We actually need to put the returned value into a ScopedFunctionObject before calling it, as the Property could get deleted during the call leading to a dangling pointer. With a GC that moves objects this will become even more important. Change-Id: I43bece6f80eb3501c1291065846e230a59ae8aed Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4property_p.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/qml/jsruntime/qv4property_p.h') diff --git a/src/qml/jsruntime/qv4property_p.h b/src/qml/jsruntime/qv4property_p.h index ef58b4c0f8..50d3c0e351 100644 --- a/src/qml/jsruntime/qv4property_p.h +++ b/src/qml/jsruntime/qv4property_p.h @@ -71,10 +71,10 @@ struct Property { inline bool isSubset(const PropertyAttributes &attrs, const Property &other, PropertyAttributes otherAttrs) const; inline void merge(PropertyAttributes &attrs, const Property &other, PropertyAttributes otherAttrs); - inline FunctionObject *getter() const { return reinterpret_cast(value.asManaged()); } - inline FunctionObject *setter() const { return reinterpret_cast(set.asManaged()); } + inline Heap::FunctionObject *getter() const { return value.isManaged() ? reinterpret_cast(value.heapObject()) : 0; } + inline Heap::FunctionObject *setter() const { return set.isManaged() ? reinterpret_cast(set.heapObject()) : 0; } inline void setGetter(FunctionObject *g) { value = Primitive::fromManaged(reinterpret_cast(g)); } - inline void setSetter(FunctionObject *s) { set = Primitive::fromManaged(reinterpret_cast(s)); } + inline void setSetter(FunctionObject *s) { set = s ? Primitive::fromManaged(reinterpret_cast(s)) : Value::fromHeapObject(0); } void copy(const Property &other, PropertyAttributes attrs) { value = other.value; @@ -82,8 +82,8 @@ struct Property { set = other.set; } - explicit Property() { value = Encode::undefined(); set = Encode::undefined(); } - explicit Property(Value v) : value(v) { set = Encode::undefined(); } + explicit Property() { value = Encode::undefined(); set = Value::fromHeapObject(0); } + explicit Property(Value v) : value(v) { set = Value::fromHeapObject(0); } Property(FunctionObject *getter, FunctionObject *setter) { value = Primitive::fromManaged(reinterpret_cast(getter)); set = Primitive::fromManaged(reinterpret_cast(setter)); @@ -111,9 +111,9 @@ inline bool Property::isSubset(const PropertyAttributes &attrs, const Property & if (attrs.type() == PropertyAttributes::Data && !value.sameValue(other.value)) return false; if (attrs.type() == PropertyAttributes::Accessor) { - if (value.asManaged() != other.value.asManaged()) + if (value.heapObject() != other.value.heapObject()) return false; - if (set.asManaged() != other.set.asManaged()) + if (set.heapObject() != other.set.heapObject()) return false; } return true; -- cgit v1.2.3