[Cocoa] Remove all uses of NSAutoreleasePool as part of preparation for ARC
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Jun 2018 16:27:16 +0000 (16:27 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Jun 2018 16:27:16 +0000 (16:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186436

Reviewed by Anders Carlsson.

Source/JavaScriptCore:

* heap/Heap.cpp: Include FoundationSPI.h rather than directly including
objc-internal.h and explicitly declaring the alternative.

Source/WebCore:

* bridge/objc/objc_class.mm: Use import instead of include.

* bridge/objc/objc_instance.h: Replaced _pool member to hold an object with
m_autoreleasePool member to hold a token from objc_autoreleasePoolPush. Also
initialize all data members here in the class definition.

* bridge/objc/objc_instance.mm:
(ObjcInstance::ObjcInstance): Moved most initialization to class definition.
(ObjcInstance::virtualBegin): Use objc_autoreleasePoolPush instead of
NSAutoreleasePool class.
(ObjcInstance::virtualEnd): Use objc_autoreleasePoolPop.

* bridge/objc/objc_runtime.mm: Use import instead of include.
* bridge/objc/objc_utility.mm: Ditto.

* platform/audio/mac/AudioBusMac.mm:
(WebCore::AudioBus::loadPlatformResource): Use @autoreleasepool.

* platform/ios/wak/WebCoreThread.mm: Re-sorted includes. Removed declaration of
autorelease pool SPI and use FoundationSPI.h instead.

* platform/network/cocoa/ResourceResponseCocoa.mm:
(WebCore::ResourceResponse::platformLazyInit): Use @autoreleasepool.

Source/WebCore/PAL:

* PAL.xcodeproj/project.pbxproj: Removed FoundationSPI.h.
* pal/PlatformMac.cmake: Ditto.
* pal/spi/cocoa/FoundationSPI.h: Moved into WTF project.

Source/WebKitLegacy/mac:

* Carbon/CarbonUtils.m: Updated include location of FoundationSPI.h.
(getNSAutoreleasePoolCount): Use objc_autoreleasePoolPush/Pop.
(WebInitForCarbon): Use objc_autoreleasePoolPush/Pop instead of NSAutoreleasePool object.
(PoolCleaner): Ditto.

* History/WebHistory.mm:
(-[WebHistoryPrivate loadHistoryGutsFromURL:savedItemsCount:collectDiscardedItemsInto:error:]):
Use @autoreleasepool instead of NSAutoreleasePool object. No need to do the "drain pool only
every 50 times"; the -[WebHistory loadFromURL] family of methods were once used by Safari, and
now hardly used if at all.
* WebView/WebView.mm:
(-[WebView rectsForTextMatches]): Ditto.

Source/WTF:

* WTF.xcodeproj/project.pbxproj: Added FoundationSPI.h.

* wtf/AutodrainedPool.h: Streamlined header a bit, added some comments.

* wtf/PlatformMac.cmake: Added FoundationSPI.h.

* wtf/cocoa/AutodrainedPool.cpp: Moved here from AutodrainedPoolMac.mm.
(WTF::AutodrainedPool::AutodrainedPool): Use objc_autoreleasePoolPush/Pop instead of
the NSAutoreleasePool class.
(WTF::AutodrainedPool::~AutodrainedPool): Ditto.

 * wtf/spi/cocoa/FoundationSPI.h: Moved from Source/WebCore/PAL/pal/spi/cocoa/FoundationSPI.h.
 Changed both include and declarations so it's the objc_autoreleasePoolPush/Pop instead
 of the higher level NS functions that call them.

Tools:

* TestWebKitAPI/Tests/WebKitObjC/CustomProtocolsTest.mm:
(TestWebKitAPI::WebKit2CustomProtocolsTest_ProcessPoolDestroyedDuringLoading):
Use @autoreleasepool.
* TestWebKitAPI/Tests/mac/MenuTypesForMouseEvents.mm:
(TestWebKitAPI::buildAndPerformTest): Ditto.
* TestWebKitAPI/Tests/mac/StopLoadingFromDidFinishLoading.mm:
(TestWebKitAPI::WebKitLegacy_StopLoadingFromDidFinishLoading): Ditto.

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

28 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/Heap.cpp
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/AutodrainedPool.h
Source/WTF/wtf/PlatformMac.cmake
Source/WTF/wtf/cocoa/AutodrainedPool.cpp [moved from Source/WTF/wtf/AutodrainedPoolMac.mm with 89% similarity]
Source/WTF/wtf/spi/cocoa/FoundationSPI.h [moved from Source/WebCore/PAL/pal/spi/cocoa/FoundationSPI.h with 84% similarity]
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
Source/WebCore/PAL/pal/PlatformMac.cmake
Source/WebCore/bridge/objc/objc_class.mm
Source/WebCore/bridge/objc/objc_instance.h
Source/WebCore/bridge/objc/objc_instance.mm
Source/WebCore/bridge/objc/objc_runtime.mm
Source/WebCore/bridge/objc/objc_utility.mm
Source/WebCore/platform/audio/mac/AudioBusMac.mm
Source/WebCore/platform/ios/wak/WebCoreThread.mm
Source/WebCore/platform/network/cocoa/ResourceResponseCocoa.mm
Source/WebKitLegacy/mac/Carbon/CarbonUtils.m
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/History/WebHistory.mm
Source/WebKitLegacy/mac/WebView/WebView.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitObjC/CustomProtocolsTest.mm
Tools/TestWebKitAPI/Tests/mac/MenuTypesForMouseEvents.mm
Tools/TestWebKitAPI/Tests/mac/StopLoadingFromDidFinishLoading.mm

index 2ca6c4d..135183d 100644 (file)
@@ -1,3 +1,13 @@
+2018-06-08  Darin Adler  <darin@apple.com>
+
+        [Cocoa] Remove all uses of NSAutoreleasePool as part of preparation for ARC
+        https://bugs.webkit.org/show_bug.cgi?id=186436
+
+        Reviewed by Anders Carlsson.
+
+        * heap/Heap.cpp: Include FoundationSPI.h rather than directly including
+        objc-internal.h and explicitly declaring the alternative.
+
 2018-06-08  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [WebKit on watchOS] Upstream watchOS source additions to OpenSource (Part 1)
index 9c66bbc..63d8001 100644 (file)
 #include "SamplingProfiler.h"
 #include "ShadowChicken.h"
 #include "SpaceTimeMutatorScheduler.h"
-#include "SubspaceInlines.h"
-#include "SuperSampler.h"
 #include "StochasticSpaceTimeMutatorScheduler.h"
 #include "StopIfNecessaryTimer.h"
+#include "SubspaceInlines.h"
+#include "SuperSampler.h"
 #include "SweepingScope.h"
 #include "SynchronousStopTheWorldMutatorScheduler.h"
 #include "TypeProfiler.h"
@@ -77,9 +77,6 @@
 #include "WeakMapImplInlines.h"
 #include "WeakSetInlines.h"
 #include <algorithm>
-#if PLATFORM(IOS)
-#include <bmalloc/bmalloc.h>
-#endif
 #include <wtf/ListDump.h>
 #include <wtf/MainThread.h>
 #include <wtf/ParallelVectorIterator.h>
 #include <wtf/SimpleStats.h>
 #include <wtf/Threading.h>
 
+#if PLATFORM(IOS)
+#include <bmalloc/bmalloc.h>
+#endif
+
 #if USE(FOUNDATION)
-#if __has_include(<objc/objc-internal.h>)
-#include <objc/objc-internal.h>
-#else
-extern "C" void* objc_autoreleasePoolPush(void);
-extern "C" void objc_autoreleasePoolPop(void *context);
+#include <wtf/spi/cocoa/FoundationSPI.h>
 #endif
-#endif // USE(FOUNDATION)
 
 #if USE(GLIB)
 #include "JSCGLibWrapperObject.h"
index 4381290..bcc873c 100644 (file)
@@ -1,3 +1,25 @@
+2018-06-08  Darin Adler  <darin@apple.com>
+
+        [Cocoa] Remove all uses of NSAutoreleasePool as part of preparation for ARC
+        https://bugs.webkit.org/show_bug.cgi?id=186436
+
+        Reviewed by Anders Carlsson.
+
+        * WTF.xcodeproj/project.pbxproj: Added FoundationSPI.h.
+
+        * wtf/AutodrainedPool.h: Streamlined header a bit, added some comments.
+
+        * wtf/PlatformMac.cmake: Added FoundationSPI.h.
+
+        * wtf/cocoa/AutodrainedPool.cpp: Moved here from AutodrainedPoolMac.mm.
+        (WTF::AutodrainedPool::AutodrainedPool): Use objc_autoreleasePoolPush/Pop instead of
+        the NSAutoreleasePool class.
+        (WTF::AutodrainedPool::~AutodrainedPool): Ditto.
+
+         * wtf/spi/cocoa/FoundationSPI.h: Moved from Source/WebCore/PAL/pal/spi/cocoa/FoundationSPI.h.
+         Changed both include and declarations so it's the objc_autoreleasePoolPush/Pop instead
+         of the higher level NS functions that call them.
+
 2018-06-08  Brian Burg  <bburg@apple.com>
 
         [Cocoa] Web Automation: include browser name and version in listing for automation targets
index fb2ee7e..ef1b33b 100644 (file)
@@ -53,7 +53,7 @@
                1469419316EAAF6D0024E146 /* RunLoopTimerCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1469419116EAAF6D0024E146 /* RunLoopTimerCF.cpp */; };
                1469419716EAAFF80024E146 /* SchedulePairMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1469419516EAAFF80024E146 /* SchedulePairMac.mm */; };
                1469419916EAB0410024E146 /* SchedulePairCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1469419816EAB0410024E146 /* SchedulePairCF.cpp */; };
-               1469419D16EAB10A0024E146 /* AutodrainedPoolMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1469419B16EAB10A0024E146 /* AutodrainedPoolMac.mm */; };
+               1469419D16EAB10A0024E146 /* AutodrainedPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1469419B16EAB10A0024E146 /* AutodrainedPool.cpp */; };
                1A1D8B9E1731879800141DA4 /* FunctionDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */; };
                1ACADD841884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */; };
                1C181C7F1D3078DA00F5FA16 /* TextBreakIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C181C7D1D3078DA00F5FA16 /* TextBreakIterator.cpp */; };
                1469419516EAAFF80024E146 /* SchedulePairMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SchedulePairMac.mm; sourceTree = "<group>"; };
                1469419816EAB0410024E146 /* SchedulePairCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SchedulePairCF.cpp; sourceTree = "<group>"; };
                1469419A16EAB10A0024E146 /* AutodrainedPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutodrainedPool.h; sourceTree = "<group>"; };
-               1469419B16EAB10A0024E146 /* AutodrainedPoolMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutodrainedPoolMac.mm; sourceTree = "<group>"; };
+               1469419B16EAB10A0024E146 /* AutodrainedPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutodrainedPool.cpp; sourceTree = "<group>"; };
                149EF16216BBFE0D000A4331 /* TriState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TriState.h; sourceTree = "<group>"; };
                14C8279718FDD73400E1800C /* mbmalloc.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = mbmalloc.xcconfig; sourceTree = "<group>"; };
                14E785E71DFB330100209BD1 /* OrdinalNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrdinalNumber.h; sourceTree = "<group>"; };
                93934BD218A1E8C300D0D6A1 /* StringViewObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = StringViewObjC.mm; path = mac/StringViewObjC.mm; sourceTree = "<group>"; };
                93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringViewCF.cpp; path = cf/StringViewCF.cpp; sourceTree = "<group>"; };
                93AC91A718942FC400244939 /* LChar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LChar.h; sourceTree = "<group>"; };
+               93D191CF20CAECE800C51B8E /* FoundationSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FoundationSPI.h; sourceTree = "<group>"; };
                93DDE9311CDC052D00FD3491 /* dyldSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dyldSPI.h; sourceTree = "<group>"; };
                93F1993D19D7958D00C2390B /* StringView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringView.cpp; sourceTree = "<group>"; };
                974CFC8D16A4F327006D5404 /* WeakPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakPtr.h; sourceTree = "<group>"; };
                                A8A4725C151A825A004123FF /* Assertions.h */,
                                A8A4725D151A825A004123FF /* Atomics.h */,
                                1469419A16EAB10A0024E146 /* AutodrainedPool.h */,
-                               1469419B16EAB10A0024E146 /* AutodrainedPoolMac.mm */,
                                0F43D8EF1DB5ADDC00108FB6 /* AutomaticThread.cpp */,
                                0F43D8F01DB5ADDC00108FB6 /* AutomaticThread.h */,
                                DCEE22041CEB9869000C2396 /* BackwardsGraph.h */,
                CE46516C19DB1FB4003ECA05 /* cocoa */ = {
                        isa = PBXGroup;
                        children = (
+                               93D191CF20CAECE800C51B8E /* FoundationSPI.h */,
                                CE46516D19DB1FB4003ECA05 /* NSMapTableSPI.h */,
                                A5098B011C16A4F900087797 /* SecuritySPI.h */,
                        );
                E4A0AD3B1A96251900536DF6 /* cocoa */ = {
                        isa = PBXGroup;
                        children = (
+                               1469419B16EAB10A0024E146 /* AutodrainedPool.cpp */,
                                E38C41241EB4E04C0042957D /* CPUTimeCocoa.mm */,
                                143DDE9520C8BC37007F76FA /* Entitlements.cpp */,
                                143DDE9720C8BE99007F76FA /* Entitlements.h */,
                                70ECA60D1B02426800449739 /* AtomicStringImpl.cpp in Sources */,
                                A5BA15FA182435A600A82E69 /* AtomicStringImplCF.cpp in Sources */,
                                9BC70F05176C379D00101DEC /* AtomicStringTable.cpp in Sources */,
-                               1469419D16EAB10A0024E146 /* AutodrainedPoolMac.mm in Sources */,
+                               1469419D16EAB10A0024E146 /* AutodrainedPool.cpp in Sources */,
                                0F43D8F11DB5ADDC00108FB6 /* AutomaticThread.cpp in Sources */,
                                8134013815B092FD001FF0B8 /* Base64.cpp in Sources */,
                                A8A473A8151A825B004123FF /* bignum-dtoa.cc in Sources */,
index 6f02c5d..b667f8e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef AutodrainedPool_h
-#define AutodrainedPool_h
+#pragma once
 
-#include <wtf/Noncopyable.h>
-
-#if USE(FOUNDATION) && !defined(__OBJC__)
-typedef struct objc_object *id;
+#ifdef __OBJC__
+#error Please use @autoreleasepool instead of AutodrainedPool.
 #endif
 
+#include <wtf/Noncopyable.h>
+
 namespace WTF {
 
+// This class allows non-Objective-C C++ code to create an autorelease pool.
+// It cannot be used in Objective-C++ code, won't be compiled; instead @autoreleasepool should be used.
+// It can be used in cross-platform code; will compile down to nothing for non-Cocoa platforms.
+
 class AutodrainedPool {
     WTF_MAKE_NONCOPYABLE(AutodrainedPool);
+
 public:
 #if USE(FOUNDATION)
     WTF_EXPORT_PRIVATE AutodrainedPool();
     WTF_EXPORT_PRIVATE ~AutodrainedPool();
 #else
-    explicit AutodrainedPool() { }
+    AutodrainedPool() { }
     ~AutodrainedPool() { }
 #endif
-    
+
 private:
 #if USE(FOUNDATION)
-    id m_pool;
+    void* m_autoreleasePool;
 #endif
 };
 
 } // namespace WTF
 
 using WTF::AutodrainedPool;
-
-#endif
index a26e050..4d837a4 100644 (file)
@@ -21,6 +21,7 @@ list(APPEND WTF_PUBLIC_HEADERS
     spi/cf/CFBundleSPI.h
     spi/cf/CFStringSPI.h
 
+    spi/cocoa/FoundationSPI.h
     spi/cocoa/NSMapTableSPI.h
     spi/cocoa/SecuritySPI.h
 
@@ -32,7 +33,6 @@ list(APPEND WTF_PUBLIC_HEADERS
 )
 
 list(APPEND WTF_SOURCES
-    AutodrainedPoolMac.mm
     BlockObjCExceptions.mm
     RunLoopTimerCF.cpp
     SchedulePairCF.cpp
@@ -41,8 +41,7 @@ list(APPEND WTF_SOURCES
     cf/LanguageCF.cpp
     cf/RunLoopCF.cpp
 
-    text/mac/TextBreakIteratorInternalICUMac.mm
-
+    cocoa/AutodrainedPool.mm
     cocoa/CPUTimeCocoa.mm
     cocoa/Entitlements.cpp
     cocoa/MachSendRight.cpp
@@ -61,6 +60,7 @@ list(APPEND WTF_SOURCES
     text/mac/StringImplMac.mm
     text/mac/StringMac.mm
     text/mac/StringViewObjC.mm
+    text/mac/TextBreakIteratorInternalICUMac.mm
 )
 
 list(APPEND WTF_PRIVATE_INCLUDE_DIRECTORIES
similarity index 89%
rename from Source/WTF/wtf/AutodrainedPoolMac.mm
rename to Source/WTF/wtf/cocoa/AutodrainedPool.cpp
index f0a75d2..b0d7c82 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #import "config.h"
 #import "AutodrainedPool.h"
 
-#import <Foundation/Foundation.h>
+#import <wtf/spi/cocoa/FoundationSPI.h>
 
 namespace WTF {
 
 AutodrainedPool::AutodrainedPool()
-    : m_pool([[NSAutoreleasePool alloc] init])
+    : m_autoreleasePool { objc_autoreleasePoolPush() }
 { 
 }
 
 AutodrainedPool::~AutodrainedPool()
 {
-    [m_pool drain];
+    objc_autoreleasePoolPop(m_autoreleasePool);
 }
 
 } // namespace WTF
similarity index 84%
rename from Source/WebCore/PAL/pal/spi/cocoa/FoundationSPI.h
rename to Source/WTF/wtf/spi/cocoa/FoundationSPI.h
index 684175d..2691044 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #if USE(APPLE_INTERNAL_SDK)
 
-#include <Foundation/NSPrivateDecls.h>
+#include <objc/objc-internal.h>
 
-#endif
-
-typedef void* NSAutoreleasePoolMark;
+#else
 
 WTF_EXTERN_C_BEGIN
 
-NSAutoreleasePoolMark NSPushAutoreleasePool(NSUInteger capacity);
-void NSPopAutoreleasePool(NSAutoreleasePoolMark);
+void* objc_autoreleasePoolPush(void);
+void objc_autoreleasePoolPop(void* context);
 
 WTF_EXTERN_C_END
+
+#endif
index ed51feb..2ff663e 100644 (file)
@@ -1,3 +1,34 @@
+2018-06-08  Darin Adler  <darin@apple.com>
+
+        [Cocoa] Remove all uses of NSAutoreleasePool as part of preparation for ARC
+        https://bugs.webkit.org/show_bug.cgi?id=186436
+
+        Reviewed by Anders Carlsson.
+
+        * bridge/objc/objc_class.mm: Use import instead of include.
+
+        * bridge/objc/objc_instance.h: Replaced _pool member to hold an object with
+        m_autoreleasePool member to hold a token from objc_autoreleasePoolPush. Also
+        initialize all data members here in the class definition.
+
+        * bridge/objc/objc_instance.mm:
+        (ObjcInstance::ObjcInstance): Moved most initialization to class definition.
+        (ObjcInstance::virtualBegin): Use objc_autoreleasePoolPush instead of
+        NSAutoreleasePool class.
+        (ObjcInstance::virtualEnd): Use objc_autoreleasePoolPop.
+
+        * bridge/objc/objc_runtime.mm: Use import instead of include.
+        * bridge/objc/objc_utility.mm: Ditto.
+
+        * platform/audio/mac/AudioBusMac.mm:
+        (WebCore::AudioBus::loadPlatformResource): Use @autoreleasepool.
+
+        * platform/ios/wak/WebCoreThread.mm: Re-sorted includes. Removed declaration of
+        autorelease pool SPI and use FoundationSPI.h instead.
+
+        * platform/network/cocoa/ResourceResponseCocoa.mm:
+        (WebCore::ResourceResponse::platformLazyInit): Use @autoreleasepool.
+
 2018-06-08  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [WebKit on watchOS] Upstream watchOS source additions to OpenSource (Part 1)
index ffd7cbb..23c1807 100644 (file)
@@ -1,3 +1,14 @@
+2018-06-08  Darin Adler  <darin@apple.com>
+
+        [Cocoa] Remove all uses of NSAutoreleasePool as part of preparation for ARC
+        https://bugs.webkit.org/show_bug.cgi?id=186436
+
+        Reviewed by Anders Carlsson.
+
+        * PAL.xcodeproj/project.pbxproj: Removed FoundationSPI.h.
+        * pal/PlatformMac.cmake: Ditto.
+        * pal/spi/cocoa/FoundationSPI.h: Moved into WTF project.
+
 2018-06-08  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [WebKit on watchOS] Upstream watchOS source additions to OpenSource (Part 1)
index 59e747a..8de5ec7 100644 (file)
                57F12518205787D7001AB8A6 /* DeviceIdentitySPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 57F12517205787C8001AB8A6 /* DeviceIdentitySPI.h */; };
                7A1656441F97B2B900BA3CE4 /* NSKeyedArchiverSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A1656431F97B2B800BA3CE4 /* NSKeyedArchiverSPI.h */; };
                7A3A6A8020CADB4700317AAE /* NSImageSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A3A6A7F20CADB4600317AAE /* NSImageSPI.h */; };
-               A10265871F56746100B4C844 /* FoundationSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = A10265861F56746100B4C844 /* FoundationSPI.h */; };
                A10265891F56747A00B4C844 /* HIToolboxSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = A10265881F56747A00B4C844 /* HIToolboxSPI.h */; };
                A102658B1F56748C00B4C844 /* QuickDrawSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = A102658A1F56748C00B4C844 /* QuickDrawSPI.h */; };
                A102658E1F567E9D00B4C844 /* HIServicesSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = A102658D1F567E9D00B4C844 /* HIServicesSPI.h */; };
                7A1656431F97B2B800BA3CE4 /* NSKeyedArchiverSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSKeyedArchiverSPI.h; sourceTree = "<group>"; };
                7A3A6A7F20CADB4600317AAE /* NSImageSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSImageSPI.h; sourceTree = "<group>"; };
                93E5909C1F93BF1E0067F8CF /* UnencodableHandling.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UnencodableHandling.h; sourceTree = "<group>"; };
-               A10265861F56746100B4C844 /* FoundationSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FoundationSPI.h; sourceTree = "<group>"; };
                A10265881F56747A00B4C844 /* HIToolboxSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HIToolboxSPI.h; sourceTree = "<group>"; };
                A102658A1F56748C00B4C844 /* QuickDrawSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickDrawSPI.h; sourceTree = "<group>"; };
                A102658D1F567E9D00B4C844 /* HIServicesSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HIServicesSPI.h; sourceTree = "<group>"; };
                                0C2DA1241F3BEB4900DBC317 /* CoreTextSPI.h */,
                                0C2DA1251F3BEB4900DBC317 /* DataDetectorsCoreSPI.h */,
                                57F12517205787C8001AB8A6 /* DeviceIdentitySPI.h */,
-                               A10265861F56746100B4C844 /* FoundationSPI.h */,
                                0C2DA1261F3BEB4900DBC317 /* IOPMLibSPI.h */,
                                0C2DA1271F3BEB4900DBC317 /* IOPSLibSPI.h */,
                                0C2DA1281F3BEB4900DBC317 /* IOReturnSPI.h */,
                                57F12518205787D7001AB8A6 /* DeviceIdentitySPI.h in Headers */,
                                0C2D9E731EEF5AF600DBC317 /* ExportMacros.h in Headers */,
                                F44291601FA5261E002CC93E /* FileSizeFormatter.h in Headers */,
-                               A10265871F56746100B4C844 /* FoundationSPI.h in Headers */,
                                0C5AF91B1F43A4C7002EAC02 /* GraphicsServicesSPI.h in Headers */,
                                A102658E1F567E9D00B4C844 /* HIServicesSPI.h in Headers */,
                                A10265891F56747A00B4C844 /* HIToolboxSPI.h in Headers */,
index 7e382d8..b2acfbb 100644 (file)
@@ -17,7 +17,6 @@ list(APPEND PAL_PUBLIC_HEADERS
     spi/cocoa/CFNSURLConnectionSPI.h
     spi/cocoa/CoreTextSPI.h
     spi/cocoa/DataDetectorsCoreSPI.h
-    spi/cocoa/FoundationSPI.h
     spi/cocoa/IOPMLibSPI.h
     spi/cocoa/IOPSLibSPI.h
     spi/cocoa/IOReturnSPI.h
index ca4a6c2..ce1ef65 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#include "config.h"
-#include "objc_class.h"
+#import "config.h"
+#import "objc_class.h"
 
-#include "objc_instance.h"
-#include "WebScriptObject.h"
-#include "WebScriptObjectProtocol.h"
+#import "WebScriptObject.h"
+#import "WebScriptObjectProtocol.h"
+#import "objc_instance.h"
 
 namespace JSC {
 namespace Bindings {
index 993a6f5..5f285e9 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef BINDINGS_OBJC_INSTANCE_H_
-#define BINDINGS_OBJC_INSTANCE_H_
-
-#include "objc_class.h"
-#include "objc_utility.h"
+#import "objc_class.h"
+#import "objc_utility.h"
 
 namespace JSC {
 
@@ -75,13 +72,11 @@ private:
     virtual RuntimeObject* newRuntimeObject(ExecState*);
 
     RetainPtr<ObjectStructPtr> _instance;
-    mutable ObjcClass *_class;
-    ObjectStructPtr _pool;
-    int _beginCount;
+    mutable ObjcClass* _class { nullptr };
+    void* m_autoreleasePool { nullptr };
+    int _beginCount { 0 };
 };
 
 } // namespace Bindings
 
 } // namespace JSC
-
-#endif // BINDINGS_OBJC_INSTANCE_H_
index 68e5731..0a11247 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004, 2008-2009, 2013, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -40,6 +40,7 @@
 #import <wtf/MainThread.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/ThreadSpecific.h>
+#import <wtf/spi/cocoa/FoundationSPI.h>
 
 #ifdef NDEBUG
 #define OBJC_LOG(formatAndArgs...) ((void)0)
@@ -100,9 +101,6 @@ void ObjcInstance::moveGlobalExceptionToExecState(ExecState* exec)
 ObjcInstance::ObjcInstance(id instance, RefPtr<RootObject>&& rootObject) 
     : Instance(WTFMove(rootObject))
     , _instance(instance)
-    , _class(0)
-    , _pool(0)
-    , _beginCount(0)
 {
 }
 
@@ -133,8 +131,8 @@ ObjcInstance::~ObjcInstance()
 
 void ObjcInstance::virtualBegin()
 {
-    if (!_pool)
-        _pool = [[NSAutoreleasePool alloc] init];
+    if (!m_autoreleasePool)
+        m_autoreleasePool = objc_autoreleasePoolPush();
     _beginCount++;
 }
 
@@ -143,8 +141,9 @@ void ObjcInstance::virtualEnd()
     _beginCount--;
     ASSERT(_beginCount >= 0);
     if (!_beginCount) {
-        [_pool drain];
-        _pool = 0;
+        ASSERT(m_autoreleasePool);
+        objc_autoreleasePoolPop(m_autoreleasePool);
+        m_autoreleasePool = nullptr;
     }
 }
 
@@ -507,13 +506,11 @@ JSC::JSValue ObjcInstance::stringValue(ExecState* exec) const
 
 JSC::JSValue ObjcInstance::numberValue(ExecState*) const
 {
-    // FIXME:  Implement something sensible
     return jsNumber(0);
 }
 
 JSC::JSValue ObjcInstance::booleanValue() const
 {
-    // FIXME:  Implement something sensible
     return jsBoolean(false);
 }
 
index 87d0387..e7b1bdb 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#include "config.h"
-#include "objc_runtime.h"
-
-#include "JSDOMBinding.h"
-#include "ObjCRuntimeObject.h"
-#include "WebScriptObject.h"
-#include "WebScriptObjectProtocol.h"
-#include "objc_instance.h"
-#include "runtime_array.h"
-#include "runtime_object.h"
-#include <JavaScriptCore/Error.h>
-#include <JavaScriptCore/JSGlobalObject.h>
-#include <JavaScriptCore/JSLock.h>
-#include <wtf/RetainPtr.h>
+#import "config.h"
+#import "objc_runtime.h"
+
+#import "JSDOMBinding.h"
+#import "ObjCRuntimeObject.h"
+#import "WebScriptObject.h"
+#import "WebScriptObjectProtocol.h"
+#import "objc_instance.h"
+#import "runtime_array.h"
+#import "runtime_object.h"
+#import <JavaScriptCore/Error.h>
+#import <JavaScriptCore/JSGlobalObject.h>
+#import <JavaScriptCore/JSLock.h>
+#import <wtf/RetainPtr.h>
 
 using namespace WebCore;
 
index 12d052d..197043f 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#include "config.h"
-#include "objc_utility.h"
+#import "config.h"
+#import "objc_utility.h"
 
-#include "WebScriptObjectProtocol.h"
-#include "objc_instance.h"
-#include "runtime_array.h"
-#include "runtime_object.h"
-#include <JavaScriptCore/JSGlobalObject.h>
-#include <JavaScriptCore/JSLock.h>
-#include <wtf/Assertions.h>
+#import "WebScriptObjectProtocol.h"
+#import "objc_instance.h"
+#import "runtime_array.h"
+#import "runtime_object.h"
+#import <JavaScriptCore/JSGlobalObject.h>
+#import <JavaScriptCore/JSLock.h>
+#import <wtf/Assertions.h>
 
 #if !defined(_C_LNG_LNG)
 #define _C_LNG_LNG 'q'
index 703a67b..fc55134 100644 (file)
@@ -29,9 +29,6 @@
 #import "AudioBus.h"
 
 #import "AudioFileReader.h"
-#import <wtf/AutodrainedPool.h>
-#import <wtf/RefPtr.h>
-#import <Foundation/Foundation.h>
 
 @interface WebCoreAudioBundleClass : NSObject
 @end
@@ -43,16 +40,12 @@ namespace WebCore {
 
 RefPtr<AudioBus> AudioBus::loadPlatformResource(const char* name, float sampleRate)
 {
-    // This method can be called from other than the main thread, so we need an auto-release pool.
-    AutodrainedPool pool;
-    
-    NSBundle *bundle = [NSBundle bundleForClass:[WebCoreAudioBundleClass class]];
-    NSURL *audioFileURL = [bundle URLForResource:[NSString stringWithUTF8String:name] withExtension:@"wav" subdirectory:@"audio"];
-    NSDataReadingOptions options = NSDataReadingMappedIfSafe;
-    NSData *audioData = [NSData dataWithContentsOfURL:audioFileURL options:options error:nil];
-
-    if (audioData)
-        return createBusFromInMemoryAudioFile([audioData bytes], [audioData length], false, sampleRate);
+    @autoreleasepool {
+        NSBundle *bundle = [NSBundle bundleForClass:[WebCoreAudioBundleClass class]];
+        NSURL *audioFileURL = [bundle URLForResource:[NSString stringWithUTF8String:name] withExtension:@"wav" subdirectory:@"audio"];
+        if (NSData *audioData = [NSData dataWithContentsOfURL:audioFileURL options:NSDataReadingMappedIfSafe error:nil])
+            return createBusFromInMemoryAudioFile([audioData bytes], [audioData length], false, sampleRate);
+    }
 
     ASSERT_NOT_REACHED();
     return nullptr;
index 4a92bc6..43bb32a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #import "RuntimeApplicationChecks.h"
 #import "ThreadGlobalData.h"
 #import "WAKWindow.h"
+#import "WKUtilities.h"
 #import "WebCoreThreadInternal.h"
 #import "WebCoreThreadMessage.h"
 #import "WebCoreThreadRun.h"
-#import "WKUtilities.h"
-
+#import <Foundation/NSInvocation.h>
 #import <JavaScriptCore/InitializeThreading.h>
 #import <JavaScriptCore/JSLock.h>
+#import <libkern/OSAtomic.h>
+#import <objc/runtime.h>
 #import <wtf/Assertions.h>
 #import <wtf/MainThread.h>
 #import <wtf/RecursiveLockAdapter.h>
 #import <wtf/RunLoop.h>
 #import <wtf/Threading.h>
+#import <wtf/spi/cocoa/FoundationSPI.h>
 #import <wtf/text/AtomicString.h>
 
-#import <Foundation/NSInvocation.h>
-#import <libkern/OSAtomic.h>
-#import <objc/runtime.h>
-
 #define LOG_MESSAGES 0
 #define LOG_WEB_LOCK 0
 #define LOG_MAIN_THREAD_LOCKING 0
@@ -82,21 +81,11 @@ static void _WebThreadUnlock();
 
 @end
 
-using NSAutoreleasePoolMark = void*;
-#ifdef __cplusplus
-extern "C" {
-#endif
-extern NSAutoreleasePoolMark NSPushAutoreleasePool(unsigned ignored);
-extern void NSPopAutoreleasePool(NSAutoreleasePoolMark token);
-#ifdef __cplusplus
-}
-#endif
-
 static RecursiveLock webLock;
 static Lock webThreadReleaseLock;
 static RecursiveLock webCoreReleaseLock;
 
-static NSAutoreleasePoolMark autoreleasePoolMark;
+static void* autoreleasePoolMark;
 static CFRunLoopRef webThreadRunLoop;
 static NSRunLoop* webThreadNSRunLoop;
 static pthread_t webThread;
@@ -104,7 +93,7 @@ static BOOL isWebThreadLocked;
 static BOOL webThreadStarted;
 static unsigned webThreadLockCount;
 
-static NSAutoreleasePoolMark savedAutoreleasePoolMark;
+static void* savedAutoreleasePoolMark;
 static BOOL isNestedWebThreadRunLoop;
 typedef enum {
     PushOrPopAutoreleasePool,
@@ -465,7 +454,7 @@ static void WebRunLoopLockInternal(AutoreleasePoolOperation poolOperation)
 {
     _WebThreadLock();
     if (poolOperation == PushOrPopAutoreleasePool)
-        autoreleasePoolMark = NSPushAutoreleasePool(0);
+        autoreleasePoolMark = objc_autoreleasePoolPush();
     isWebThreadLocked = YES;
 }
 
@@ -479,7 +468,7 @@ static void WebRunLoopUnlockInternal(AutoreleasePoolOperation poolOperation)
     }
 
     if (poolOperation == PushOrPopAutoreleasePool)
-        NSPopAutoreleasePool(autoreleasePoolMark);
+        objc_autoreleasePoolPop(autoreleasePoolMark);
 
     _WebThreadUnlock();
     isWebThreadLocked = NO;
index 3d8f396..301da1e 100644 (file)
@@ -33,7 +33,6 @@
 #import <Foundation/Foundation.h>
 #import <limits>
 #import <pal/spi/cf/CFNetworkSPI.h>
-#import <wtf/AutodrainedPool.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/StdLibExtras.h>
 #import <wtf/cf/TypeCastsCF.h>
@@ -175,26 +174,28 @@ void ResourceResponse::platformLazyInit(InitLevel initLevel)
     if (m_isNull || !m_nsResponse)
         return;
     
-    AutodrainedPool pool;
+    @autoreleasepool {
 
-    NSHTTPURLResponse *httpResponse = [m_nsResponse.get() isKindOfClass:[NSHTTPURLResponse class]] ? (NSHTTPURLResponse *)m_nsResponse.get() : nullptr;
+        NSHTTPURLResponse *httpResponse = [m_nsResponse.get() isKindOfClass:[NSHTTPURLResponse class]] ? (NSHTTPURLResponse *)m_nsResponse.get() : nullptr;
+
+        if (m_initLevel < CommonFieldsOnly) {
+            m_url = [m_nsResponse.get() URL];
+            m_mimeType = [m_nsResponse.get() MIMEType];
+            m_expectedContentLength = [m_nsResponse.get() expectedContentLength];
+            // Stripping double quotes as a workaround for <rdar://problem/8757088>, can be removed once that is fixed.
+            m_textEncodingName = stripLeadingAndTrailingDoubleQuote([m_nsResponse.get() textEncodingName]);
+            m_httpStatusCode = httpResponse ? [httpResponse statusCode] : 0;
+        }
+        if (httpResponse) {
+            if (initLevel == AllFields) {
+                auto messageRef = CFURLResponseGetHTTPResponse([httpResponse _CFURLResponse]);
+                m_httpStatusText = extractHTTPStatusText(messageRef);
+                m_httpVersion = String(adoptCF(CFHTTPMessageCopyVersion(messageRef)).get()).convertToASCIIUppercase();
+                initializeHTTPHeaders(OnlyCommonHeaders::No, httpResponse, m_httpHeaderFields);
+            } else
+                initializeHTTPHeaders(OnlyCommonHeaders::Yes, httpResponse, m_httpHeaderFields);
+        }
 
-    if (m_initLevel < CommonFieldsOnly) {
-        m_url = [m_nsResponse.get() URL];
-        m_mimeType = [m_nsResponse.get() MIMEType];
-        m_expectedContentLength = [m_nsResponse.get() expectedContentLength];
-        // Stripping double quotes as a workaround for <rdar://problem/8757088>, can be removed once that is fixed.
-        m_textEncodingName = stripLeadingAndTrailingDoubleQuote([m_nsResponse.get() textEncodingName]);
-        m_httpStatusCode = httpResponse ? [httpResponse statusCode] : 0;
-    }
-    if (httpResponse) {
-        if (initLevel == AllFields) {
-            auto messageRef = CFURLResponseGetHTTPResponse([httpResponse _CFURLResponse]);
-            m_httpStatusText = extractHTTPStatusText(messageRef);
-            m_httpVersion = String(adoptCF(CFHTTPMessageCopyVersion(messageRef)).get()).convertToASCIIUppercase();
-            initializeHTTPHeaders(OnlyCommonHeaders::No, httpResponse, m_httpHeaderFields);
-        } else
-            initializeHTTPHeaders(OnlyCommonHeaders::Yes, httpResponse, m_httpHeaderFields);
     }
 
     m_initLevel = initLevel;
index af197c7..ff14b3c 100644 (file)
 #ifndef __LP64__
 
 #include "CarbonUtils.h"
-#import <pal/spi/cocoa/FoundationSPI.h>
+#import <wtf/spi/cocoa/FoundationSPI.h>
 
 extern CGImageRef _NSCreateImageRef( unsigned char *const bitmapData[5], int pixelsWide, int pixelsHigh, int bitsPerSample, int samplesPerPixel, int bitsPerPixel, int bytesPerRow, BOOL isPlanar, BOOL hasAlpha, NSString *colorSpaceName, CGColorSpaceRef customColorSpace, id sourceObj);
 
 static void                            PoolCleaner( EventLoopTimerRef inTimer, EventLoopIdleTimerMessage inState, void *inUserData );
 
-static NSAutoreleasePool*      sPool;
+static void* sPool;
 static unsigned numPools;
 static EventLoopRef poolLoop;
 
@@ -43,9 +43,9 @@ void                    HIWebViewRegisterClass( void );
 
 static unsigned getNSAutoreleasePoolCount(void)
 {
-    void* v = NSPushAutoreleasePool(0);
+    void* v = objc_autoreleasePoolPush();
     uintptr_t numPools = (uintptr_t)v;
-    NSPopAutoreleasePool(v);
+    objc_autoreleasePoolPop(v);
     return numPools;
 }
 
@@ -63,7 +63,7 @@ WebInitForCarbon()
         GetCurrentProcess( &process ); 
         NSApplicationLoad();
                 
-        sPool = [[NSAutoreleasePool allocWithZone:NULL] init];
+        sPool = objc_autoreleasePoolPush();
         numPools = getNSAutoreleasePoolCount();
         
         poolLoop = GetCurrentEventLoop ();
@@ -95,9 +95,8 @@ PoolCleaner( EventLoopTimerRef inTimer, EventLoopIdleTimerMessage inState, void
         if ( CFEqual( mode, kCFRunLoopDefaultMode ) && thisLoop == poolLoop) {
             unsigned currentNumPools = getNSAutoreleasePoolCount()-1;            
             if (currentNumPools == numPools){
-                [sPool drain];
-                
-                sPool = [[NSAutoreleasePool allocWithZone:NULL] init];
+                objc_autoreleasePoolPop(sPool);
+                sPool = objc_autoreleasePoolPush();
                 numPools = getNSAutoreleasePoolCount();
             }
         }
index 13e80ee..2e58374 100644 (file)
@@ -1,3 +1,23 @@
+2018-06-08  Darin Adler  <darin@apple.com>
+
+        [Cocoa] Remove all uses of NSAutoreleasePool as part of preparation for ARC
+        https://bugs.webkit.org/show_bug.cgi?id=186436
+
+        Reviewed by Anders Carlsson.
+
+        * Carbon/CarbonUtils.m: Updated include location of FoundationSPI.h.
+        (getNSAutoreleasePoolCount): Use objc_autoreleasePoolPush/Pop.
+        (WebInitForCarbon): Use objc_autoreleasePoolPush/Pop instead of NSAutoreleasePool object.
+        (PoolCleaner): Ditto.
+
+        * History/WebHistory.mm:
+        (-[WebHistoryPrivate loadHistoryGutsFromURL:savedItemsCount:collectDiscardedItemsInto:error:]):
+        Use @autoreleasepool instead of NSAutoreleasePool object. No need to do the "drain pool only
+        every 50 times"; the -[WebHistory loadFromURL] family of methods were once used by Safari, and
+        now hardly used if at all.
+        * WebView/WebView.mm:
+        (-[WebView rectsForTextMatches]): Ditto.
+
 2018-06-08  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [WebKit on watchOS] Upstream watchOS source additions to OpenSource (Part 1)
index 9cf8a8e..13832e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -591,41 +591,34 @@ static inline WebHistoryDateKey dateKey(NSTimeInterval date)
 
     int itemCountLimit = [self historyItemLimit];
     NSTimeInterval ageLimitDate = [[self ageLimitDate] timeIntervalSinceReferenceDate];
-    NSEnumerator *enumerator = [array objectEnumerator];
     BOOL ageLimitPassed = NO;
     BOOL itemLimitPassed = NO;
     ASSERT(*numberOfItemsLoaded == 0);
 
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    NSDictionary *itemAsDictionary;
-    while ((itemAsDictionary = [enumerator nextObject]) != nil) {
-        WebHistoryItem *item = [[WebHistoryItem alloc] initFromDictionaryRepresentation:itemAsDictionary];
-
-        // item without URL is useless; data on disk must have been bad; ignore
-        if ([item URLString]) {
-            // Test against date limit. Since the items are ordered newest to oldest, we can stop comparing
-            // once we've found the first item that's too old.
-            if (!ageLimitPassed && [item lastVisitedTimeInterval] <= ageLimitDate)
-                ageLimitPassed = YES;
-
-            if (ageLimitPassed || itemLimitPassed)
-                [discardedItems addObject:item];
-            else {
-                if ([self addItem:item discardDuplicate:YES])
-                    ++(*numberOfItemsLoaded);
-                if (*numberOfItemsLoaded == itemCountLimit)
-                    itemLimitPassed = YES;
-
-                // Draining the autorelease pool every 50 iterations was found by experimentation to be optimal
-                if (*numberOfItemsLoaded % 50 == 0) {
-                    [pool drain];
-                    pool = [[NSAutoreleasePool alloc] init];
+    for (NSDictionary *itemAsDictionary in array) {
+        @autoreleasepool {
+            WebHistoryItem *item = [[WebHistoryItem alloc] initFromDictionaryRepresentation:itemAsDictionary];
+
+            // item without URL is useless; data on disk must have been bad; ignore
+            if ([item URLString]) {
+                // Test against date limit. Since the items are ordered newest to oldest, we can stop comparing
+                // once we've found the first item that's too old.
+                if (!ageLimitPassed && [item lastVisitedTimeInterval] <= ageLimitDate)
+                    ageLimitPassed = YES;
+
+                if (ageLimitPassed || itemLimitPassed)
+                    [discardedItems addObject:item];
+                else {
+                    if ([self addItem:item discardDuplicate:YES])
+                        ++(*numberOfItemsLoaded);
+                    if (*numberOfItemsLoaded == itemCountLimit)
+                        itemLimitPassed = YES;
                 }
             }
+
+            [item release];
         }
-        [item release];
     }
-    [pool drain];
 
     return YES;
 }
index 0e2f7c2..4077e91 100644 (file)
@@ -7903,28 +7903,21 @@ static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSC::JSValue j
         if ([view conformsToProtocol:@protocol(WebMultipleTextMatches)]) {
             NSView <WebMultipleTextMatches> *documentView = (NSView <WebMultipleTextMatches> *)view;
             NSRect documentViewVisibleRect = [documentView visibleRect];
-            NSArray *originalRects = [documentView rectsForTextMatches];
-            unsigned rectCount = [originalRects count];
-            unsigned rectIndex;
-            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-            for (rectIndex = 0; rectIndex < rectCount; ++rectIndex) {
-                NSRect r = [[originalRects objectAtIndex:rectIndex] rectValue];
+            for (NSValue *rect in [documentView rectsForTextMatches]) {
+                NSRect r = [rect rectValue];
                 // Clip rect to document view's visible rect so rect is confined to subframe
                 r = NSIntersectionRect(r, documentViewVisibleRect);
                 if (NSIsEmptyRect(r))
                     continue;
-                
-                // Convert rect to our coordinate system
-                r = [documentView convertRect:r toView:self];
-                [result addObject:[NSValue valueWithRect:r]];
-                if (rectIndex % 10 == 0) {
-                    [pool drain];
-                    pool = [[NSAutoreleasePool alloc] init];
+
+                @autoreleasepool {
+                    // Convert rect to our coordinate system
+                    r = [documentView convertRect:r toView:self];
+                    [result addObject:[NSValue valueWithRect:r]];
                 }
             }
-            [pool drain];
         }
-        
+
         frame = incrementFrame(frame);
     } while (frame);
     
index 46aa07c..8b15b31 100644 (file)
@@ -1,3 +1,18 @@
+2018-06-08  Darin Adler  <darin@apple.com>
+
+        [Cocoa] Remove all uses of NSAutoreleasePool as part of preparation for ARC
+        https://bugs.webkit.org/show_bug.cgi?id=186436
+
+        Reviewed by Anders Carlsson.
+
+        * TestWebKitAPI/Tests/WebKitObjC/CustomProtocolsTest.mm:
+        (TestWebKitAPI::WebKit2CustomProtocolsTest_ProcessPoolDestroyedDuringLoading):
+        Use @autoreleasepool.
+        * TestWebKitAPI/Tests/mac/MenuTypesForMouseEvents.mm:
+        (TestWebKitAPI::buildAndPerformTest): Ditto.
+        * TestWebKitAPI/Tests/mac/StopLoadingFromDidFinishLoading.mm:
+        (TestWebKitAPI::WebKitLegacy_StopLoadingFromDidFinishLoading): Ditto.
+
 2018-06-08  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [WebKit on watchOS] Upstream watchOS source additions to OpenSource (Part 1)
index a6ee166..589c3d0 100644 (file)
@@ -34,7 +34,6 @@
 #import "TestProtocol.h"
 #import <WebKit/WKContextPrivate.h>
 #import <WebKit/WKProcessGroupPrivate.h>
-#import <wtf/AutodrainedPool.h>
 #import <wtf/RetainPtr.h>
 
 #if WK_API_ENABLED && PLATFORM(MAC)
@@ -171,8 +170,7 @@ TEST(WebKit2CustomProtocolsTest, ProcessPoolDestroyedDuringLoading)
 {
     [ProcessPoolDestroyedDuringLoadingProtocol registerWithScheme:@"custom"];
 
-    {
-        AutodrainedPool pool;
+    @autoreleasepool {
         auto browsingContextGroup = adoptNS([[WKBrowsingContextGroup alloc] initWithIdentifier:@"TestIdentifier"]);
         auto processGroup = adoptNS([[WKProcessGroup alloc] init]);
         auto wkView = adoptNS([[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup.get() browsingContextGroup:browsingContextGroup.get()]);
index 700254e..c91b09f 100644 (file)
@@ -29,7 +29,6 @@
 #import <Carbon/Carbon.h> // For GetCurrentEventTime
 #import <WebCore/PlatformEventFactoryMac.h>
 #import <pal/spi/mac/NSMenuSPI.h>
-#import <wtf/AutodrainedPool.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/mac/AppKitCompatibilityDeclarations.h>
 
@@ -42,25 +41,26 @@ static bool canCallMenuTypeForEvent()
 
 static void buildAndPerformTest(NSEventType buttonEvent, NSEventModifierFlags modifierFlags, WebCore::MouseButton expectedButton, NSMenuType expectedMenu)
 {
-    AutodrainedPool pool;
-    RetainPtr<WebView> webView = adoptNS([[WebView alloc] init]);
-    NSEvent *event = [NSEvent mouseEventWithType:buttonEvent
-                                        location:NSMakePoint(100, 100)
-                                   modifierFlags:modifierFlags
-                                       timestamp:GetCurrentEventTime()
-                                    windowNumber:[[webView window] windowNumber]
-                                         context:[NSGraphicsContext currentContext]
-                                     eventNumber:0
-                                      clickCount:0
-                                        pressure:0];
-    
-    auto pme = WebCore::PlatformEventFactory::createPlatformMouseEvent(event, nil, webView.get());
-    
-    EXPECT_EQ(expectedButton, pme.button());
-    EXPECT_TRUE(!modifierFlags || pme.modifierFlags() & modifierFlags);
-    EXPECT_EQ(expectedMenu, pme.menuTypeForEvent());
-    if (canCallMenuTypeForEvent())
-        EXPECT_EQ(expectedMenu, [NSMenu menuTypeForEvent:event]);
+    @autoreleasepool {
+        auto webView = adoptNS([[WebView alloc] init]);
+        NSEvent *event = [NSEvent mouseEventWithType:buttonEvent
+                                            location:NSMakePoint(100, 100)
+                                       modifierFlags:modifierFlags
+                                           timestamp:GetCurrentEventTime()
+                                        windowNumber:[[webView window] windowNumber]
+                                             context:[NSGraphicsContext currentContext]
+                                         eventNumber:0
+                                          clickCount:0
+                                            pressure:0];
+
+        auto pme = WebCore::PlatformEventFactory::createPlatformMouseEvent(event, nil, webView.get());
+
+        EXPECT_EQ(expectedButton, pme.button());
+        EXPECT_TRUE(!modifierFlags || pme.modifierFlags() & modifierFlags);
+        EXPECT_EQ(expectedMenu, pme.menuTypeForEvent());
+        if (canCallMenuTypeForEvent())
+            EXPECT_EQ(expectedMenu, [NSMenu menuTypeForEvent:event]);
+    }
 }
 
 TEST(WebKitLegacy, MenuAndButtonForNormalLeftClick)
index 08dc660..c0e23ca 100644 (file)
  */
 
 #import "config.h"
+
 #import "PlatformUtilities.h"
-#import <wtf/AutodrainedPool.h>
 #import <wtf/RetainPtr.h>
 
-@interface StopLoadingFromDidFinishLoadingDelegate : NSObject <WebResourceLoadDelegate> {
-}
+@interface StopLoadingFromDidFinishLoadingDelegate : NSObject <WebResourceLoadDelegate>
 @end
 
 static bool finished = false;
@@ -48,12 +47,12 @@ namespace TestWebKitAPI {
 
 TEST(WebKitLegacy, StopLoadingFromDidFinishLoading)
 {
-    AutodrainedPool pool;
-    RetainPtr<WebView> webView = adoptNS([[WebView alloc] init]);
-    RetainPtr<StopLoadingFromDidFinishLoadingDelegate> delegate = adoptNS([[StopLoadingFromDidFinishLoadingDelegate alloc] init]);
-    webView.get().resourceLoadDelegate = delegate.get();
-    [webView.get().mainFrame loadHTMLString:@"Hello, World!" baseURL:[NSURL URLWithString:@""]];
-    Util::run(&finished);
+    @autoreleasepool {
+        auto webView = adoptNS([[WebView alloc] init]);
+        webView.get().resourceLoadDelegate = adoptNS([[StopLoadingFromDidFinishLoadingDelegate alloc] init]).get();
+        [webView.get().mainFrame loadHTMLString:@"Hello, World!" baseURL:[NSURL URLWithString:@""]];
+        Util::run(&finished);
+    }
     // No crash means the test passed.
 }