<!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>[283476] 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/283476">283476</a></dd>
<dt>Author</dt> <dd>ddkilzer@apple.com</dd>
<dt>Date</dt> <dd>2021-10-03 12:31:55 -0700 (Sun, 03 Oct 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>WTF::RetainPtr<> allows assignment of two pointer types that are not assignable
<https://webkit.org/b/230406>
<rdar://problem/83241893>

Reviewed by Darin Adler.

Source/WebKit:

* Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(transformTrustToData):
- Change return type to match object.
(encodeError):
- Use bridge_cast() to fix assignment.
(transformDataToTrust):
- Change return type to match object.
(decodeError):
- Use bridge_id_cast() to fix assignment.
* Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::applyBackingStoreToLayer):
- Use bridge_id_cast() to fix assignment.

* UIProcess/mac/WebDataListSuggestionsDropdownMac.h:
- Use correct name of class that actually exists.

Source/WebKitLegacy/mac:

* Plugins/WebBasePluginPackage.mm:
(+[WebBasePluginPackage pluginWithPath:]):
- Use explicit type with RetainPtr<> to match return type.

Source/WTF:

* wtf/RetainPtr.h:
(WTF::RetainPtr::RetainPtr):
(WTF::RetainPtr::checkType): Add.
- Add type check for move constructor.

* wtf/cocoa/TypeCastsCocoa.h:
- Change #include to #import.
(WTF_CF_TO_NS_BRIDGE_TRANSFER): Add.
(WTF_CF_TO_NS_BRIDGE_TRANSFER): Add.
- Helper macros for bridge_cast() and bridge_id_cast().
(WTF_DECLARE_CF_NS_BRIDGE_CAST): Add.
- Macro used to define bridge_cast() functions for all known
  toll-free-bridged types.
(WTF::bridge_cast): Add.
- Helper macro for toll-free-bridge casting from a known CF type
  to and from their Objective-C NS type.  Prevents ref churn for
  rvale RetainPtr<> objects.
(WTF::bridge_id_cast): Add.
- Helper macro for casting from any CFTypeRef to id.  Prevents
  ref churn for rvalue RetainPtr<> objects.
(WTF::checked_objc_cast):
- Simplified to match dynamic_objc_cast<> implementation in
  RetainPtr.h.

* wtf/cocoa/VectorCocoa.h:
(WTF::createNSArray):
- Change return type to match object.

Tools:

* DumpRenderTree/mac/DumpRenderTree.mm:
(dump):
- Use bridge_cast() to fix assignment.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
- Add RetainPtrARC.mm and TypeCastsCocoaARC.mm to the project.
* TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoa.mm:
- Update for dual compilation with MRR and with ARC.  Change
  -retainCount methods to CFGetRetainCount().
- Add @autoreleasepool blocks around groups of tests to find
  over-released bugs sooner (for future changes).
- Add more CFGetRetainCount() to catch unexpected auto-released
  objects as well as leaks.
(TestWebKitAPI::helloWorldCStringLength): Add.
(TestWebKitAPI::TEST):
- Add tests for bridge_cast() and bridge_id_cast().
- Remove invalid tests after changing RetainPtr<> move
  constructor to check types.
* TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoaARC.mm: Add.
- Run tests in TypeCastsCocoa.mm with ARC enabled.
* TestWebKitAPI/Tests/WTF/ns/RetainPtr.mm:
(TestWebKitAPI::TEST):
- Update for dual compilation with MRR and with ARC.  Change
  -retainCount methods to CFGetRetainCount().
- Make it possible to name tests differently for MRR vs. ARC
  using RETAIN_PTR_TEST_NAME macro.
* TestWebKitAPI/Tests/WTF/ns/RetainPtrARC.mm: Add.
- Run tests in RetainPtr.mm with ARC enabled.
* TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm:
(readFile):
- Use bridge_cast() to fix assignment.
- Drive-by fix to keep NSData out of autoreleasePool.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfRetainPtrh">trunk/Source/WTF/wtf/RetainPtr.h</a></li>
<li><a href="#trunkSourceWTFwtfcocoaTypeCastsCocoah">trunk/Source/WTF/wtf/cocoa/TypeCastsCocoa.h</a></li>
<li><a href="#trunkSourceWTFwtfcocoaVectorCocoah">trunk/Source/WTF/wtf/cocoa/VectorCocoa.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitSharedAPICocoaWKRemoteObjectCodermm">trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm</a></li>
<li><a href="#trunkSourceWebKitSharedRemoteLayerTreeRemoteLayerBackingStoremm">trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessmacWebDataListSuggestionsDropdownMach">trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h</a></li>
<li><a href="#trunkSourceWebKitLegacymacChangeLog">trunk/Source/WebKitLegacy/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitLegacymacPluginsWebBasePluginPackagemm">trunk/Source/WebKitLegacy/mac/Plugins/WebBasePluginPackage.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsDumpRenderTreemacDumpRenderTreemm">trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFcocoaTypeCastsCocoamm">trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoa.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFnsRetainPtrmm">trunk/Tools/TestWebKitAPI/Tests/WTF/ns/RetainPtr.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaQuickLookmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWTFcocoaTypeCastsCocoaARCmm">trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoaARC.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFnsRetainPtrARCmm">trunk/Tools/TestWebKitAPI/Tests/WTF/ns/RetainPtrARC.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog       2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WTF/ChangeLog  2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2021-10-03  David Kilzer  <ddkilzer@apple.com>
+
+        WTF::RetainPtr<> allows assignment of two pointer types that are not assignable
+        <https://webkit.org/b/230406>
+        <rdar://problem/83241893>
+
+        Reviewed by Darin Adler.
+
+        * wtf/RetainPtr.h:
+        (WTF::RetainPtr::RetainPtr):
+        (WTF::RetainPtr::checkType): Add.
+        - Add type check for move constructor.
+
+        * wtf/cocoa/TypeCastsCocoa.h:
+        - Change #include to #import.
+        (WTF_CF_TO_NS_BRIDGE_TRANSFER): Add.
+        (WTF_CF_TO_NS_BRIDGE_TRANSFER): Add.
+        - Helper macros for bridge_cast() and bridge_id_cast().
+        (WTF_DECLARE_CF_NS_BRIDGE_CAST): Add.
+        - Macro used to define bridge_cast() functions for all known
+          toll-free-bridged types.
+        (WTF::bridge_cast): Add.
+        - Helper macro for toll-free-bridge casting from a known CF type
+          to and from their Objective-C NS type.  Prevents ref churn for
+          rvale RetainPtr<> objects.
+        (WTF::bridge_id_cast): Add.
+        - Helper macro for casting from any CFTypeRef to id.  Prevents
+          ref churn for rvalue RetainPtr<> objects.
+        (WTF::checked_objc_cast):
+        - Simplified to match dynamic_objc_cast<> implementation in
+          RetainPtr.h.
+
+        * wtf/cocoa/VectorCocoa.h:
+        (WTF::createNSArray):
+        - Change return type to match object.
+
</ins><span class="cx"> 2021-10-03  Basuke Suzuki  <basuke.suzuki@sony.com>
</span><span class="cx"> 
</span><span class="cx">         Enable release log to stderr
</span></span></pre></div>
<a id="trunkSourceWTFwtfRetainPtrh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/RetainPtr.h (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/RetainPtr.h 2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WTF/wtf/RetainPtr.h    2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -90,7 +90,7 @@
</span><span class="cx">     template<typename U> RetainPtr(const RetainPtr<U>&);
</span><span class="cx"> 
</span><span class="cx">     constexpr RetainPtr(RetainPtr&& o) : m_ptr(toStorageType(o.leakRef())) { }
</span><del>-    template<typename U> constexpr RetainPtr(RetainPtr<U>&& o) : m_ptr(toStorageType(o.leakRef())) { }
</del><ins>+    template<typename U> constexpr RetainPtr(RetainPtr<U>&& o) : m_ptr(toStorageType(checkType(o.leakRef()))) { }
</ins><span class="cx"> 
</span><span class="cx">     // Hash table deleted values, which are only constructed and never copied or destroyed.
</span><span class="cx">     constexpr RetainPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { }
</span><span class="lines">@@ -138,6 +138,8 @@
</span><span class="cx">     enum AdoptTag { Adopt };
</span><span class="cx">     constexpr RetainPtr(PtrType ptr, AdoptTag) : m_ptr(toStorageType(ptr)) { }
</span><span class="cx"> 
</span><ins>+    static constexpr PtrType checkType(PtrType ptr) { return ptr; }
+
</ins><span class="cx">     static constexpr PtrType hashTableDeletedValue() { return reinterpret_cast<PtrType>(-1); }
</span><span class="cx"> 
</span><span class="cx"> #ifdef __OBJC__
</span></span></pre></div>
<a id="trunkSourceWTFwtfcocoaTypeCastsCocoah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/cocoa/TypeCastsCocoa.h (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/cocoa/TypeCastsCocoa.h      2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WTF/wtf/cocoa/TypeCastsCocoa.h 2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -25,24 +25,97 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><del>-#include <wtf/Assertions.h>
-#include <wtf/RetainPtr.h>
</del><ins>+#import <wtf/Assertions.h>
+#import <wtf/RetainPtr.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span><span class="cx"> 
</span><ins>+// Use bridge_cast() to convert between CF <-> NS types without ref churn.
+
+#if __has_feature(objc_arc)
+#define WTF_CF_TO_NS_BRIDGE_TRANSFER(type, value) ((__bridge_transfer type)value)
+#define WTF_NS_TO_CF_BRIDGE_TRANSFER(type, value) ((type)reinterpret_cast<uintptr_t>(value))
+#else
+#define WTF_CF_TO_NS_BRIDGE_TRANSFER(type, value) ((__bridge type)value)
+#define WTF_NS_TO_CF_BRIDGE_TRANSFER(type, value) ((__bridge type)value)
+#endif
+
+#define WTF_DECLARE_CF_NS_BRIDGE_CAST(CFClassName, NSClassName) \
+inline CFClassName##Ref bridge_cast(NSClassName *object) \
+{ \
+    return (__bridge CFClassName##Ref)object; \
+} \
+inline RetainPtr<CFClassName##Ref> bridge_cast(RetainPtr<NSClassName>&& object) \
+{ \
+    return adoptCF(WTF_NS_TO_CF_BRIDGE_TRANSFER(CFClassName##Ref, object.leakRef())); \
+} \
+inline NSClassName *bridge_cast(CFClassName##Ref object) \
+{ \
+    return (__bridge NSClassName *)object; \
+} \
+inline RetainPtr<NSClassName> bridge_cast(RetainPtr<CFClassName##Ref>&& object) \
+{ \
+    return adoptNS(WTF_CF_TO_NS_BRIDGE_TRANSFER(NSClassName *, object.leakRef())); \
+}
+
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFArray, NSArray)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFAttributedString, NSAttributedString)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFCharacterSet, NSCharacterSet)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFData, NSData)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFDate, NSDate)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFDictionary, NSDictionary)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFError, NSError)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFFileSecurity, NSFileSecurity)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFLocale, NSLocale)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFNull, NSNull)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFNumber, NSNumber)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFSet, NSSet)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFString, NSString)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFTimeZone, NSTimeZone)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFURL, NSURL)
+
+inline NSNumber *bridge_cast(CFBooleanRef object)
+{
+    return (__bridge NSNumber *)object;
+}
+inline RetainPtr<NSNumber> bridge_cast(RetainPtr<CFBooleanRef>&& object)
+{
+    return adoptNS(WTF_CF_TO_NS_BRIDGE_TRANSFER(NSNumber *, object.leakRef()));
+}
+
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFMutableArray, NSMutableArray)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFMutableAttributedString, NSMutableAttributedString)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFMutableData, NSMutableData)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFMutableDictionary, NSMutableDictionary)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFMutableSet, NSMutableSet)
+WTF_DECLARE_CF_NS_BRIDGE_CAST(CFMutableString, NSMutableString)
+
+// Use bridge_id_cast to convert from CF -> id without ref churn.
+
+inline id bridge_id_cast(CFTypeRef object)
+{
+    return (__bridge id)object;
+}
+
+inline RetainPtr<id> bridge_id_cast(RetainPtr<CFTypeRef>&& object)
+{
+    return adoptNS(WTF_CF_TO_NS_BRIDGE_TRANSFER(id, object.leakRef()));
+}
+
+#undef WTF_DECLARE_CF_NS_BRIDGE_CAST
+#undef WTF_NS_TO_CF_BRIDGE_TRANSFER
+#undef WTF_CF_TO_NS_BRIDGE_TRANSFER
+
</ins><span class="cx"> // Use checked_objc_cast<> instead of dynamic_objc_cast<> when a specific NS type is required.
</span><span class="cx"> 
</span><span class="cx"> template<typename T> T* checked_objc_cast(id object)
</span><span class="cx"> {
</span><del>-    using ValueType = std::remove_pointer_t<T>;
-    using PtrType = ValueType*;
-
</del><span class="cx">     if (!object)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION([object isKindOfClass:[ValueType class]]);
</del><ins>+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION([object isKindOfClass:[T class]]);
</ins><span class="cx"> 
</span><del>-    return reinterpret_cast<PtrType>(object);
</del><ins>+    return reinterpret_cast<T*>(object);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // Use dynamic_objc_cast<> instead of checked_objc_cast<> when actively checking NS types,
</span><span class="lines">@@ -60,4 +133,6 @@
</span><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span><span class="cx"> 
</span><ins>+using WTF::bridge_cast;
+using WTF::bridge_id_cast;
</ins><span class="cx"> using WTF::checked_objc_cast;
</span></span></pre></div>
<a id="trunkSourceWTFwtfcocoaVectorCocoah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/cocoa/VectorCocoa.h (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/cocoa/VectorCocoa.h 2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WTF/wtf/cocoa/VectorCocoa.h    2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -47,13 +47,13 @@
</span><span class="cx"> //
</span><span class="cx"> //    std::optional<VectorElementType> makeVectorElement(const VectorElementType*, id arrayElement);
</span><span class="cx"> 
</span><del>-template<typename CollectionType> RetainPtr<NSArray> createNSArray(CollectionType&&);
</del><ins>+template<typename CollectionType> RetainPtr<NSMutableArray> createNSArray(CollectionType&&);
</ins><span class="cx"> template<typename VectorElementType> Vector<VectorElementType> makeVector(NSArray *);
</span><span class="cx"> 
</span><span class="cx"> // This overload of createNSArray takes a function to map each vector element to an Objective-C object.
</span><span class="cx"> // The map function has the same interface as the makeNSArrayElement function above, but can be any
</span><span class="cx"> // function including a lambda, a function-like object, or Function<>.
</span><del>-template<typename CollectionType, typename MapFunctionType> RetainPtr<NSArray> createNSArray(CollectionType&&, MapFunctionType&&);
</del><ins>+template<typename CollectionType, typename MapFunctionType> RetainPtr<NSMutableArray> createNSArray(CollectionType&&, MapFunctionType&&);
</ins><span class="cx"> 
</span><span class="cx"> // This overload of makeVector takes a function to map each Objective-C object to a vector element.
</span><span class="cx"> // Currently, the map function needs to return an Optional.
</span><span class="lines">@@ -67,7 +67,7 @@
</span><span class="cx">         [array addObject:value];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-template<typename CollectionType> RetainPtr<NSArray> createNSArray(CollectionType&& collection)
</del><ins>+template<typename CollectionType> RetainPtr<NSMutableArray> createNSArray(CollectionType&& collection)
</ins><span class="cx"> {
</span><span class="cx">     auto array = adoptNS([[NSMutableArray alloc] initWithCapacity:std::size(collection)]);
</span><span class="cx">     for (auto&& element : collection)
</span><span class="lines">@@ -75,7 +75,7 @@
</span><span class="cx">     return array;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-template<typename CollectionType, typename MapFunctionType> RetainPtr<NSArray> createNSArray(CollectionType&& collection, MapFunctionType&& function)
</del><ins>+template<typename CollectionType, typename MapFunctionType> RetainPtr<NSMutableArray> createNSArray(CollectionType&& collection, MapFunctionType&& function)
</ins><span class="cx"> {
</span><span class="cx">     auto array = adoptNS([[NSMutableArray alloc] initWithCapacity:std::size(collection)]);
</span><span class="cx">     for (auto&& element : collection)
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WebKit/ChangeLog       2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2021-10-03  David Kilzer  <ddkilzer@apple.com>
+
+        WTF::RetainPtr<> allows assignment of two pointer types that are not assignable
+        <https://webkit.org/b/230406>
+        <rdar://problem/83241893>
+
+        Reviewed by Darin Adler.
+
+        * Shared/API/Cocoa/WKRemoteObjectCoder.mm:
+        (transformTrustToData):
+        - Change return type to match object.
+        (encodeError):
+        - Use bridge_cast() to fix assignment.
+        (transformDataToTrust):
+        - Change return type to match object.
+        (decodeError):
+        - Use bridge_id_cast() to fix assignment.
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
+        (WebKit::RemoteLayerBackingStore::applyBackingStoreToLayer):
+        - Use bridge_id_cast() to fix assignment.
+
+        * UIProcess/mac/WebDataListSuggestionsDropdownMac.h:
+        - Use correct name of class that actually exists.
+
</ins><span class="cx"> 2021-10-03  Simon Fraser  <simon.fraser@apple.com>
</span><span class="cx"> 
</span><span class="cx">         WebCore::Length incorrectly uses memcpy() for copy constructors/operator and IPC encoding/decoding
</span></span></pre></div>
<a id="trunkSourceWebKitSharedAPICocoaWKRemoteObjectCodermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm      2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm 2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx"> #import <wtf/Scope.h>
</span><span class="cx"> #import <wtf/SetForScope.h>
</span><ins>+#import <wtf/cocoa/TypeCastsCocoa.h>
</ins><span class="cx"> #import <wtf/text/CString.h>
</span><span class="cx"> 
</span><span class="cx"> static const char* const classNameKey = "$class";
</span><span class="lines">@@ -332,7 +333,7 @@
</span><span class="cx">     return dataArray;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static RetainPtr<NSData> transformTrustToData(SecTrustRef trust)
</del><ins>+static RetainPtr<CFDataRef> transformTrustToData(SecTrustRef trust)
</ins><span class="cx"> {
</span><span class="cx">     if (CFGetTypeID(trust) != SecTrustGetTypeID())
</span><span class="cx">         [NSException raise:NSInvalidArgumentException format:@"Error encoding invalid SecTrustRef"];
</span><span class="lines">@@ -363,7 +364,7 @@
</span><span class="cx">     if (id trust = error.userInfo[peerTrustKey]) {
</span><span class="cx">         if (!copy)
</span><span class="cx">             copy = adoptNS([error.userInfo mutableCopy]);
</span><del>-        copy.get()[peerTrustKey] = transformTrustToData((SecTrustRef)trust).get();
</del><ins>+        copy.get()[peerTrustKey] = bridge_cast(transformTrustToData((SecTrustRef)trust).get());
</ins><span class="cx">     }
</span><span class="cx">     if (!copy)
</span><span class="cx">         [error encodeWithCoder:encoder];
</span><span class="lines">@@ -385,7 +386,7 @@
</span><span class="cx">     return array;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static RetainPtr<id> transformDataToTrust(NSData *data)
</del><ins>+static RetainPtr<SecTrustRef> transformDataToTrust(NSData *data)
</ins><span class="cx"> {
</span><span class="cx">     if (CFGetTypeID(data) != CFDataGetTypeID())
</span><span class="cx">         [NSException raise:NSInvalidUnarchiveOperationException format:@"Invalid SecTrustRef data %@", NSStringFromClass([data class])];
</span><span class="lines">@@ -407,7 +408,7 @@
</span><span class="cx">     if (NSData *trust = error.get().userInfo[peerTrustKey]) {
</span><span class="cx">         if (!copy)
</span><span class="cx">             copy = adoptNS([error.get().userInfo mutableCopy]);
</span><del>-        copy.get()[peerTrustKey] = transformDataToTrust(trust).get();
</del><ins>+        copy.get()[peerTrustKey] = bridge_id_cast(transformDataToTrust(trust).get());
</ins><span class="cx">     }
</span><span class="cx">     if (!copy)
</span><span class="cx">         return error;
</span></span></pre></div>
<a id="trunkSourceWebKitSharedRemoteLayerTreeRemoteLayerBackingStoremm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm    2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm       2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx"> #import <WebCore/WebLayer.h>
</span><span class="cx"> #import <mach/mach_port.h>
</span><span class="cx"> #import <pal/spi/cocoa/QuartzCoreSPI.h>
</span><ins>+#import <wtf/cocoa/TypeCastsCocoa.h>
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
</span><span class="cx"> #import <WebKitAdditions/CGDisplayListImageBufferAdditions.h>
</span><span class="lines">@@ -432,8 +433,7 @@
</span><span class="cx">     WTF::switchOn(*m_bufferHandle,
</span><span class="cx">         [&] (ShareableBitmap::Handle& handle) {
</span><span class="cx">             ASSERT(m_type == Type::Bitmap);
</span><del>-            auto bitmap = ShareableBitmap::create(handle);
-            contents = bitmap->makeCGImageCopy();
</del><ins>+            contents = bridge_id_cast(ShareableBitmap::create(handle)->makeCGImageCopy());
</ins><span class="cx">         },
</span><span class="cx">         [&] (MachSendRight& machSendRight) {
</span><span class="cx">             ASSERT(m_type == Type::IOSurface);
</span><span class="lines">@@ -444,7 +444,7 @@
</span><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">             case RemoteLayerBackingStore::LayerContentsType::CAMachPort:
</span><del>-                contents = adoptCF(CAMachPortCreate(machSendRight.leakSendRight()));
</del><ins>+                contents = bridge_id_cast(adoptCF(CAMachPortCreate(machSendRight.leakSendRight())));
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessmacWebDataListSuggestionsDropdownMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h    2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.h       2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -30,7 +30,7 @@
</span><span class="cx"> #import "WebDataListSuggestionsDropdown.h"
</span><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx"> 
</span><del>-OBJC_CLASS WKDataListSuggestionsView;
</del><ins>+OBJC_CLASS WKDataListSuggestionsController;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx">     void selectOption();
</span><span class="cx"> 
</span><span class="cx">     NSView *m_view;
</span><del>-    RetainPtr<WKDataListSuggestionsView> m_dropdownUI;
</del><ins>+    RetainPtr<WKDataListSuggestionsController> m_dropdownUI;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKitLegacymacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKitLegacy/mac/ChangeLog  2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog     2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2021-10-03  David Kilzer  <ddkilzer@apple.com>
+
+        WTF::RetainPtr<> allows assignment of two pointer types that are not assignable
+        <https://webkit.org/b/230406>
+        <rdar://problem/83241893>
+
+        Reviewed by Darin Adler.
+
+        * Plugins/WebBasePluginPackage.mm:
+        (+[WebBasePluginPackage pluginWithPath:]):
+        - Use explicit type with RetainPtr<> to match return type.
+
</ins><span class="cx"> 2021-10-01  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Drop support for macOS < 10.15
</span></span></pre></div>
<a id="trunkSourceWebKitLegacymacPluginsWebBasePluginPackagemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKitLegacy/mac/Plugins/WebBasePluginPackage.mm (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKitLegacy/mac/Plugins/WebBasePluginPackage.mm    2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Source/WebKitLegacy/mac/Plugins/WebBasePluginPackage.mm       2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -67,8 +67,7 @@
</span><span class="cx"> 
</span><span class="cx"> + (WebBasePluginPackage *)pluginWithPath:(NSString *)pluginPath
</span><span class="cx"> {
</span><del>-    
-    auto pluginPackage = adoptNS([[WebPluginPackage alloc] initWithPath:pluginPath]);
</del><ins>+    RetainPtr<WebBasePluginPackage> pluginPackage = adoptNS([[WebPluginPackage alloc] initWithPath:pluginPath]);
</ins><span class="cx"> 
</span><span class="cx">     if (!pluginPackage) {
</span><span class="cx"> #if ENABLE(NETSCAPE_PLUGIN_API)
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Tools/ChangeLog       2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2021-10-03  David Kilzer  <ddkilzer@apple.com>
+
+        WTF::RetainPtr<> allows assignment of two pointer types that are not assignable
+        <https://webkit.org/b/230406>
+        <rdar://problem/83241893>
+
+        Reviewed by Darin Adler.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (dump):
+        - Use bridge_cast() to fix assignment.
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        - Add RetainPtrARC.mm and TypeCastsCocoaARC.mm to the project.
+        * TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoa.mm:
+        - Update for dual compilation with MRR and with ARC.  Change
+          -retainCount methods to CFGetRetainCount().
+        - Add @autoreleasepool blocks around groups of tests to find
+          over-released bugs sooner (for future changes).
+        - Add more CFGetRetainCount() to catch unexpected auto-released
+          objects as well as leaks.
+        (TestWebKitAPI::helloWorldCStringLength): Add.
+        (TestWebKitAPI::TEST):
+        - Add tests for bridge_cast() and bridge_id_cast().
+        - Remove invalid tests after changing RetainPtr<> move
+          constructor to check types.
+        * TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoaARC.mm: Add.
+        - Run tests in TypeCastsCocoa.mm with ARC enabled.
+        * TestWebKitAPI/Tests/WTF/ns/RetainPtr.mm:
+        (TestWebKitAPI::TEST):
+        - Update for dual compilation with MRR and with ARC.  Change
+          -retainCount methods to CFGetRetainCount().
+        - Make it possible to name tests differently for MRR vs. ARC
+          using RETAIN_PTR_TEST_NAME macro.
+        * TestWebKitAPI/Tests/WTF/ns/RetainPtrARC.mm: Add.
+        - Run tests in RetainPtr.mm with ARC enabled.
+        * TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm:
+        (readFile):
+        - Use bridge_cast() to fix assignment.
+        - Drive-by fix to keep NSData out of autoreleasePool.
+
</ins><span class="cx"> 2021-10-03  Myles C. Maxfield  <mmaxfield@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Some layout tests with Japanese glyphs fail if Japanese is included in the system "Preferred Languages" settings
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacDumpRenderTreemm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm 2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm    2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -107,6 +107,7 @@
</span><span class="cx"> #import <wtf/UniqueArray.h>
</span><span class="cx"> #import <wtf/WorkQueue.h>
</span><span class="cx"> #import <wtf/cocoa/CrashReporter.h>
</span><ins>+#import <wtf/cocoa/TypeCastsCocoa.h>
</ins><span class="cx"> #import <wtf/cocoa/VectorCocoa.h>
</span><span class="cx"> #import <wtf/text/StringBuilder.h>
</span><span class="cx"> #import <wtf/text/WTFString.h>
</span><span class="lines">@@ -1620,11 +1621,11 @@
</span><span class="cx">             resultMimeType = @"application/pdf";
</span><span class="cx">         } else if (gTestRunner->dumpDOMAsWebArchive()) {
</span><span class="cx">             WebArchive *webArchive = [[mainFrame DOMDocument] webArchive];
</span><del>-            resultString = WebCoreTestSupport::createXMLStringFromWebArchiveData((__bridge CFDataRef)[webArchive data]);
</del><ins>+            resultString = bridge_cast(WebCoreTestSupport::createXMLStringFromWebArchiveData(bridge_cast([webArchive data])));
</ins><span class="cx">             resultMimeType = @"application/x-webarchive";
</span><span class="cx">         } else if (gTestRunner->dumpSourceAsWebArchive()) {
</span><span class="cx">             WebArchive *webArchive = [[mainFrame dataSource] webArchive];
</span><del>-            resultString = WebCoreTestSupport::createXMLStringFromWebArchiveData((__bridge CFDataRef)[webArchive data]);
</del><ins>+            resultString = bridge_cast(WebCoreTestSupport::createXMLStringFromWebArchiveData(bridge_cast([webArchive data])));
</ins><span class="cx">             resultMimeType = @"application/x-webarchive";
</span><span class="cx">         } else if (gTestRunner->isPrinting())
</span><span class="cx">             resultString = [mainFrame renderTreeAsExternalRepresentationForPrinting];
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj   2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -262,6 +262,7 @@
</span><span class="cx">          41E67A8525D16E83007B0A4C /* STUNMessageParsingTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41E67A8425D16E83007B0A4C /* STUNMessageParsingTest.cpp */; };
</span><span class="cx">          44077BB123144B5000179E2D /* DataDetectorsTestIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */; };
</span><span class="cx">          4433A396208044140091ED57 /* SynchronousTimeoutTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */; };
</span><ins>+               44652CB726FCD405005EC272 /* TypeCastsCocoaARC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44652CB626FCD405005EC272 /* TypeCastsCocoaARC.mm */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
</ins><span class="cx">           448110C2253F40300097FC33 /* WebPreferencesTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 448110C1253F40240097FC33 /* WebPreferencesTest.mm */; };
</span><span class="cx">          44817A2F1F0486BF00003810 /* WKRequestActivatedElementInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */; };
</span><span class="cx">          448D7E471EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */; };
</span><span class="lines">@@ -269,6 +270,7 @@
</span><span class="cx">          44C2FBE225E7592C00ABC72F /* WKAppHighlights.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44C2FBE125E7592C00ABC72F /* WKAppHighlights.mm */; };
</span><span class="cx">          44CDE4D426EE6E4A009F6ACB /* TypeCastsCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44CDE4D326EE6E41009F6ACB /* TypeCastsCocoa.mm */; };
</span><span class="cx">          44CF31FD249941E8009CB6CB /* ContextMenuAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 44CF31FB24993F66009CB6CB /* ContextMenuAction.cpp */; };
</span><ins>+               44D5008E26FE9ED6000EB12F /* RetainPtrARC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44D5008D26FE9ED6000EB12F /* RetainPtrARC.mm */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
</ins><span class="cx">           4612C2B9210A6ACE00B788A6 /* LoadFileThenReload.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4612C2B8210A6ABF00B788A6 /* LoadFileThenReload.mm */; };
</span><span class="cx">          4628C8E92367ABD100B073F0 /* WKSecurityOrigin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4628C8E82367ABBC00B073F0 /* WKSecurityOrigin.cpp */; };
</span><span class="cx">          46397B951DC2C850009A78AE /* DOMNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46397B941DC2C850009A78AE /* DOMNode.mm */; };
</span><span class="lines">@@ -2098,6 +2100,7 @@
</span><span class="cx">          44077BB0231449D200179E2D /* DataDetectorsTestIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DataDetectorsTestIOS.mm; sourceTree = "<group>"; };
</span><span class="cx">          442BBF681C91CAD90017087F /* RefLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefLogger.cpp; sourceTree = "<group>"; };
</span><span class="cx">          4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SynchronousTimeoutTests.mm; sourceTree = "<group>"; };
</span><ins>+               44652CB626FCD405005EC272 /* TypeCastsCocoaARC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TypeCastsCocoaARC.mm; sourceTree = "<group>"; };
</ins><span class="cx">           448110C1253F40240097FC33 /* WebPreferencesTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPreferencesTest.mm; sourceTree = "<group>"; };
</span><span class="cx">          44817A2E1F0486BF00003810 /* WKRequestActivatedElementInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKRequestActivatedElementInfo.mm; sourceTree = "<group>"; };
</span><span class="cx">          448D7E451EA6C55500ECC756 /* EnvironmentUtilitiesTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EnvironmentUtilitiesTest.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -2105,6 +2108,7 @@
</span><span class="cx">          44C2FBE125E7592C00ABC72F /* WKAppHighlights.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKAppHighlights.mm; sourceTree = "<group>"; };
</span><span class="cx">          44CDE4D326EE6E41009F6ACB /* TypeCastsCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TypeCastsCocoa.mm; sourceTree = "<group>"; };
</span><span class="cx">          44CF31FB24993F66009CB6CB /* ContextMenuAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContextMenuAction.cpp; sourceTree = "<group>"; };
</span><ins>+               44D5008D26FE9ED6000EB12F /* RetainPtrARC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RetainPtrARC.mm; path = ns/RetainPtrARC.mm; sourceTree = "<group>"; };
</ins><span class="cx">           4612C2B8210A6ABF00B788A6 /* LoadFileThenReload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LoadFileThenReload.mm; sourceTree = "<group>"; };
</span><span class="cx">          4628C8E82367ABBC00B073F0 /* WKSecurityOrigin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKSecurityOrigin.cpp; sourceTree = "<group>"; };
</span><span class="cx">          46397B941DC2C850009A78AE /* DOMNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMNode.mm; sourceTree = "<group>"; };
</span><span class="lines">@@ -4284,6 +4288,7 @@
</span><span class="cx">                  children = (
</span><span class="cx">                          1ADAD14E1D77A9F600212586 /* BlockPtr.mm */,
</span><span class="cx">                          BC029B1B1486B25900817DA9 /* RetainPtr.mm */,
</span><ins>+                               44D5008D26FE9ED6000EB12F /* RetainPtrARC.mm */,
</ins><span class="cx">                   );
</span><span class="cx">                  name = ns;
</span><span class="cx">                  sourceTree = "<group>";
</span><span class="lines">@@ -4998,6 +5003,7 @@
</span><span class="cx">                          1C4616A626BB172F00F8C9F6 /* TextStreamCocoa.cpp */,
</span><span class="cx">                          1C46169E26BA510700F8C9F6 /* TextStreamCocoa.mm */,
</span><span class="cx">                          44CDE4D326EE6E41009F6ACB /* TypeCastsCocoa.mm */,
</span><ins>+                               44652CB626FCD405005EC272 /* TypeCastsCocoaARC.mm */,
</ins><span class="cx">                           E3C21A7B21B25CA2003B31A3 /* URLExtras.mm */,
</span><span class="cx">                  );
</span><span class="cx">                  path = cocoa;
</span><span class="lines">@@ -5316,6 +5322,7 @@
</span><span class="cx">                          7C83DF161D0A590C00FEBCF3 /* RefPtr.cpp in Sources */,
</span><span class="cx">                          44AC8BC621D0245A00CAFB34 /* RetainPtr.cpp in Sources */,
</span><span class="cx">                          7C83DF241D0A590C00FEBCF3 /* RetainPtr.mm in Sources */,
</span><ins>+                               44D5008E26FE9ED6000EB12F /* RetainPtrARC.mm in Sources */,
</ins><span class="cx">                           E355A6322615718F001C1129 /* RobinHoodHashMap.cpp in Sources */,
</span><span class="cx">                          E355A63026157174001C1129 /* RobinHoodHashSet.cpp in Sources */,
</span><span class="cx">                          7C83DF051D0A590C00FEBCF3 /* RunLoop.cpp in Sources */,
</span><span class="lines">@@ -5348,6 +5355,7 @@
</span><span class="cx">                          5311BD5E1EA9490E00525281 /* ThreadMessages.cpp in Sources */,
</span><span class="cx">                          0F2C20B81DCD545000542D9E /* Time.cpp in Sources */,
</span><span class="cx">                          44CDE4D426EE6E4A009F6ACB /* TypeCastsCocoa.mm in Sources */,
</span><ins>+                               44652CB726FCD405005EC272 /* TypeCastsCocoaARC.mm in Sources */,
</ins><span class="cx">                           E324A6F02041C82000A76593 /* UniqueArray.cpp in Sources */,
</span><span class="cx">                          E3A1E78221B25B7A008C6007 /* URL.cpp in Sources */,
</span><span class="cx">                          E3C21A7C21B25CA2003B31A3 /* URLExtras.mm in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFcocoaTypeCastsCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoa.mm (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoa.mm      2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoa.mm 2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -27,6 +27,10 @@
</span><span class="cx"> 
</span><span class="cx"> #import <wtf/StdLibExtras.h>
</span><span class="cx"> 
</span><ins>+#if __has_feature(objc_arc) && !defined(TypeCastsCocoa)
+#error This tests TypeCastsCocoa.h with ARC disabled.
+#endif
+
</ins><span class="cx"> @interface MyObjectSubtype : NSObject
</span><span class="cx"> @end
</span><span class="cx"> 
</span><span class="lines">@@ -37,24 +41,98 @@
</span><span class="cx"> 
</span><span class="cx"> using namespace WTF;
</span><span class="cx"> 
</span><ins>+static const char* helloWorldCString = "Hello world";
+static size_t helloWorldCStringLength()
+{
+    static auto length = strlen(helloWorldCString);
+    return length;
+}
+
+TEST(TypeCastsCocoa, bridge_cast)
+{
+    @autoreleasepool {
+        auto objectNS = adoptNS([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
+
+        auto objectCF = bridge_cast(WTFMove(objectNS));
+        auto objectCFPtr = reinterpret_cast<uintptr_t>(objectCF.get());
+        EXPECT_EQ(nil, objectNS.get());
+        EXPECT_EQ(objectNSPtr, objectCFPtr);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectCFPtr));
+
+        objectNS = bridge_cast(WTFMove(objectCF));
+        objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(NULL, objectCF.get());
+        EXPECT_EQ(objectCFPtr, objectNSPtr);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
+    }
+
+    @autoreleasepool {
+        auto objectCF = adoptCF(CFStringCreateWithBytes(NULL, (const UInt8*)helloWorldCString, helloWorldCStringLength(), kCFStringEncodingUTF8, false));
+        auto objectCFPtr = reinterpret_cast<uintptr_t>(objectCF.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectCFPtr));
+
+        auto objectNS = bridge_cast(WTFMove(objectCF));
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(NULL, objectCF.get());
+        EXPECT_EQ(objectCFPtr, objectNSPtr);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
+
+        objectCF = bridge_cast(WTFMove(objectNS));
+        objectCFPtr = reinterpret_cast<uintptr_t>(objectCF.get());
+        EXPECT_EQ(nil, objectNS.get());
+        EXPECT_EQ(objectNSPtr, objectCFPtr);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectCFPtr));
+    }
+}
+
+TEST(TypeCastsCocoa, bridge_id_cast)
+{
+    @autoreleasepool {
+        RetainPtr<CFTypeRef> objectCF;
+        auto objectID = bridge_id_cast(WTFMove(objectCF));
+        EXPECT_EQ(NULL, objectCF.get());
+        EXPECT_EQ(nil, objectID.get());
+    }
+
+    @autoreleasepool {
+        auto objectCF = adoptCF(CFStringCreateWithBytes(NULL, (const UInt8*)helloWorldCString, helloWorldCStringLength(), kCFStringEncodingUTF8, false));
+        auto objectCFPtr = reinterpret_cast<uintptr_t>(objectCF.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectCFPtr));
+
+        auto objectID = bridge_id_cast(WTFMove(objectCF));
+        auto objectIDPtr = reinterpret_cast<uintptr_t>(objectID.get());
+        EXPECT_EQ(NULL, objectCF.get());
+        EXPECT_EQ(objectCFPtr, objectIDPtr);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectIDPtr));
+    }
+}
+
</ins><span class="cx"> TEST(TypeCastsCocoa, checked_objc_cast)
</span><span class="cx"> {
</span><span class="cx">     EXPECT_EQ(nil, checked_objc_cast<NSString>(nil));
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS(reinterpret_cast<id>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        EXPECT_EQ(object.get(), checked_objc_cast<NSString>(object.get()));
-        EXPECT_EQ(object.get(), checked_objc_cast<NSObject>(object.get()));
</del><ins>+    @autoreleasepool {
+        auto objectNS = adoptNS((id)[[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(objectNS.get(), checked_objc_cast<NSString>((__bridge id)(CFTypeRef)objectNSPtr));
+        EXPECT_EQ(objectNS.get(), checked_objc_cast<NSObject>((__bridge id)(CFTypeRef)objectNSPtr));
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS(reinterpret_cast<NSObject *>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        EXPECT_EQ(object.get(), checked_objc_cast<NSString>(object.get()));
</del><ins>+    @autoreleasepool {
+        auto objectNS = adoptNS((NSObject *)[[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(objectNS.get(), checked_objc_cast<NSString>((__bridge NSObject *)(CFTypeRef)objectNSPtr));
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS([[NSString alloc] initWithFormat:@"%s", "Hello world"]);
-        EXPECT_EQ(object.get(), checked_objc_cast<NSObject>(object.get()));
</del><ins>+    @autoreleasepool {
+        auto objectNS = adoptNS([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(objectNS.get(), checked_objc_cast<NSObject>((__bridge NSString *)(CFTypeRef)objectNSPtr));
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -62,40 +140,50 @@
</span><span class="cx"> {
</span><span class="cx">     EXPECT_EQ(nil, dynamic_objc_cast<NSString>(nil));
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS(reinterpret_cast<id>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        EXPECT_EQ(object.get(), dynamic_objc_cast<NSString>(object.get()));
-        EXPECT_EQ(object.get(), dynamic_objc_cast<NSObject>(object.get()));
-        EXPECT_EQ(nil, dynamic_objc_cast<NSArray>(object.get()));
</del><ins>+    @autoreleasepool {
+        auto objectNS = adoptNS<id>([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(objectNS.get(), dynamic_objc_cast<NSString>(objectNS.get()));
+        EXPECT_EQ(objectNS.get(), dynamic_objc_cast<NSObject>(objectNS.get()));
+        EXPECT_EQ(nil, dynamic_objc_cast<NSArray>(objectNS.get()));
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS(reinterpret_cast<NSObject *>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        EXPECT_EQ(object.get(), dynamic_objc_cast<NSString>(object.get()));
-        EXPECT_EQ(nil, dynamic_objc_cast<NSArray>(object.get()));
</del><ins>+    @autoreleasepool {
+        auto objectNS = adoptNS<NSObject *>([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(objectNS.get(), dynamic_objc_cast<NSString>(objectNS.get()));
+        EXPECT_EQ(nil, dynamic_objc_cast<NSArray>(objectNS.get()));
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS([[NSString alloc] initWithFormat:@"%s", "Hello world"]);
-        EXPECT_EQ(object.get(), dynamic_objc_cast<NSObject>(object.get()));
-        EXPECT_EQ(nil, dynamic_objc_cast<NSArray>(object.get()));
</del><ins>+    @autoreleasepool {
+        auto objectNS = adoptNS([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(objectNS.get(), dynamic_objc_cast<NSObject>(objectNS.get()));
+        EXPECT_EQ(nil, dynamic_objc_cast<NSArray>(objectNS.get()));
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS(reinterpret_cast<id>([[NSObject alloc] init]));
-        EXPECT_EQ(object.get(), dynamic_objc_cast<NSObject>(object.get()));
-        EXPECT_EQ(nil, dynamic_objc_cast<MyObjectSubtype>(object.get()));
</del><ins>+    @autoreleasepool {
+        auto objectID = adoptNS<id>([[NSObject alloc] init]);
+        auto objectIDPtr = reinterpret_cast<uintptr_t>(objectID.get());
+        EXPECT_EQ(objectID.get(), dynamic_objc_cast<NSObject>(objectID.get()));
+        EXPECT_EQ(nil, dynamic_objc_cast<MyObjectSubtype>(objectID.get()));
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectIDPtr));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS([[NSObject alloc] init]);
-        EXPECT_EQ(nil, dynamic_objc_cast<MyObjectSubtype>(object.get()));
</del><ins>+    @autoreleasepool {
+        auto objectNS = adoptNS([[NSObject alloc] init]);
+        auto objectNSPtr = reinterpret_cast<uintptr_t>(objectNS.get());
+        EXPECT_EQ(nil, dynamic_objc_cast<MyObjectSubtype>(objectNS.get()));
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectNSPtr));
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(TypeCastsCocoa, dynamic_ns_cast_RetainPtr)
</del><ins>+TEST(TypeCastsCocoa, dynamic_objc_cast_RetainPtr)
</ins><span class="cx"> {
</span><del>-    {
</del><ins>+    @autoreleasepool {
</ins><span class="cx">         RetainPtr<NSString> object;
</span><span class="cx">         auto objectCast = dynamic_objc_cast<NSString>(WTFMove(object));
</span><span class="cx">         EXPECT_EQ(nil, object.get());
</span><span class="lines">@@ -102,94 +190,68 @@
</span><span class="cx">         EXPECT_EQ(nil, objectCast.get());
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS(reinterpret_cast<id>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        id objectPtr = object.get();
</del><ins>+    @autoreleasepool {
+        auto object = adoptNS<id>([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectPtr = reinterpret_cast<uintptr_t>(object.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr));
+
</ins><span class="cx">         auto objectCast = dynamic_objc_cast<NSString>(WTFMove(object));
</span><ins>+        auto objectCastPtr = reinterpret_cast<uintptr_t>(objectCast.get());
</ins><span class="cx">         EXPECT_EQ(nil, object.get());
</span><del>-        EXPECT_EQ(objectPtr, objectCast.get());
-        objectPtr = nil; // For ARC.
-        EXPECT_EQ(1U, [objectCast retainCount]);
</del><ins>+        EXPECT_EQ(objectPtr, objectCastPtr);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectCastPtr));
</ins><span class="cx"> 
</span><del>-        object = adoptNS(reinterpret_cast<id>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        objectPtr = object.get();
</del><ins>+        object = adoptNS<id>([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        objectPtr = reinterpret_cast<uintptr_t>(object.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr));
+
</ins><span class="cx">         auto objectCast2 = dynamic_objc_cast<NSObject>(WTFMove(object));
</span><ins>+        auto objectCastPtr2 = reinterpret_cast<uintptr_t>(objectCast2.get());
</ins><span class="cx">         EXPECT_EQ(nil, object.get());
</span><del>-        EXPECT_EQ(objectPtr, objectCast2.get());
-        objectPtr = nil; // For ARC.
-        EXPECT_EQ(1U, [objectCast2 retainCount]);
</del><ins>+        EXPECT_EQ(objectPtr, objectCastPtr2);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectCastPtr2));
</ins><span class="cx"> 
</span><del>-        object = adoptNS(reinterpret_cast<id>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        objectPtr = object.get();
-        auto objectCast3 = dynamic_objc_cast<NSArray>(WTFMove(object));
-        EXPECT_EQ(objectPtr, object.get());
-        EXPECT_EQ(nil, objectCast3.get());
-        objectPtr = nil; // For ARC.
-        EXPECT_EQ(1U, [object retainCount]);
</del><ins>+        object = adoptNS<id>([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        objectPtr = reinterpret_cast<uintptr_t>(object.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr));
+
+        auto objectCastBad = dynamic_objc_cast<NSArray>(WTFMove(object));
+        auto objectPtr2 = reinterpret_cast<uintptr_t>(object.get());
+        EXPECT_EQ(objectPtr, objectPtr2);
+        EXPECT_EQ(nil, objectCastBad.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr2));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS(reinterpret_cast<NSObject *>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        id objectPtr = object.get();
-        auto objectCast = dynamic_objc_cast<NSString>(WTFMove(object));
-        EXPECT_EQ(nil, object.get());
-        EXPECT_EQ(objectPtr, objectCast.get());
-        objectPtr = nil;
-        EXPECT_EQ(1U, [objectCast retainCount]);
</del><ins>+    @autoreleasepool {
+        auto object = adoptNS([[NSString alloc] initWithFormat:@"%s", helloWorldCString]);
+        auto objectPtr = reinterpret_cast<uintptr_t>(object.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr));
</ins><span class="cx"> 
</span><del>-        object = adoptNS(reinterpret_cast<NSObject *>([[NSString alloc] initWithFormat:@"%s", "Hello world"]));
-        objectPtr = object.get();
-        auto objectCast2 = dynamic_objc_cast<NSArray>(WTFMove(object));
-        EXPECT_EQ(objectPtr, object.get());
-        EXPECT_EQ(nil, objectCast2.get());
-        objectPtr = nil;
-        EXPECT_EQ(1U, [object retainCount]);
-    }
-
-    {
-        auto object = adoptNS([[NSString alloc] initWithFormat:@"%s", "Hello world"]);
-        id objectPtr = object.get();
</del><span class="cx">         auto objectCast = dynamic_objc_cast<NSObject>(WTFMove(object));
</span><ins>+        auto objectCastPtr = reinterpret_cast<uintptr_t>(objectCast.get());
</ins><span class="cx">         EXPECT_EQ(nil, object.get());
</span><del>-        EXPECT_EQ(objectPtr, objectCast.get());
-        objectPtr = nil;
-        EXPECT_EQ(1U, [objectCast retainCount]);
-
-        object = adoptNS([[NSString alloc] initWithFormat:@"%s", "Hello world"]);
-        objectPtr = object.get();
-        auto objectCast2 = dynamic_objc_cast<NSArray>(WTFMove(object));
-        EXPECT_EQ(objectPtr, object.get());
-        EXPECT_EQ(nil, objectCast2.get());
-        objectPtr = nil;
-        EXPECT_EQ(1U, [object retainCount]);
</del><ins>+        EXPECT_EQ(objectPtr, objectCastPtr);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectCastPtr));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS(reinterpret_cast<id>([[NSObject alloc] init]));
-        id objectPtr = object.get();
</del><ins>+    @autoreleasepool {
+        auto object = adoptNS<id>([[NSObject alloc] init]);
+        auto objectPtr = reinterpret_cast<uintptr_t>(object.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr));
+
</ins><span class="cx">         auto objectCast = dynamic_objc_cast<NSObject>(WTFMove(object));
</span><ins>+        auto objectCastPtr = reinterpret_cast<uintptr_t>(objectCast.get());
</ins><span class="cx">         EXPECT_EQ(nil, object.get());
</span><del>-        EXPECT_EQ(objectPtr, objectCast.get());
-        objectPtr = nil; // For ARC.
-        EXPECT_EQ(1U, [objectCast retainCount]);
</del><ins>+        EXPECT_EQ(objectPtr, objectCastPtr);
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectCastPtr));
</ins><span class="cx"> 
</span><del>-        object = adoptNS(reinterpret_cast<id>([[NSObject alloc] init]));
-        objectPtr = object.get();
-        auto objectCast2 = dynamic_objc_cast<MyObjectSubtype>(WTFMove(object));
-        EXPECT_EQ(objectPtr, object.get());
-        EXPECT_EQ(nil, objectCast2.get());
-        objectPtr = nil; // For ARC.
-        EXPECT_EQ(1U, [object retainCount]);
-    }
</del><ins>+        object = adoptNS<id>([[NSObject alloc] init]);
+        objectPtr = reinterpret_cast<uintptr_t>(object.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr));
</ins><span class="cx"> 
</span><del>-    {
-        auto object = adoptNS([[NSObject alloc] init]);
-        id objectPtr = object.get();
-        auto objectCast = dynamic_objc_cast<MyObjectSubtype>(WTFMove(object));
-        EXPECT_EQ(objectPtr, object.get());
-        EXPECT_EQ(nil, objectCast.get());
-        objectPtr = nil; // For ARC.
-        EXPECT_EQ(1U, [object retainCount]);
</del><ins>+        auto objectCastBad = dynamic_objc_cast<MyObjectSubtype>(WTFMove(object));
+        EXPECT_EQ(nil, objectCastBad.get());
+        EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr));
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFcocoaTypeCastsCocoaARCmm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoaARC.mm (0 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoaARC.mm                           (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/cocoa/TypeCastsCocoaARC.mm      2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+/*
+ * Copyright (C) 2021 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.
+ */
+
+#if !__has_feature(objc_arc)
+#error This tests TypeCastsCocoa.h with ARC enabled.
+#endif
+
+#define MyObjectSubtype MyObjectSubtypeARC
+#define TypeCastsCocoa TypeCastsCocoaARC
+#include "TypeCastsCocoa.mm"
+#undef TypeCastsCocoa
+#undef MyObjectSubtype
</ins></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFnsRetainPtrmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/ns/RetainPtr.mm (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/ns/RetainPtr.mm      2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/ns/RetainPtr.mm 2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2011-2021 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -27,24 +27,37 @@
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #import "config.h"
</span><del>-
</del><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx"> 
</span><ins>+#if __has_feature(objc_arc)
+#ifndef RETAIN_PTR_TEST_NAME
+#error This tests RetainPtr.h with ARC disabled.
+#endif
+#define autorelease self
+#endif
+
+#ifndef RETAIN_PTR_TEST_NAME
+#define RETAIN_PTR_TEST_NAME RetainPtr
+#endif
+
</ins><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, AdoptNS)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, AdoptNS)
</ins><span class="cx"> {
</span><span class="cx">     RetainPtr<NSObject> object1 = adoptNS([[NSObject alloc] init]);
</span><del>-    EXPECT_EQ(1, CFGetRetainCount(object1.get()));
</del><ins>+    auto objectPtr1 = reinterpret_cast<uintptr_t>(object1.get());
+    EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr1));
</ins><span class="cx"> 
</span><span class="cx">     RetainPtr<NSObject *> object2 = adoptNS([[NSObject alloc] init]);
</span><del>-    EXPECT_EQ(1, CFGetRetainCount(object2.get()));
</del><ins>+    auto objectPtr2 = reinterpret_cast<uintptr_t>(object2.get());
+    EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr2));
</ins><span class="cx"> 
</span><span class="cx">     RetainPtr<id> object3 = adoptNS([[NSObject alloc] init]);
</span><del>-    EXPECT_EQ(1, CFGetRetainCount(object3.get()));
</del><ins>+    auto objectPtr3 = reinterpret_cast<uintptr_t>(object3.get());
+    EXPECT_EQ(1, CFGetRetainCount((CFTypeRef)objectPtr3));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, ConstructionFromMutableNSType)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, ConstructionFromMutableNSType)
</ins><span class="cx"> {
</span><span class="cx">     NSMutableString *string = [NSMutableString stringWithUTF8String:"foo"];
</span><span class="cx"> 
</span><span class="lines">@@ -64,7 +77,7 @@
</span><span class="cx">     EXPECT_EQ((NSString *)nil, temp);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, ConstructionFromSameNSType)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, ConstructionFromSameNSType)
</ins><span class="cx"> {
</span><span class="cx">     NSString *string = @"foo";
</span><span class="cx"> 
</span><span class="lines">@@ -84,7 +97,7 @@
</span><span class="cx">     EXPECT_EQ((NSString *)nil, temp);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, ConstructionFromSimilarNSType)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, ConstructionFromSimilarNSType)
</ins><span class="cx"> {
</span><span class="cx">     NSString *string = @"foo";
</span><span class="cx"> 
</span><span class="lines">@@ -104,7 +117,7 @@
</span><span class="cx">     EXPECT_EQ((NSString *)nil, temp);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, ConstructionFromSimilarNSTypeReversed)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, ConstructionFromSimilarNSTypeReversed)
</ins><span class="cx"> {
</span><span class="cx">     NSString *string = @"foo";
</span><span class="cx"> 
</span><span class="lines">@@ -124,7 +137,7 @@
</span><span class="cx">     EXPECT_EQ((NSString *)nil, temp);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, MoveAssignmentFromMutableNSType)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, MoveAssignmentFromMutableNSType)
</ins><span class="cx"> {
</span><span class="cx">     NSMutableString *string = [NSMutableString stringWithUTF8String:"foo"];
</span><span class="cx">     RetainPtr<NSString> ptr;
</span><span class="lines">@@ -146,7 +159,7 @@
</span><span class="cx">     EXPECT_EQ((NSString *)nil, temp);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, MoveAssignmentFromSameNSType)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, MoveAssignmentFromSameNSType)
</ins><span class="cx"> {
</span><span class="cx">     NSString *string = @"foo";
</span><span class="cx">     RetainPtr<NSString> ptr;
</span><span class="lines">@@ -168,7 +181,7 @@
</span><span class="cx">     EXPECT_EQ((NSString *)nil, temp);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, MoveAssignmentFromSimilarNSType)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, MoveAssignmentFromSimilarNSType)
</ins><span class="cx"> {
</span><span class="cx">     NSString *string = @"foo";
</span><span class="cx">     RetainPtr<NSString> ptr;
</span><span class="lines">@@ -190,7 +203,7 @@
</span><span class="cx">     EXPECT_EQ((NSString *)nil, temp);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, MoveAssignmentFromSimilarNSTypeReversed)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, MoveAssignmentFromSimilarNSTypeReversed)
</ins><span class="cx"> {
</span><span class="cx">     NSString *string = @"foo";
</span><span class="cx">     RetainPtr<NSString *> ptr;
</span><span class="lines">@@ -212,11 +225,12 @@
</span><span class="cx">     EXPECT_EQ((NSString *)nil, temp);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, OptionalRetainPtrNS)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, OptionalRetainPtrNS)
</ins><span class="cx"> {
</span><span class="cx">     // Test assignment from adoptNS().
</span><span class="cx">     std::optional<RetainPtr<NSObject>> optionalObject1 = adoptNS([NSObject new]);
</span><del>-    EXPECT_EQ(1, CFGetRetainCount(optionalObject1.value().get()));
</del><ins>+    auto optionalObjectPtr1 = reinterpret_cast<uintptr_t>(optionalObject1.value().get());
+    EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)optionalObjectPtr1));
</ins><span class="cx">     RetainPtr<NSObject> object1 = optionalObject1.value();
</span><span class="cx">     EXPECT_EQ(optionalObject1.value(), object1);
</span><span class="cx"> 
</span><span class="lines">@@ -225,8 +239,10 @@
</span><span class="cx">     @autoreleasepool {
</span><span class="cx">         optionalObject2 = retainPtr([[NSObject new] autorelease]);
</span><span class="cx">     }
</span><del>-    EXPECT_EQ(1, CFGetRetainCount(optionalObject2.value().get()));
</del><ins>+    auto optionalObjectPtr2 = reinterpret_cast<uintptr_t>(optionalObject2.value().get());
+    EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)optionalObjectPtr2));
</ins><span class="cx">     RetainPtr<NSObject> object2 = optionalObject2.value();
</span><ins>+    auto objectPtr2 = reinterpret_cast<uintptr_t>(object2.get());
</ins><span class="cx">     EXPECT_EQ(optionalObject2.value(), object2);
</span><span class="cx"> 
</span><span class="cx">     EXPECT_NE(object1, object2);
</span><span class="lines">@@ -246,33 +262,36 @@
</span><span class="cx">     EXPECT_EQ(optionalObject2.value(), object2);
</span><span class="cx"> 
</span><span class="cx">     // Test move from std::optional<RetainPtr<NSObject>>.
</span><del>-    EXPECT_EQ(2, CFGetRetainCount(object2.get()));
</del><ins>+    EXPECT_EQ(2L, CFGetRetainCount((CFTypeRef)objectPtr2));
</ins><span class="cx">     optionalObject1 = WTFMove(optionalObject2);
</span><del>-    EXPECT_EQ(2, CFGetRetainCount(object2.get()));
</del><ins>+    EXPECT_EQ(2L, CFGetRetainCount((CFTypeRef)objectPtr2));
</ins><span class="cx">     EXPECT_TRUE(optionalObject1.value());
</span><span class="cx">     EXPECT_TRUE(optionalObject1.value().get());
</span><span class="cx">     EXPECT_EQ(optionalObject1.value(), object2);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TEST(RetainPtr, RetainPtrNS)
</del><ins>+TEST(RETAIN_PTR_TEST_NAME, RetainPtrNS)
</ins><span class="cx"> {
</span><span class="cx">     RetainPtr<NSObject> object1;
</span><span class="cx">     @autoreleasepool {
</span><span class="cx">         object1 = retainPtr([[NSObject new] autorelease]);
</span><span class="cx">     }
</span><del>-    EXPECT_EQ(1, CFGetRetainCount(object1.get()));
</del><ins>+    auto objectPtr1 = reinterpret_cast<uintptr_t>(object1.get());
+    EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr1));
</ins><span class="cx"> 
</span><span class="cx">     RetainPtr<NSObject *> object2;
</span><span class="cx">     @autoreleasepool {
</span><span class="cx">         object2 = retainPtr([[NSObject new] autorelease]);
</span><span class="cx">     }
</span><del>-    EXPECT_EQ(1, CFGetRetainCount(object2.get()));
</del><ins>+    auto objectPtr2 = reinterpret_cast<uintptr_t>(object2.get());
+    EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr2));
</ins><span class="cx"> 
</span><span class="cx">     RetainPtr<id> object3;
</span><span class="cx">     @autoreleasepool {
</span><span class="cx">         object3 = retainPtr([[NSObject new] autorelease]);
</span><span class="cx">     }
</span><del>-    EXPECT_EQ(1, CFGetRetainCount(object3.get()));
</del><ins>+    auto objectPtr3 = reinterpret_cast<uintptr_t>(object3.get());
+    EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr3));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace TestWebKitAPI
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFnsRetainPtrARCmm"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WTF/ns/RetainPtrARC.mm (0 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/ns/RetainPtrARC.mm                           (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/ns/RetainPtrARC.mm      2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -0,0 +1,31 @@
</span><ins>+/*
+ * Copyright (C) 2021 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.
+ */
+
+#if !__has_feature(objc_arc)
+#error This tests RetainPtr.h with ARC enabled.
+#endif
+
+#define RETAIN_PTR_TEST_NAME RetainPtrARC
+#include "RetainPtr.mm"
+#undef RETAIN_PTR_TEST_NAME
</ins></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaQuickLookmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm (283475 => 283476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm 2021-10-03 18:48:20 UTC (rev 283475)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/QuickLook.mm    2021-10-03 19:31:55 UTC (rev 283476)
</span><span class="lines">@@ -44,7 +44,7 @@
</span><span class="cx"> #import <WebKit/_WKDownload.h>
</span><span class="cx"> #import <WebKit/_WKDownloadDelegate.h>
</span><span class="cx"> #import <wtf/NeverDestroyed.h>
</span><del>-#import <wtf/RetainPtr.h>
</del><ins>+#import <wtf/cocoa/TypeCastsCocoa.h>
</ins><span class="cx"> 
</span><span class="cx"> using namespace TestWebKitAPI;
</span><span class="cx"> 
</span><span class="lines">@@ -97,8 +97,8 @@
</span><span class="cx">     if ([fileURL getResourceValue:&typeIdentifier forKey:NSURLTypeIdentifierKey error:nil])
</span><span class="cx">         fileType = typeIdentifier;
</span><span class="cx"> 
</span><del>-    mimeType = adoptCF(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)typeIdentifier, kUTTagClassMIMEType));
-    fileData = [NSData dataWithContentsOfURL:fileURL];
</del><ins>+    mimeType = bridge_cast(adoptCF(UTTypeCopyPreferredTagWithClass(bridge_cast(typeIdentifier), kUTTagClassMIMEType)));
+    fileData = adoptNS([[NSData alloc] initWithContentsOfURL:fileURL]);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (instancetype)initWithExpectedFileURL:(NSURL *)fileURL responsePolicy:(WKNavigationResponsePolicy)responsePolicy
</span></span></pre>
</div>
</div>

</body>
</html>