Bug 1329319 - gtest for issue with NewRunnableMethod on a non-refcounted base class method - r?froydnj
This test alone would fail to even build without the previous patch,
demonstrating the issue at hand, where the method-pointer from the base class
forces NewRunnableMethod to store a pointer to that base class in a RefPtr,
which is not possible when that base class is not ref-counted.
MozReview-Commit-ID: 9XaQ8SwMqVo
--- a/xpcom/glue/tests/gtest/TestThreadUtils.cpp
+++ b/xpcom/glue/tests/gtest/TestThreadUtils.cpp
@@ -175,17 +175,23 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
NS_IMETHOD_(nsrefcnt) RefCnt() = 0;
NS_IMETHOD_(int32_t) ID() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(IThreadUtilsObject, NS_IFOO_IID)
+struct ThreadUtilsObjectNonRefCountedBase
+{
+ virtual void MethodFromNonRefCountedBase() {}
+};
+
struct ThreadUtilsObject : public IThreadUtilsObject
+ , public ThreadUtilsObjectNonRefCountedBase
{
// nsISupports implementation
NS_DECL_ISUPPORTS
// IThreadUtilsObject implementation
NS_IMETHOD_(nsrefcnt) RefCnt() override { return mRefCnt; }
NS_IMETHOD_(int32_t) ID() override { return 0; }
@@ -369,16 +375,22 @@ TEST(ThreadUtils, main)
r1->Run();
EXPECT_EQ(count += 1, rpt->mCount);
r1 = NewRunnableMethod<int>(rpt, &ThreadUtilsObject::Test1i, 11);
r1->Run();
EXPECT_EQ(count += 2, rpt->mCount);
EXPECT_EQ(11, rpt->mA0);
+ // Test calling a method from a non-ref-counted base.
+
+ r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::MethodFromNonRefCountedBase);
+ r1->Run();
+ EXPECT_EQ(count, rpt->mCount);
+
// Test variadic function with simple POD arguments.
r1 = NewRunnableMethod(rpt, &ThreadUtilsObject::Test0);
r1->Run();
EXPECT_EQ(count += 1, rpt->mCount);
static_assert(
mozilla::IsSame< ::detail::ParameterStorage<int>::Type,