Bug 1329319 - gtest for issue with NewRunnableMethod on a non-refcounted base class method - r?froydnj draft
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 09 Jan 2017 11:09:59 +1100
changeset 457800 1ea285ab81ac52ccffc4d765b7f495b76faebf77
parent 457799 aa2cac47036d0d1d7a36c8c0137fe21f21b4961b
child 541597 1e2e2d350cc98bc0449e34ab1c7931c98a24fd49
push id40901
push usergsquelart@mozilla.com
push dateMon, 09 Jan 2017 23:50:28 +0000
reviewersfroydnj
bugs1329319
milestone53.0a1
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
xpcom/glue/tests/gtest/TestThreadUtils.cpp
--- 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,