Title: [180528] trunk
Revision
180528
Author
[email protected]
Date
2015-02-23 15:44:02 -0800 (Mon, 23 Feb 2015)

Log Message

Source/WTF:
WTF::WeakPtr should have a 'forget' method
https://bugs.webkit.org/show_bug.cgi?id=141923

Reviewed by Myles C. Maxfield.

* wtf/WeakPtr.h:
(WTF::WeakPtr::forget): Added.

Tools:
WTF::WeakPtr should have a 'forget' method.
https://bugs.webkit.org/show_bug.cgi?id=141923

Reviewed by Myles C. Maxfield.

* TestWebKitAPI/Tests/WTF/WeakPtr.cpp:
(TestWebKitAPI::TEST): Added 'Forget' tests case.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (180527 => 180528)


--- trunk/Source/WTF/ChangeLog	2015-02-23 23:26:04 UTC (rev 180527)
+++ trunk/Source/WTF/ChangeLog	2015-02-23 23:44:02 UTC (rev 180528)
@@ -1,3 +1,13 @@
+2015-02-23  Brent Fulgham  <[email protected]>
+
+        WTF::WeakPtr should have a 'forget' method
+        https://bugs.webkit.org/show_bug.cgi?id=141923
+
+        Reviewed by Myles C. Maxfield.
+
+        * wtf/WeakPtr.h:
+        (WTF::WeakPtr::forget): Added.
+
 2015-02-20  Geoffrey Garen  <[email protected]>
 
         Remove TCMalloc

Modified: trunk/Source/WTF/wtf/WeakPtr.h (180527 => 180528)


--- trunk/Source/WTF/wtf/WeakPtr.h	2015-02-23 23:26:04 UTC (rev 180527)
+++ trunk/Source/WTF/wtf/WeakPtr.h	2015-02-23 23:44:02 UTC (rev 180528)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2013 Google, Inc. All Rights Reserved.
+ * Copyright (C) 2015 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -40,6 +41,7 @@
 template<typename T> class WeakPtr;
 template<typename T> class WeakPtrFactory;
 
+// Note: WeakReference is an implementation detail, and should not be used directly.
 template<typename T>
 class WeakReference : public ThreadSafeRefCounted<WeakReference<T>> {
     WTF_MAKE_NONCOPYABLE(WeakReference<T>);
@@ -101,6 +103,8 @@
 
     T* operator->() const { return m_ref->get(); }
 
+    void forget() { m_ref = WeakReference<T>::create(nullptr); }
+
 private:
     friend class WeakPtrFactory<T>;
     WeakPtr(Ref<WeakReference<T>>&& ref) : m_ref(std::forward<Ref<WeakReference<T>>>(ref)) { }

Modified: trunk/Tools/ChangeLog (180527 => 180528)


--- trunk/Tools/ChangeLog	2015-02-23 23:26:04 UTC (rev 180527)
+++ trunk/Tools/ChangeLog	2015-02-23 23:44:02 UTC (rev 180528)
@@ -1,3 +1,13 @@
+2015-02-23  Brent Fulgham  <[email protected]>
+
+        WTF::WeakPtr should have a 'forget' method.
+        https://bugs.webkit.org/show_bug.cgi?id=141923
+
+        Reviewed by Myles C. Maxfield.
+
+        * TestWebKitAPI/Tests/WTF/WeakPtr.cpp:
+        (TestWebKitAPI::TEST): Added 'Forget' tests case.
+
 2015-02-23  Alexey Proskuryakov  <[email protected]>
 
         build.webkit.org/dashboard CrashOnly queues should not show two green bubbles

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp (180527 => 180528)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp	2015-02-23 23:26:04 UTC (rev 180527)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp	2015-02-23 23:44:02 UTC (rev 180528)
@@ -119,4 +119,52 @@
     weakPtr->bar();
 }
 
+TEST(WTF_WeakPtr, Forget)
+{
+    int dummy = 5;
+    int dummy2 = 7;
+
+    WeakPtrFactory<int> outerFactory(&dummy2);
+    WeakPtr<int> weakPtr1, weakPtr2, weakPtr4;
+    {
+        WeakPtrFactory<int> innerFactory(&dummy);
+        weakPtr1 = innerFactory.createWeakPtr();
+        weakPtr2 = innerFactory.createWeakPtr();
+        EXPECT_EQ(weakPtr1.get(), &dummy);
+        EXPECT_EQ(weakPtr2.get(), &dummy);
+        weakPtr1.forget();
+        EXPECT_NULL(weakPtr1.get());
+        EXPECT_EQ(weakPtr2.get(), &dummy);
+        weakPtr1.forget();
+        EXPECT_NULL(weakPtr1.get());
+        EXPECT_EQ(weakPtr2.get(), &dummy);
+        WeakPtr<int> weakPtr3 = weakPtr2;
+        EXPECT_EQ(weakPtr2.get(), &dummy);
+        EXPECT_EQ(weakPtr3.get(), &dummy);
+        weakPtr3.forget();
+        EXPECT_NULL(weakPtr3.get());
+        EXPECT_EQ(weakPtr2.get(), &dummy);
+        weakPtr4 = weakPtr2;
+        EXPECT_EQ(weakPtr2.get(), &dummy);
+        EXPECT_EQ(weakPtr4.get(), &dummy);
+
+        weakPtr4 = outerFactory.createWeakPtr();
+        EXPECT_EQ(weakPtr2.get(), &dummy);
+        EXPECT_EQ(weakPtr4.get(), &dummy2);
+    }
+
+    EXPECT_NULL(weakPtr1.get());
+    EXPECT_NULL(weakPtr2.get());
+    EXPECT_EQ(weakPtr4.get(), &dummy2);
+
+    WeakPtr<int> weakPtr5 = weakPtr4;
+    EXPECT_EQ(weakPtr4.get(), &dummy2);
+    EXPECT_EQ(weakPtr5.get(), &dummy2);
+    weakPtr5.forget();
+    EXPECT_NULL(weakPtr5.get());
+    WeakPtr<int> weakPtr6 = weakPtr5;
+    EXPECT_NULL(weakPtr6.get());
+    EXPECT_EQ(weakPtr5.get(), weakPtr6.get());
+}
+    
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to