<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[178615] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/178615">178615</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2015-01-16 16:39:57 -0800 (Fri, 16 Jan 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>WeakPtr functions crash when created with default constructor
https://bugs.webkit.org/show_bug.cgi?id=140479

Reviewed by Andreas Kling.

Source/WTF:

This patch rearranges how WeakPtr works, and has the following ideas behind it:

1. WeakPtr should use Ref internally. This solves the crash by always having a
valid WeakReference.
2. Clients should not be able to construct WeakReferences directly. Instead,
only WeakPtrFactory (and WeakPtr's default constructor) should be able to
construct them. They are considered an implementation detail of WeakPtr.
3. Except for the default constructor, clients should not be able to construct
WeakPtrs directly. Instead, the WeakPtrFactory must construct them. This
guarantees that the WeakPtrs all reference the same WeakReference.
4. Clients can construct a WeakPtr using its default constructor, and then
use the assignment operator to make it non-null. (Or they could use
WeakPtrFactory to make it non-null at creation-time.)
5. No one was using WeakReference::bindTo(), and it doesn't seem useful, so I
removed it.

Tests: WTF_WeakPtr API tests

* wtf/Ref.h:
(WTF::Ref::Ref): Added extra ASSERT()s, and explicitly deleted copy
constructors with a comment.
(WTF::Ref::operator=): Added extra ASSERT()s, and explicitly deleted copy
assignment operators with a comment.
* wtf/WeakPtr.h:
(WTF::WeakReference::clear): Used nullptr.
(WTF::WeakReference::create): Moved to private:
(WTF::WeakPtr::WeakPtr): For the default constructor, initialized the Ref with
a new WeakReference. For the other constructor, moved it to private:. Also added
copy constructors and copy assignment operators (since Ref doesn't have them but
RefPtr does). These constructors/operators are relied upon in various places
throughout WebCore.
(WTF::WeakPtr::operator bool): Made non-explicit.
(WTF::WeakReference::createUnbound): Deleted.
(WTF::WeakReference::bindTo): Deleted.
(WTF::WeakReference::WeakReference): Deleted.
(WTF::WeakPtrFactory::WeakPtrFactory): Deleted.

Tools:

Add WeakPtr API tests.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Added.
* TestWebKitAPI/Tests/WTF/Ref.cpp: Update to not use copy constructor.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfRefh">trunk/Source/WTF/wtf/Ref.h</a></li>
<li><a href="#trunkSourceWTFwtfWeakPtrh">trunk/Source/WTF/wtf/WeakPtr.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFRefcpp">trunk/Tools/TestWebKitAPI/Tests/WTF/Ref.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWTFWeakPtrcpp">trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (178614 => 178615)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2015-01-17 00:37:08 UTC (rev 178614)
+++ trunk/Source/WTF/ChangeLog        2015-01-17 00:39:57 UTC (rev 178615)
</span><span class="lines">@@ -1,3 +1,47 @@
</span><ins>+2015-01-16  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        WeakPtr functions crash when created with default constructor
+        https://bugs.webkit.org/show_bug.cgi?id=140479
+
+        Reviewed by Andreas Kling.
+
+        This patch rearranges how WeakPtr works, and has the following ideas behind it:
+
+        1. WeakPtr should use Ref internally. This solves the crash by always having a
+        valid WeakReference.
+        2. Clients should not be able to construct WeakReferences directly. Instead,
+        only WeakPtrFactory (and WeakPtr's default constructor) should be able to
+        construct them. They are considered an implementation detail of WeakPtr.
+        3. Except for the default constructor, clients should not be able to construct
+        WeakPtrs directly. Instead, the WeakPtrFactory must construct them. This
+        guarantees that the WeakPtrs all reference the same WeakReference.
+        4. Clients can construct a WeakPtr using its default constructor, and then
+        use the assignment operator to make it non-null. (Or they could use
+        WeakPtrFactory to make it non-null at creation-time.)
+        5. No one was using WeakReference::bindTo(), and it doesn't seem useful, so I
+        removed it.
+
+        Tests: WTF_WeakPtr API tests
+
+        * wtf/Ref.h:
+        (WTF::Ref::Ref): Added extra ASSERT()s, and explicitly deleted copy
+        constructors with a comment.
+        (WTF::Ref::operator=): Added extra ASSERT()s, and explicitly deleted copy
+        assignment operators with a comment.
+        * wtf/WeakPtr.h:
+        (WTF::WeakReference::clear): Used nullptr.
+        (WTF::WeakReference::create): Moved to private:
+        (WTF::WeakPtr::WeakPtr): For the default constructor, initialized the Ref with
+        a new WeakReference. For the other constructor, moved it to private:. Also added
+        copy constructors and copy assignment operators (since Ref doesn't have them but
+        RefPtr does). These constructors/operators are relied upon in various places
+        throughout WebCore.
+        (WTF::WeakPtr::operator bool): Made non-explicit.
+        (WTF::WeakReference::createUnbound): Deleted.
+        (WTF::WeakReference::bindTo): Deleted.
+        (WTF::WeakReference::WeakReference): Deleted.
+        (WTF::WeakPtrFactory::WeakPtrFactory): Deleted.
+
</ins><span class="cx"> 2015-01-16  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         std::all_of requires complete C++ iterators in GCC 4.8
</span></span></pre></div>
<a id="trunkSourceWTFwtfRefh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/Ref.h (178614 => 178615)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/Ref.h        2015-01-17 00:37:08 UTC (rev 178614)
+++ trunk/Source/WTF/wtf/Ref.h        2015-01-17 00:39:57 UTC (rev 178615)
</span><span class="lines">@@ -52,15 +52,21 @@
</span><span class="cx">         m_ptr-&gt;ref();
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // Use copyRef() instead.
+    Ref(const Ref&amp; other) = delete;
+    template&lt;typename U&gt; Ref(const Ref&lt;U&gt;&amp; other) = delete;
+
</ins><span class="cx">     Ref(Ref&amp;&amp; other)
</span><span class="cx">         : m_ptr(&amp;other.leakRef())
</span><span class="cx">     {
</span><ins>+        ASSERT(m_ptr);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     template&lt;typename U&gt;
</span><span class="cx">     Ref(Ref&lt;U&gt;&amp;&amp; other)
</span><span class="cx">         : m_ptr(&amp;other.leakRef())
</span><span class="cx">     {
</span><ins>+        ASSERT(m_ptr);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     Ref&amp; operator=(T&amp; object)
</span><span class="lines">@@ -69,14 +75,20 @@
</span><span class="cx">         object.ref();
</span><span class="cx">         m_ptr-&gt;deref();
</span><span class="cx">         m_ptr = &amp;object;
</span><ins>+        ASSERT(m_ptr);
</ins><span class="cx">         return *this;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // Use copyRef() and the move assignment operators instead.
+    Ref&amp; operator=(const Ref&amp; reference) = delete;
+    template&lt;typename U&gt; Ref&amp; operator=(const Ref&lt;U&gt;&amp; reference) = delete;
+
</ins><span class="cx">     Ref&amp; operator=(Ref&amp;&amp; reference)
</span><span class="cx">     {
</span><span class="cx">         ASSERT(m_ptr);
</span><span class="cx">         m_ptr-&gt;deref();
</span><span class="cx">         m_ptr = &amp;reference.leakRef();
</span><ins>+        ASSERT(m_ptr);
</ins><span class="cx">         return *this;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -85,6 +97,7 @@
</span><span class="cx">         ASSERT(m_ptr);
</span><span class="cx">         m_ptr-&gt;deref();
</span><span class="cx">         m_ptr = &amp;reference.leakRef();
</span><ins>+        ASSERT(m_ptr);
</ins><span class="cx">         return *this;
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWTFwtfWeakPtrh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/WeakPtr.h (178614 => 178615)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/WeakPtr.h        2015-01-17 00:37:08 UTC (rev 178614)
+++ trunk/Source/WTF/wtf/WeakPtr.h        2015-01-17 00:39:57 UTC (rev 178615)
</span><span class="lines">@@ -27,8 +27,7 @@
</span><span class="cx"> #define WTF_WeakPtr_h
</span><span class="cx"> 
</span><span class="cx"> #include &lt;wtf/Noncopyable.h&gt;
</span><del>-#include &lt;wtf/PassRefPtr.h&gt;
-#include &lt;wtf/RefPtr.h&gt;
</del><ins>+#include &lt;wtf/Ref.h&gt;
</ins><span class="cx"> #include &lt;wtf/ThreadSafeRefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/Threading.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -38,14 +37,14 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span><span class="cx"> 
</span><ins>+template&lt;typename T&gt; class WeakPtr;
+template&lt;typename T&gt; class WeakPtrFactory;
+
</ins><span class="cx"> template&lt;typename T&gt;
</span><span class="cx"> class WeakReference : public ThreadSafeRefCounted&lt;WeakReference&lt;T&gt;&gt; {
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(WeakReference&lt;T&gt;);
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    static PassRefPtr&lt;WeakReference&lt;T&gt;&gt; create(T* ptr) { return adoptRef(new WeakReference(ptr)); }
-    static PassRefPtr&lt;WeakReference&lt;T&gt;&gt; createUnbound() { return adoptRef(new WeakReference()); }
-
</del><span class="cx">     T* get() const
</span><span class="cx">     {
</span><span class="cx"> #if USE(WEB_THREAD)
</span><span class="lines">@@ -63,21 +62,15 @@
</span><span class="cx"> #else
</span><span class="cx">         ASSERT(m_boundThread == currentThread());
</span><span class="cx"> #endif
</span><del>-        m_ptr = 0;
</del><ins>+        m_ptr = nullptr;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void bindTo(T* ptr)
-    {
-        ASSERT(!m_ptr);
-#ifndef NDEBUG
-        m_boundThread = currentThread();
-#endif
-        m_ptr = ptr;
-    }
-
</del><span class="cx"> private:
</span><del>-    WeakReference() : m_ptr(0) { }
</del><ins>+    friend class WeakPtr&lt;T&gt;;
+    friend class WeakPtrFactory&lt;T&gt;;
</ins><span class="cx"> 
</span><ins>+    static Ref&lt;WeakReference&lt;T&gt;&gt; create(T* ptr) { return adoptRef(*new WeakReference(ptr)); }
+
</ins><span class="cx">     explicit WeakReference(T* ptr)
</span><span class="cx">         : m_ptr(ptr)
</span><span class="cx"> #ifndef NDEBUG
</span><span class="lines">@@ -96,16 +89,23 @@
</span><span class="cx"> class WeakPtr {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    WeakPtr() { }
-    WeakPtr(PassRefPtr&lt;WeakReference&lt;T&gt;&gt; ref) : m_ref(ref) { }
</del><ins>+    WeakPtr() : m_ref(WeakReference&lt;T&gt;::create(nullptr)) { }
+    WeakPtr(const WeakPtr&amp; o) : m_ref(o.m_ref.copyRef()) { }
+    template&lt;typename U&gt; WeakPtr(const WeakPtr&lt;U&gt;&amp; o) : m_ref(o.m_ref.copyRef()) { }
</ins><span class="cx"> 
</span><span class="cx">     T* get() const { return m_ref-&gt;get(); }
</span><del>-    explicit operator bool() const { return m_ref-&gt;get(); }
</del><ins>+    operator bool() const { return m_ref-&gt;get(); }
</ins><span class="cx"> 
</span><ins>+    WeakPtr&amp; operator=(const WeakPtr&amp; o) { m_ref = o.m_ref.copyRef(); return *this; }
+    template&lt;typename U&gt; WeakPtr&amp; operator=(const WeakPtr&lt;U&gt;&amp; o) { m_ref = o.m_ref.copyRef(); return *this; }
+
</ins><span class="cx">     T* operator-&gt;() const { return m_ref-&gt;get(); }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    RefPtr&lt;WeakReference&lt;T&gt;&gt; m_ref;
</del><ins>+    friend class WeakPtrFactory&lt;T&gt;;
+    WeakPtr(Ref&lt;WeakReference&lt;T&gt;&gt;&amp;&amp; ref) : m_ref(std::forward&lt;Ref&lt;WeakReference&lt;T&gt;&gt;&gt;(ref)) { }
+
+    Ref&lt;WeakReference&lt;T&gt;&gt; m_ref;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;typename T&gt;
</span><span class="lines">@@ -115,16 +115,10 @@
</span><span class="cx"> public:
</span><span class="cx">     explicit WeakPtrFactory(T* ptr) : m_ref(WeakReference&lt;T&gt;::create(ptr)) { }
</span><span class="cx"> 
</span><del>-    WeakPtrFactory(PassRefPtr&lt;WeakReference&lt;T&gt;&gt; ref, T* ptr)
-        : m_ref(ref)
-    {
-        m_ref-&gt;bindTo(ptr);
-    }
-
</del><span class="cx">     ~WeakPtrFactory() { m_ref-&gt;clear(); }
</span><span class="cx"> 
</span><span class="cx">     // We should consider having createWeakPtr populate m_ref the first time createWeakPtr is called.
</span><del>-    WeakPtr&lt;T&gt; createWeakPtr() { return WeakPtr&lt;T&gt;(m_ref); }
</del><ins>+    WeakPtr&lt;T&gt; createWeakPtr() { return WeakPtr&lt;T&gt;(m_ref.copyRef()); }
</ins><span class="cx"> 
</span><span class="cx">     void revokeAll()
</span><span class="cx">     {
</span><span class="lines">@@ -135,7 +129,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    RefPtr&lt;WeakReference&lt;T&gt;&gt; m_ref;
</del><ins>+    Ref&lt;WeakReference&lt;T&gt;&gt; m_ref;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (178614 => 178615)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-01-17 00:37:08 UTC (rev 178614)
+++ trunk/Tools/ChangeLog        2015-01-17 00:39:57 UTC (rev 178615)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2015-01-16  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        WeakPtr functions crash when created with default constructor
+        https://bugs.webkit.org/show_bug.cgi?id=140479
+
+        Reviewed by Andreas Kling.
+
+        Add WeakPtr API tests.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/WeakPtr.cpp: Added.
+        * TestWebKitAPI/Tests/WTF/Ref.cpp: Update to not use copy constructor.
+
</ins><span class="cx"> 2015-01-16  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Regression(r178586): Caused webkitpy.w3c.test_converter_unittest.W3CTestConverterTest.test_convert_prefixed_properties to fail
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (178614 => 178615)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-01-17 00:37:08 UTC (rev 178614)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2015-01-17 00:39:57 UTC (rev 178615)
</span><span class="lines">@@ -17,6 +17,7 @@
</span><span class="cx">                 1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C045F9461385C2F800C0F3CD /* 18-characters.html */; };
</span><span class="cx">                 1ADBEFE3130C6AA100D61D19 /* simple-accelerated-compositing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */; };
</span><span class="cx">                 1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */; };
</span><ins>+                1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CB9BC371A67482300FE5678 /* WeakPtr.cpp */; };
</ins><span class="cx">                 26DF5A6315A2A27E003689C2 /* CancelLoadFromResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */; };
</span><span class="cx">                 26F52EAD1828827B0023D412 /* geolocationGetCurrentPosition.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26F52EAC1828820E0023D412 /* geolocationGetCurrentPosition.html */; };
</span><span class="cx">                 26F52EAF18288C230023D412 /* geolocationGetCurrentPositionWithHighAccuracy.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26F52EAE18288C040023D412 /* geolocationGetCurrentPositionWithHighAccuracy.html */; };
</span><span class="lines">@@ -404,6 +405,7 @@
</span><span class="cx">                 1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundleControllerMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1AEF994817A09F5300998EF0 /* GetPIDAfterAbortedProcessLaunch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetPIDAfterAbortedProcessLaunch.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1AFDE6541953B2C000C48FFA /* Optional.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Optional.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                1CB9BC371A67482300FE5678 /* WeakPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakPtr.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 261516D515B0E60500A2C201 /* SetAndUpdateCacheModel.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SetAndUpdateCacheModel.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 26300B1716755CD90066886D /* ListHashSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ListHashSet.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 265AF54F15D1E48A00B0CB4A /* WTFString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WTFString.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1020,6 +1022,7 @@
</span><span class="cx">                                 0BCD85691485C98B00EA2003 /* TemporaryChange.cpp */,
</span><span class="cx">                                 BC55F5F814AD78EE00484BE1 /* Vector.cpp */,
</span><span class="cx">                                 265AF54F15D1E48A00B0CB4A /* WTFString.cpp */,
</span><ins>+                                1CB9BC371A67482300FE5678 /* WeakPtr.cpp */,
</ins><span class="cx">                         );
</span><span class="cx">                         path = WTF;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="lines">@@ -1513,6 +1516,7 @@
</span><span class="cx">                         isa = PBXSourcesBuildPhase;
</span><span class="cx">                         buildActionMask = 2147483647;
</span><span class="cx">                         files = (
</span><ins>+                                1CB9BC381A67482300FE5678 /* WeakPtr.cpp in Sources */,
</ins><span class="cx">                                 2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */,
</span><span class="cx">                                 2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */,
</span><span class="cx">                         );
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFRefcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Ref.cpp (178614 => 178615)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/Ref.cpp        2015-01-17 00:37:08 UTC (rev 178614)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Ref.cpp        2015-01-17 00:39:57 UTC (rev 178615)
</span><span class="lines">@@ -151,7 +151,7 @@
</span><span class="cx"> 
</span><span class="cx">     {
</span><span class="cx">         Ref&lt;DerivedRefLogger&gt; derivedReference(a);
</span><del>-        Ref&lt;RefLogger&gt; baseReference(passWithRef(Ref&lt;RefLogger&gt;(derivedReference)));
</del><ins>+        Ref&lt;RefLogger&gt; baseReference(passWithRef(derivedReference.copyRef()));
</ins><span class="cx">         ASSERT_EQ(&amp;a, derivedReference.ptr());
</span><span class="cx">         ASSERT_EQ(&amp;a, baseReference.ptr());
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFWeakPtrcpp"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp (0 => 178615)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/WeakPtr.cpp        2015-01-17 00:39:57 UTC (rev 178615)
</span><span class="lines">@@ -0,0 +1,122 @@
</span><ins>+/*
+ * 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
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;test.h&quot;
+
+#include &lt;wtf/WeakPtr.h&gt;
+
+namespace TestWebKitAPI {
+
+TEST(WTF_WeakPtr, Basic)
+{
+    int dummy = 5;
+    WeakPtrFactory&lt;int&gt;* factory = new WeakPtrFactory&lt;int&gt;(&amp;dummy);
+    WeakPtr&lt;int&gt; weakPtr1 = factory-&gt;createWeakPtr();
+    WeakPtr&lt;int&gt; weakPtr2 = factory-&gt;createWeakPtr();
+    WeakPtr&lt;int&gt; weakPtr3 = factory-&gt;createWeakPtr();
+    EXPECT_EQ(weakPtr1.get(), &amp;dummy);
+    EXPECT_EQ(weakPtr2.get(), &amp;dummy);
+    EXPECT_EQ(weakPtr3.get(), &amp;dummy);
+    EXPECT_TRUE(weakPtr1);
+    EXPECT_TRUE(weakPtr2);
+    EXPECT_TRUE(weakPtr3);
+    delete factory;
+    EXPECT_NULL(weakPtr1.get());
+    EXPECT_NULL(weakPtr2.get());
+    EXPECT_NULL(weakPtr3.get());
+    EXPECT_FALSE(weakPtr1);
+    EXPECT_FALSE(weakPtr2);
+    EXPECT_FALSE(weakPtr3);
+}
+
+TEST(WTF_WeakPtr, Assignment)
+{
+    int dummy = 5;
+    WeakPtr&lt;int&gt; weakPtr;
+    {
+        WeakPtrFactory&lt;int&gt; factory(&amp;dummy);
+        EXPECT_NULL(weakPtr.get());
+        weakPtr = factory.createWeakPtr();
+        EXPECT_EQ(weakPtr.get(), &amp;dummy);
+    }
+    EXPECT_NULL(weakPtr.get());
+}
+
+TEST(WTF_WeakPtr, MultipleFactories)
+{
+    int dummy1 = 5;
+    int dummy2 = 7;
+    WeakPtrFactory&lt;int&gt;* factory1 = new WeakPtrFactory&lt;int&gt;(&amp;dummy1);
+    WeakPtrFactory&lt;int&gt;* factory2 = new WeakPtrFactory&lt;int&gt;(&amp;dummy2);
+    WeakPtr&lt;int&gt; weakPtr1 = factory1-&gt;createWeakPtr();
+    WeakPtr&lt;int&gt; weakPtr2 = factory2-&gt;createWeakPtr();
+    EXPECT_EQ(weakPtr1.get(), &amp;dummy1);
+    EXPECT_EQ(weakPtr2.get(), &amp;dummy2);
+    delete factory1;
+    EXPECT_NULL(weakPtr1.get());
+    EXPECT_EQ(weakPtr2.get(), &amp;dummy2);
+    delete factory2;
+    EXPECT_NULL(weakPtr2.get());
+}
+
+TEST(WTF_WeakPtr, RevokeAll)
+{
+    int dummy = 5;
+    WeakPtrFactory&lt;int&gt; factory(&amp;dummy);
+    WeakPtr&lt;int&gt; weakPtr1 = factory.createWeakPtr();
+    WeakPtr&lt;int&gt; weakPtr2 = factory.createWeakPtr();
+    WeakPtr&lt;int&gt; weakPtr3 = factory.createWeakPtr();
+    EXPECT_EQ(weakPtr1.get(), &amp;dummy);
+    EXPECT_EQ(weakPtr2.get(), &amp;dummy);
+    EXPECT_EQ(weakPtr3.get(), &amp;dummy);
+    factory.revokeAll();
+    EXPECT_NULL(weakPtr1.get());
+    EXPECT_NULL(weakPtr2.get());
+    EXPECT_NULL(weakPtr3.get());
+}
+
+TEST(WTF_WeakPtr, NullFactory)
+{
+    WeakPtrFactory&lt;int&gt; factory(nullptr);
+    WeakPtr&lt;int&gt; weakPtr = factory.createWeakPtr();
+    EXPECT_NULL(weakPtr.get());
+    factory.revokeAll();
+    EXPECT_NULL(weakPtr.get());
+}
+
+struct Foo {
+    void bar() { };
+};
+
+TEST(WTF_WeakPtr, Dereference)
+{
+    Foo f;
+    WeakPtrFactory&lt;Foo&gt; factory(&amp;f);
+    WeakPtr&lt;Foo&gt; weakPtr = factory.createWeakPtr();
+    weakPtr-&gt;bar();
+}
+
+} // namespace TestWebKitAPI
</ins></span></pre>
</div>
</div>

</body>
</html>