Allow constructing a base PassRef with a derived Ref
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Nov 2014 19:07:11 +0000 (19:07 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Nov 2014 19:07:11 +0000 (19:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138701

Reviewed by Andreas Kling

Source/WTF:

* wtf/PassRef.h:
(WTF::PassRef<T>::PassRef):

Tools:

* TestWebKitAPI/Tests/WTF/Ref.cpp:
(TestWebKitAPI::passWithPassRef):
(TestWebKitAPI::passWithPassRefPtr):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176078 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/PassRef.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/Ref.cpp

index 0f0e9677025217de5b4e635bee9c6ff3fe8c371f..397035ca09796cc51571c9199a96453e7b1787e6 100644 (file)
@@ -1,3 +1,13 @@
+2014-11-13  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Allow constructing a base PassRef with a derived Ref
+        https://bugs.webkit.org/show_bug.cgi?id=138701
+
+        Reviewed by Andreas Kling
+
+        * wtf/PassRef.h:
+        (WTF::PassRef<T>::PassRef):
+
 2014-11-12  Ryuan Choi  <ryuan.choi@navercorp.com>
 
         [EFL] Fix the build with EFL 1.12
index 883651ec5fa19c35c9aa9ee40846980e4bc3a5ac..bc09b11d98587cadad05c618ca3ef49e7bd83fc5 100644 (file)
@@ -100,7 +100,7 @@ template<typename T> template<typename U> inline PassRef<T>::PassRef(PassRef<U>
 }
 
 template<typename T> template<typename U> inline PassRef<T>::PassRef(const Ref<U>& other)
-    : m_reference(const_cast<T&>(other.get()))
+    : m_reference(static_cast<T&>(const_cast<U&>(other.get())))
 #ifndef NDEBUG
     , m_gaveUpReference(false)
 #endif
index fe38a8de43803ce56a8f51a984948f46b4d9da68..e80ecf54db14540afe2fbef62d8b6d699c3829f6 100644 (file)
@@ -1,3 +1,15 @@
+2014-11-13  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Allow constructing a base PassRef with a derived Ref
+        https://bugs.webkit.org/show_bug.cgi?id=138701
+
+        Reviewed by Andreas Kling
+
+        * TestWebKitAPI/Tests/WTF/Ref.cpp:
+        (TestWebKitAPI::passWithPassRef):
+        (TestWebKitAPI::passWithPassRefPtr):
+        (TestWebKitAPI::TEST):
+
 2014-11-05  Ada Chan  <adachan@apple.com>
 
         Implement new plug-in API for muting plug-ins
index b6e9d5c5fee67a62844aa938c1f491c80e32b2e1..c3009a490cd88c02b9db0c9dd9e5b9265c102329 100644 (file)
@@ -98,12 +98,12 @@ TEST(WTF_Ref, Assignment)
     ASSERT_STREQ("ref(a) | deref(a) | deref(c) ", takeLogStr().c_str());
 }
 
-PassRef<RefLogger> passWithPassRef(PassRef<RefLogger> reference)
+static PassRef<RefLogger> passWithPassRef(PassRef<RefLogger> reference)
 {
     return reference;
 }
 
-RefPtr<RefLogger> passWithPassRefPtr(PassRefPtr<RefLogger> reference)
+static RefPtr<RefLogger> passWithPassRefPtr(PassRefPtr<RefLogger> reference)
 {
     return reference;
 }
@@ -141,6 +141,22 @@ TEST(WTF_Ref, ReturnValue)
         ASSERT_EQ(&a, ptr.get());
     }
     ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+    {
+        RefPtr<DerivedRefLogger> ptr(&a);
+        RefPtr<RefLogger> ptr2(WTF::move(ptr));
+        ASSERT_EQ(nullptr, ptr.get());
+        ASSERT_EQ(&a, ptr2.get());
+    }
+    ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+    {
+        Ref<DerivedRefLogger> derivedReference(a);
+        Ref<RefLogger> baseReference(passWithPassRef(derivedReference));
+        ASSERT_EQ(&a, derivedReference.ptr());
+        ASSERT_EQ(&a, baseReference.ptr());
+    }
+    ASSERT_STREQ("ref(a) ref(a) deref(a) deref(a) ", takeLogStr().c_str());
 }
 
 } // namespace TestWebKitAPI