Modified: trunk/Source/WTF/ChangeLog (168347 => 168348)
--- trunk/Source/WTF/ChangeLog 2014-05-06 02:54:26 UTC (rev 168347)
+++ trunk/Source/WTF/ChangeLog 2014-05-06 03:12:54 UTC (rev 168348)
@@ -1,3 +1,19 @@
+2014-05-04 Darin Adler <[email protected]>
+
+ RetainPtr: Use adoptCF function instead of AdoptCF constructor argument
+ https://bugs.webkit.org/show_bug.cgi?id=80222
+
+ Reviewed by Alexey Proskuryakov.
+
+ All the clients are gone, so we can now remove AdoptCF and AdoptNS.
+
+ * wtf/RetainPtr.h: Removed the public constructors that let you specify AdoptCF
+ and AdoptNS. Instead, made the adoptCF and adoptNS functions be friends and use
+ a private constructor that takes an Adopt argument.
+ (WTF::adoptCF): Moved the Objective-C class check in here.
+ (WTF::adoptNS): Moved the code to deal with the CFRetain for garbage collection
+ in here; it used to be spread across the constructor and adoptNSReference.
+
2014-05-04 Andreas Kling <[email protected]>
Optimize JSRopeString for resolving directly to AtomicString.
Modified: trunk/Source/WTF/wtf/RetainPtr.h (168347 => 168348)
--- trunk/Source/WTF/wtf/RetainPtr.h 2014-05-06 02:54:26 UTC (rev 168347)
+++ trunk/Source/WTF/wtf/RetainPtr.h 2014-05-06 03:12:54 UTC (rev 168348)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005, 2006, 2007, 2008, 2010, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006, 2007, 2008, 2010, 2013, 2014 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -48,29 +48,10 @@
// Unlike most most of our smart pointers, RetainPtr can take either the pointer type or the pointed-to type,
// so both RetainPtr<NSDictionary> and RetainPtr<CFDictionaryRef> will work.
-#if !PLATFORM(IOS)
- #define AdoptCF DeprecatedAdoptCF
- #define AdoptNS DeprecatedAdoptNS
-#endif
+ template<typename T> class RetainPtr;
- enum AdoptCFTag { AdoptCF };
- enum AdoptNSTag { AdoptNS };
-
-#if defined(__OBJC__) && !__has_feature(objc_arc)
-#ifdef OBJC_NO_GC
- inline void adoptNSReference(id)
- {
- }
-#else
- inline void adoptNSReference(id ptr)
- {
- if (ptr) {
- CFRetain(ptr);
- [ptr release];
- }
- }
-#endif
-#endif
+ template<typename T> RetainPtr<T> adoptCF(T CF_RELEASES_ARGUMENT) WARN_UNUSED_RETURN;
+ template<typename T> RetainPtr<T> adoptNS(T NS_RELEASES_ARGUMENT) WARN_UNUSED_RETURN;
template<typename T> class RetainPtr {
public:
@@ -78,27 +59,9 @@
typedef ValueType* PtrType;
typedef CFTypeRef StorageType;
- RetainPtr() : m_ptr(0) {}
+ RetainPtr() : m_ptr(nullptr) { }
RetainPtr(PtrType ptr) : m_ptr(toStorageType(ptr)) { if (m_ptr) CFRetain(m_ptr); }
- RetainPtr(AdoptCFTag, PtrType ptr)
- : m_ptr(toStorageType(ptr))
- {
-#ifdef __OBJC__
- static_assert((!std::is_convertible<T, id>::value), "Don't use adoptCF with Objective-C pointer types, use adoptNS.");
-#endif
- }
-
-#if __has_feature(objc_arc)
- RetainPtr(AdoptNSTag, PtrType ptr) : m_ptr(toStorageType(ptr)) { if (m_ptr) CFRetain(m_ptr); }
-#else
- RetainPtr(AdoptNSTag, PtrType ptr)
- : m_ptr(toStorageType(ptr))
- {
- adoptNSReference(ptr);
- }
-#endif
-
RetainPtr(const RetainPtr& o) : m_ptr(o.m_ptr) { if (StorageType ptr = m_ptr) CFRetain(ptr); }
RetainPtr(RetainPtr&& o) : m_ptr(toStorageType(o.leakRef())) { }
@@ -124,7 +87,7 @@
// This conversion operator allows implicit conversion to bool but not to other integer types.
typedef StorageType RetainPtr::*UnspecifiedBoolType;
- operator UnspecifiedBoolType() const { return m_ptr ? &RetainPtr::m_ptr : 0; }
+ operator UnspecifiedBoolType() const { return m_ptr ? &RetainPtr::m_ptr : nullptr; }
RetainPtr& operator=(const RetainPtr&);
template<typename U> RetainPtr& operator=(const RetainPtr<U>&);
@@ -136,7 +99,13 @@
void swap(RetainPtr&);
+ template<typename U> friend RetainPtr<U> adoptCF(U CF_RELEASES_ARGUMENT) WARN_UNUSED_RETURN;
+ template<typename U> friend RetainPtr<U> adoptNS(U NS_RELEASES_ARGUMENT) WARN_UNUSED_RETURN;
+
private:
+ enum AdoptTag { Adopt };
+ RetainPtr(PtrType ptr, AdoptTag) : m_ptr(toStorageType(ptr)) { }
+
static PtrType hashTableDeletedValue() { return reinterpret_cast<PtrType>(-1); }
#if defined (__OBJC__) && __has_feature(objc_arc)
@@ -165,6 +134,9 @@
StorageType m_ptr;
};
+ // Helper function for creating a RetainPtr using template argument deduction.
+ template<typename T> inline RetainPtr<T> retainPtr(T) WARN_UNUSED_RETURN;
+
template<typename T> template<typename U> inline RetainPtr<T>::RetainPtr(const RetainPtr<U>& o)
: m_ptr(toStorageType(o.get()))
{
@@ -175,7 +147,7 @@
template<typename T> inline void RetainPtr<T>::clear()
{
if (StorageType ptr = m_ptr) {
- m_ptr = 0;
+ m_ptr = nullptr;
CFRelease(ptr);
}
}
@@ -183,7 +155,7 @@
template<typename T> inline typename RetainPtr<T>::PtrType RetainPtr<T>::leakRef()
{
PtrType ptr = fromStorageType(m_ptr);
- m_ptr = 0;
+ m_ptr = nullptr;
return ptr;
}
@@ -269,23 +241,32 @@
return a != b.get();
}
- template<typename T> inline RetainPtr<T> adoptCF(T CF_RELEASES_ARGUMENT) WARN_UNUSED_RETURN;
- template<typename T> inline RetainPtr<T> adoptCF(T CF_RELEASES_ARGUMENT o)
+ template<typename T> inline RetainPtr<T> adoptCF(T CF_RELEASES_ARGUMENT ptr)
{
- return RetainPtr<T>(AdoptCF, o);
+#ifdef __OBJC__
+ static_assert((!std::is_convertible<T, id>::value), "Don't use adoptCF with Objective-C pointer types, use adoptNS.");
+#endif
+ return RetainPtr<T>(ptr, RetainPtr<T>::Adopt);
}
- template<typename T> inline RetainPtr<T> adoptNS(T NS_RELEASES_ARGUMENT) WARN_UNUSED_RETURN;
- template<typename T> inline RetainPtr<T> adoptNS(T NS_RELEASES_ARGUMENT o)
+#ifdef __OBJC__
+ template<typename T> inline RetainPtr<T> adoptNS(T NS_RELEASES_ARGUMENT ptr)
{
- return RetainPtr<T>(AdoptNS, o);
+#if __has_feature(objc_arc)
+ return ptr;
+#elif defined(OBJC_NO_GC)
+ return RetainPtr<T>(ptr, RetainPtr<T>::Adopt);
+#else
+ RetainPtr<T> result = ptr;
+ [ptr release];
+ return result;
+#endif
}
+#endif
- // Helper function for creating a RetainPtr using template argument deduction.
- template<typename T> inline RetainPtr<T> retainPtr(T) WARN_UNUSED_RETURN;
- template<typename T> inline RetainPtr<T> retainPtr(T o)
+ template<typename T> inline RetainPtr<T> retainPtr(T ptr)
{
- return o;
+ return ptr;
}
template<typename P> struct HashTraits<RetainPtr<P>> : SimpleClassHashTraits<RetainPtr<P>> { };
@@ -324,11 +305,6 @@
static const bool safeToCompareToEmptyOrDeleted = false;
};
-#if !PLATFORM(IOS)
- #undef AdoptCF
- #undef AdoptNS
-#endif
-
} // namespace WTF
using WTF::RetainPtr;
@@ -336,11 +312,6 @@
using WTF::adoptNS;
using WTF::retainPtr;
-#if PLATFORM(IOS)
-using WTF::AdoptCF;
-using WTF::AdoptNS;
-#endif
-
#endif // USE(CF) || defined(__OBJC__)
#endif // WTF_RetainPtr_h
Modified: trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm (168347 => 168348)
--- trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm 2014-05-06 02:54:26 UTC (rev 168347)
+++ trunk/Tools/DumpRenderTree/mac/TestRunnerMac.mm 2014-05-06 03:12:54 UTC (rev 168348)
@@ -922,77 +922,88 @@
@end
#if PLATFORM(IOS)
+
@interface APITestDelegateIPhone : NSObject
{
- TestRunner* m_layoutTestRunner;
- JSStringRef m_utf8Data;
- JSStringRef m_baseURL;
- WebView *m_webView;
+ TestRunner& testRunner;
+ NSData *data;
+ NSURL *baseURL;
+ WebView *webView;
}
-
-- (id)initWithTestRunner:(TestRunner*)layoutTestRunner utf8Data:(JSStringRef)utf8Data baseURL:(JSStringRef)baseURL;
+- (id)initWithTestRunner:(TestRunner*)testRunner utf8Data:(JSStringRef)data baseURL:(JSStringRef)baseURL;
- (void)run;
@end
@implementation APITestDelegateIPhone
-- (id)initWithTestRunner:(TestRunner*)layoutTestRunner utf8Data:(JSStringRef)utf8Data baseURL:(JSStringRef)baseURL
+- (id)initWithTestRunner:(TestRunner*)runner utf8Data:(JSStringRef)data baseURL:(JSStringRef)baseURL
{
self = [super init];
if (!self)
return nil;
- m_layoutTestRunner = layoutTestRunner;
- m_utf8Data = utf8Data;
- m_baseURL = baseURL;
+ testRunner = *runner;
+ data = "" *)adoptCF(JSStringCopyCFString(kCFAllocatorDefault, data)).get() dataUsingEncoding:NSUTF8StringEncoding] retain];
+ baseURL = [[NSURL URLWithString:(NSString *)adoptCF(JSStringCopyCFString(kCFAllocatorDefault, baseURL)).get()] retain];
return self;
}
+- (void)dealloc
+{
+ [data release];
+ [baseURL release];
+ [super dealloc];
+}
+
- (void)run
{
- m_layoutTestRunner->setWaitToDump(true);
+ if (webView)
+ return;
- RetainPtr<CFStringRef> utf8DataCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, m_utf8Data));
- RetainPtr<CFStringRef> baseURLCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, m_baseURL));
- m_utf8Data = NULL;
- m_baseURL = NULL;
+ testRunner.setWaitToDump(true);
WebThreadLock();
- m_webView = [[WebView alloc] initWithFrame:NSZeroRect frameName:@"" groupName:@""];
- [m_webView setFrameLoadDelegate:self];
- [[m_webView mainFrame] loadData:[(NSString *)utf8DataCF.get() dataUsingEncoding:NSUTF8StringEncoding] MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:[NSURL URLWithString:(NSString *)baseURLCF.get()]];
+ webView = [[WebView alloc] initWithFrame:NSZeroRect frameName:@"" groupName:@""];
+ [webView setFrameLoadDelegate:self];
+ [[webView mainFrame] loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:baseURL];
}
-- (void)_cleanup
+- (void)_cleanUp
{
+ if (!webView)
+ return;
+
WebThreadLock();
- [m_webView _clearDelegates];
- [m_webView close];
- [m_webView release];
- m_layoutTestRunner->notifyDone();
+ [webView _clearDelegates];
+ [webView close];
+ [webView release];
+ webView = nil;
+
+ testRunner.notifyDone();
}
- (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
{
printf("API Test load failed\n");
- [self _cleanup];
+ [self _cleanUp];
}
- (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
{
printf("API Test load failed provisional\n");
- [self _cleanup];
+ [self _cleanUp];
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
printf("API Test load succeeded\n");
- [self _cleanup];
+ [self _cleanUp];
}
@end
+
#endif
void TestRunner::apiTestNewWindowDataLoadBaseURL(JSStringRef utf8Data, JSStringRef baseURL)