Title: [273848] trunk
Revision
273848
Author
cdu...@apple.com
Date
2021-03-03 15:07:08 -0800 (Wed, 03 Mar 2021)

Log Message

Use adoptNS() right away after calling [obj copy] / [obj mutableCopy]
https://bugs.webkit.org/show_bug.cgi?id=222634

Reviewed by Darin Adler.

Use adoptNS() right away after calling [obj copy] / [obj mutableCopy] to minimize the chance of leaks.

Source/WebCore:

* editing/cocoa/HTMLConverter.mm:
(defaultParagraphStyle):
* platform/cocoa/SystemVersion.mm:
(WebCore::createSystemMarketingVersion):
(WebCore::systemMarketingVersion):

Source/WebKit:

* Shared/ApplePay/ApplePayPaymentSetupFeatures.mm:
(WebKit::PaymentSetupFeatures::decode):
* Shared/ApplePay/PaymentSetupConfiguration.mm:
(WebKit::PaymentSetupConfiguration::decode):
* Shared/ApplePay/cocoa/PaymentSetupConfiguration.mm:
(WebKitAdditions::PaymentSetupConfiguration::decode):
* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::systemDirectoryPath):
* UIProcess/mac/ServicesController.mm:
(WebKit::ServicesController::refreshExistingServices):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::temporaryPDFDirectoryPath):

Source/WebKitLegacy/mac:

* Misc/WebNSPasteboardExtras.mm:
(_writableTypesForImageWithArchive):
* WebCoreSupport/WebApplicationCache.mm:
(overrideBundleIdentifier):
(+[WebApplicationCache initializeWithBundleIdentifier:]):
(applicationCacheBundleIdentifier):
* WebView/WebPreferences.mm:
(classIBCreatorID):
(+[WebPreferences _setIBCreatorID:]):
(+[WebPreferences _IBCreatorID]):

Tools:

* TestWebKitAPI/Tests/WebKit/mac/ContextMenuMouseEvents.mm:
(TestWebKitAPI::runTest):
* TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (273847 => 273848)


--- trunk/Source/WebCore/ChangeLog	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebCore/ChangeLog	2021-03-03 23:07:08 UTC (rev 273848)
@@ -1,3 +1,18 @@
+2021-03-03  Chris Dumez  <cdu...@apple.com>
+
+        Use adoptNS() right away after calling [obj copy] / [obj mutableCopy]
+        https://bugs.webkit.org/show_bug.cgi?id=222634
+
+        Reviewed by Darin Adler.
+
+        Use adoptNS() right away after calling [obj copy] / [obj mutableCopy] to minimize the chance of leaks.
+
+        * editing/cocoa/HTMLConverter.mm:
+        (defaultParagraphStyle):
+        * platform/cocoa/SystemVersion.mm:
+        (WebCore::createSystemMarketingVersion):
+        (WebCore::systemMarketingVersion):
+
 2021-03-03  Zalan Bujtas  <za...@apple.com>
 
         [LFC][IFC] Enable simplified vertical alignment for non-empty inline boxes

Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (273847 => 273848)


--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -517,13 +517,13 @@
 
 static NSParagraphStyle *defaultParagraphStyle()
 {
-    static NSMutableParagraphStyle *defaultParagraphStyle = nil;
-    if (!defaultParagraphStyle) {
-        defaultParagraphStyle = [[PlatformNSParagraphStyle defaultParagraphStyle] mutableCopy];
+    static auto defaultParagraphStyle = makeNeverDestroyed([] {
+        auto defaultParagraphStyle = adoptNS([[PlatformNSParagraphStyle defaultParagraphStyle] mutableCopy]);
         [defaultParagraphStyle setDefaultTabInterval:36];
         [defaultParagraphStyle setTabStops:@[]];
-    }
-    return defaultParagraphStyle;
+        return defaultParagraphStyle;
+    }());
+    return defaultParagraphStyle.get().get();
 }
 
 RefPtr<CSSValue> HTMLConverterCaches::computedStylePropertyForElement(Element& element, CSSPropertyID propertyId)

Modified: trunk/Source/WebCore/platform/cocoa/SystemVersion.mm (273847 => 273848)


--- trunk/Source/WebCore/platform/cocoa/SystemVersion.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebCore/platform/cocoa/SystemVersion.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -27,7 +27,7 @@
 
 namespace WebCore {
 
-static NSString *createSystemMarketingVersion()
+static RetainPtr<NSString> createSystemMarketingVersion()
 {
     // Can't use -[NSProcessInfo operatingSystemVersionString] because it has too much stuff we don't want.
     NSString *systemLibraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSSystemDomainMask, YES) objectAtIndex:0];
@@ -37,13 +37,13 @@
 #endif
     NSString *systemVersionPlistPath = [systemLibraryPath stringByAppendingPathComponent:@"CoreServices/SystemVersion.plist"];
     NSDictionary *systemVersionInfo = [NSDictionary dictionaryWithContentsOfFile:systemVersionPlistPath];
-    return [[systemVersionInfo objectForKey:@"ProductVersion"] copy];
+    return adoptNS([[systemVersionInfo objectForKey:@"ProductVersion"] copy]);
 }
 
 NSString *systemMarketingVersion()
 {
-    static NSString *version = createSystemMarketingVersion();
-    return version;
+    static NeverDestroyed<RetainPtr<NSString>> version = createSystemMarketingVersion();
+    return version.get().get();
 }
 
 }

Modified: trunk/Source/WebKit/ChangeLog (273847 => 273848)


--- trunk/Source/WebKit/ChangeLog	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKit/ChangeLog	2021-03-03 23:07:08 UTC (rev 273848)
@@ -1,3 +1,25 @@
+2021-03-03  Chris Dumez  <cdu...@apple.com>
+
+        Use adoptNS() right away after calling [obj copy] / [obj mutableCopy]
+        https://bugs.webkit.org/show_bug.cgi?id=222634
+
+        Reviewed by Darin Adler.
+
+        Use adoptNS() right away after calling [obj copy] / [obj mutableCopy] to minimize the chance of leaks.
+
+        * Shared/ApplePay/ApplePayPaymentSetupFeatures.mm:
+        (WebKit::PaymentSetupFeatures::decode):
+        * Shared/ApplePay/PaymentSetupConfiguration.mm:
+        (WebKit::PaymentSetupConfiguration::decode):
+        * Shared/ApplePay/cocoa/PaymentSetupConfiguration.mm:
+        (WebKitAdditions::PaymentSetupConfiguration::decode):
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::systemDirectoryPath):
+        * UIProcess/mac/ServicesController.mm:
+        (WebKit::ServicesController::refreshExistingServices):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::temporaryPDFDirectoryPath):
+
 2021-03-03  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, reverting r273727.

Modified: trunk/Source/WebKit/Shared/ApplePay/ApplePayPaymentSetupFeatures.mm (273847 => 273848)


--- trunk/Source/WebKit/Shared/ApplePay/ApplePayPaymentSetupFeatures.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKit/Shared/ApplePay/ApplePayPaymentSetupFeatures.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -64,7 +64,7 @@
 
 Optional<PaymentSetupFeatures> PaymentSetupFeatures::decode(IPC::Decoder& decoder)
 {
-    static NSArray *allowedClasses;
+    static NeverDestroyed<RetainPtr<NSArray>> allowedClasses;
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
         auto allowed = adoptNS([[NSMutableArray alloc] initWithCapacity:2]);
@@ -71,10 +71,10 @@
         [allowed addObject:[NSArray class]];
         if (auto pkPaymentSetupFeatureClass = PAL::getPKPaymentSetupFeatureClass())
             [allowed addObject:pkPaymentSetupFeatureClass];
-        allowedClasses = [allowed copy];
+        allowedClasses.get() = adoptNS([allowed copy]);
     });
 
-    auto platformFeatures = IPC::decode<NSArray<PKPaymentSetupFeature *>>(decoder, allowedClasses);
+    auto platformFeatures = IPC::decode<NSArray<PKPaymentSetupFeature *>>(decoder, allowedClasses.get().get());
     if (!platformFeatures)
         return WTF::nullopt;
 

Modified: trunk/Source/WebKit/Shared/ApplePay/PaymentSetupConfiguration.mm (273847 => 273848)


--- trunk/Source/WebKit/Shared/ApplePay/PaymentSetupConfiguration.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKit/Shared/ApplePay/PaymentSetupConfiguration.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -84,16 +84,16 @@
 
 Optional<PaymentSetupConfiguration> PaymentSetupConfiguration::decode(IPC::Decoder& decoder)
 {
-    static NSArray *allowedClasses;
+    static NeverDestroyed<RetainPtr<NSArray>> allowedClasses;
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
         auto allowed = adoptNS([[NSMutableArray alloc] initWithCapacity:1]);
         if (auto pkPaymentSetupConfigurationClass = PAL::getPKPaymentSetupConfigurationClass())
             [allowed addObject:pkPaymentSetupConfigurationClass];
-        allowedClasses = [allowed copy];
+        allowedClasses.get() = adoptNS([allowed copy]);
     });
 
-    auto configuration = IPC::decode<PKPaymentSetupConfiguration>(decoder, allowedClasses);
+    auto configuration = IPC::decode<PKPaymentSetupConfiguration>(decoder, allowedClasses.get().get());
     if (!configuration)
         return WTF::nullopt;
 

Modified: trunk/Source/WebKit/Shared/ApplePay/cocoa/PaymentSetupConfiguration.mm (273847 => 273848)


--- trunk/Source/WebKit/Shared/ApplePay/cocoa/PaymentSetupConfiguration.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKit/Shared/ApplePay/cocoa/PaymentSetupConfiguration.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -61,16 +61,16 @@
 
 Optional<PaymentSetupConfiguration> PaymentSetupConfiguration::decode(IPC::Decoder& decoder)
 {
-    static NSArray *allowedClasses;
+    static NeverDestroyed<RetainPtr<NSArray>> allowedClasses;
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
         auto allowed = adoptNS([[NSMutableArray alloc] initWithCapacity:1]);
         if (auto pkPaymentSetupConfigurationClass = PAL::getPKPaymentSetupConfigurationClass())
             [allowed addObject:pkPaymentSetupConfigurationClass];
-        allowedClasses = [allowed copy];
+        allowedClasses.get() = adoptNS([allowed copy]);
     });
 
-    auto configuration = IPC::decode<PKPaymentSetupConfiguration>(decoder, allowedClasses);
+    auto configuration = IPC::decode<PKPaymentSetupConfiguration>(decoder, allowedClasses.get().get());
     if (!configuration)
         return WTF::nullopt;
 

Modified: trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm (273847 => 273848)


--- trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -100,7 +100,7 @@
 
 static NSString *systemDirectoryPath()
 {
-    static NSString *path = [^{
+    static NeverDestroyed<RetainPtr<NSString>> path = adoptNS([^{
 #if PLATFORM(IOS_FAMILY_SIMULATOR)
         char *simulatorRoot = getenv("SIMULATOR_ROOT");
         return simulatorRoot ? [NSString stringWithFormat:@"%s/System/", simulatorRoot] : @"/System/";
@@ -107,9 +107,9 @@
 #else
         return @"/System/";
 #endif
-    }() copy];
+    }() copy]);
 
-    return path;
+    return path.get().get();
 }
 
 void ProcessLauncher::launchProcess()

Modified: trunk/Source/WebKit/UIProcess/mac/ServicesController.mm (273847 => 273848)


--- trunk/Source/WebKit/UIProcess/mac/ServicesController.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKit/UIProcess/mac/ServicesController.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -101,19 +101,20 @@
             m_hasSelectionServices = hasServices;
         });
 
-        static NSAttributedString *attributedStringWithRichContent = [] {
-            NSMutableAttributedString *richString;
-            dispatch_sync(dispatch_get_main_queue(), [&richString] {
+        static NeverDestroyed<RetainPtr<NSAttributedString>> attributedStringWithRichContent;
+        static std::once_flag attributedStringWithRichContentOnceFlag;
+        std::call_once(attributedStringWithRichContentOnceFlag, [&] {
+            dispatch_sync(dispatch_get_main_queue(), [&] {
                 auto attachment = adoptNS([[NSTextAttachment alloc] init]);
                 auto cell = adoptNS([[NSTextAttachmentCell alloc] initImageCell:image]);
                 [attachment setAttachmentCell:cell.get()];
-                richString = [[NSAttributedString attributedStringWithAttachment:attachment.get()] mutableCopy];
+                auto richString = adoptNS([[NSAttributedString attributedStringWithAttachment:attachment.get()] mutableCopy]);
                 [richString appendAttributedString:attributedString];
+                attributedStringWithRichContent.get() = WTFMove(richString);
             });
-            return richString;
-        }();
+        });
 
-        hasCompatibleServicesForItems(serviceLookupGroup.get(), @[ attributedStringWithRichContent ], [this] (bool hasServices) {
+        hasCompatibleServicesForItems(serviceLookupGroup.get(), @[ attributedStringWithRichContent.get().get() ], [this] (bool hasServices) {
             m_hasRichContentServices = hasServices;
         });
 

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (273847 => 273848)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -411,17 +411,16 @@
 
 static NSString *temporaryPDFDirectoryPath()
 {
-    static NSString *temporaryPDFDirectoryPath;
-
-    if (!temporaryPDFDirectoryPath) {
+    static auto temporaryPDFDirectoryPath = makeNeverDestroyed([] {
         NSString *temporaryDirectoryTemplate = [NSTemporaryDirectory() stringByAppendingPathComponent:@"WebKitPDFs-XXXXXX"];
         CString templateRepresentation = [temporaryDirectoryTemplate fileSystemRepresentation];
 
         if (mkdtemp(templateRepresentation.mutableData()))
-            temporaryPDFDirectoryPath = [[[NSFileManager defaultManager] stringWithFileSystemRepresentation:templateRepresentation.data() length:templateRepresentation.length()] copy];
-    }
+            return adoptNS([[[NSFileManager defaultManager] stringWithFileSystemRepresentation:templateRepresentation.data() length:templateRepresentation.length()] copy]);
+        return RetainPtr<id> { };
+    }());
 
-    return temporaryPDFDirectoryPath;
+    return temporaryPDFDirectoryPath.get().get();
 }
 
 static NSString *pathToPDFOnDisk(const String& suggestedFilename)

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (273847 => 273848)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-03-03 23:07:08 UTC (rev 273848)
@@ -1,3 +1,23 @@
+2021-03-03  Chris Dumez  <cdu...@apple.com>
+
+        Use adoptNS() right away after calling [obj copy] / [obj mutableCopy]
+        https://bugs.webkit.org/show_bug.cgi?id=222634
+
+        Reviewed by Darin Adler.
+
+        Use adoptNS() right away after calling [obj copy] / [obj mutableCopy] to minimize the chance of leaks.
+
+        * Misc/WebNSPasteboardExtras.mm:
+        (_writableTypesForImageWithArchive):
+        * WebCoreSupport/WebApplicationCache.mm:
+        (overrideBundleIdentifier):
+        (+[WebApplicationCache initializeWithBundleIdentifier:]):
+        (applicationCacheBundleIdentifier):
+        * WebView/WebPreferences.mm:
+        (classIBCreatorID):
+        (+[WebPreferences _setIBCreatorID:]):
+        (+[WebPreferences _IBCreatorID]):
+
 2021-03-03  Megan Gardner  <megan_gard...@apple.com>
 
         Preserve information about the origin of the app highlight request

Modified: trunk/Source/WebKitLegacy/mac/Misc/WebNSPasteboardExtras.mm (273847 => 273848)


--- trunk/Source/WebKitLegacy/mac/Misc/WebNSPasteboardExtras.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKitLegacy/mac/Misc/WebNSPasteboardExtras.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -81,18 +81,15 @@
     return types.get().get();
 }
 
-static inline NSArray *_createWritableTypesForImageWithArchive()
-{
-    NSMutableArray *types = [_writableTypesForImageWithoutArchive() mutableCopy];
-    [types addObject:legacyRTFDPasteboardType()];
-    [types addObject:WebArchivePboardType];
-    return types;
-}
-
 static NSArray *_writableTypesForImageWithArchive (void)
 {
-    static NSArray *types = _createWritableTypesForImageWithArchive();
-    return types;
+    static auto types = makeNeverDestroyed([] {
+        auto types = adoptNS([_writableTypesForImageWithoutArchive() mutableCopy]);
+        [types addObject:legacyRTFDPasteboardType()];
+        [types addObject:WebArchivePboardType];
+        return types;
+    }());
+    return types.get().get();
 }
 
 + (NSArray *)_web_writableTypesForImageIncludingArchive:(BOOL)hasArchive

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebApplicationCache.mm (273847 => 273848)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebApplicationCache.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebApplicationCache.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -42,7 +42,11 @@
 @implementation WebApplicationCache
 
 #if PLATFORM(IOS_FAMILY)
-static NSString *overrideBundleIdentifier;
+static RetainPtr<NSString>& overrideBundleIdentifier()
+{
+    static NeverDestroyed<RetainPtr<NSString>> overrideBundleIdentifier;
+    return overrideBundleIdentifier;
+}
 
 // FIXME: This will be removed when WebKitInitializeApplicationCachePathIfNecessary()
 // is moved from WebView.mm to WebKitInitializeApplicationCacheIfNecessary() in this file.
@@ -55,8 +59,8 @@
 
     WebCore::SQLiteDatabaseTracker::setClient(&WebCore::WebSQLiteDatabaseTrackerClient::sharedWebSQLiteDatabaseTrackerClient());
 
-    ASSERT(!overrideBundleIdentifier);
-    overrideBundleIdentifier = [bundleIdentifier copy];
+    ASSERT(!overrideBundleIdentifier());
+    overrideBundleIdentifier() = adoptNS([bundleIdentifier copy]);
 
     initialized = YES;
 }
@@ -65,8 +69,8 @@
 static NSString *applicationCacheBundleIdentifier()
 {
 #if PLATFORM(IOS_FAMILY)
-    if (overrideBundleIdentifier)
-        return overrideBundleIdentifier;
+    if (overrideBundleIdentifier())
+        return overrideBundleIdentifier().get();
     if (WebCore::IOSApplication::isMobileSafari())
         return @"com.apple.WebAppCache";
 #endif

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebPreferences.mm (273847 => 273848)


--- trunk/Source/WebKitLegacy/mac/WebView/WebPreferences.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebPreferences.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -1654,12 +1654,15 @@
         @{ WebKitDefaultTextEncodingNamePreferenceKey: defaultTextEncodingNameForSystemLanguage() }];
 }
 
-static NSString *classIBCreatorID = nil;
+static RetainPtr<NSString>& classIBCreatorID()
+{
+    static NeverDestroyed<RetainPtr<NSString>> classIBCreatorID;
+    return classIBCreatorID;
+}
 
 + (void)_setIBCreatorID:(NSString *)string
 {
-    auto old = adoptNS(classIBCreatorID);
-    classIBCreatorID = [string copy];
+    classIBCreatorID() = adoptNS([string copy]);
 }
 
 - (BOOL)isDOMPasteAllowed
@@ -2954,7 +2957,7 @@
 
 + (NSString *)_IBCreatorID
 {
-    return classIBCreatorID;
+    return classIBCreatorID().get();
 }
 
 + (NSString *)_concatenateKeyWithIBCreatorID:(NSString *)key

Modified: trunk/Tools/ChangeLog (273847 => 273848)


--- trunk/Tools/ChangeLog	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Tools/ChangeLog	2021-03-03 23:07:08 UTC (rev 273848)
@@ -1,3 +1,17 @@
+2021-03-03  Chris Dumez  <cdu...@apple.com>
+
+        Use adoptNS() right away after calling [obj copy] / [obj mutableCopy]
+        https://bugs.webkit.org/show_bug.cgi?id=222634
+
+        Reviewed by Darin Adler.
+
+        Use adoptNS() right away after calling [obj copy] / [obj mutableCopy] to minimize the chance of leaks.
+
+        * TestWebKitAPI/Tests/WebKit/mac/ContextMenuMouseEvents.mm:
+        (TestWebKitAPI::runTest):
+        * TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm:
+        (TEST):
+
 2021-03-03  Sam Sneddon  <gsnedd...@apple.com>
 
         Move LayoutTestFinder.skip_tests to Manager._skip_tests

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuMouseEvents.mm (273847 => 273848)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuMouseEvents.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuMouseEvents.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -55,10 +55,10 @@
     [webView setUIDelegate:uiDelegate.get()];
 
     __block bool done = false;
-    __block void(^completionHandlerCopy)(NSMenu *);
+    __block BlockPtr<void(NSMenu *)> completionHandlerCopy;
     [uiDelegate setGetContextMenuFromProposedMenu:^(NSMenu *, _WKContextMenuElementInfo *, id <NSSecureCoding>, void (^completionHandler)(NSMenu *)) {
         dispatch_async(dispatch_get_main_queue(), ^{
-            completionHandlerCopy = [completionHandler copy];
+            completionHandlerCopy = completionHandler;
             done = true;
         });
     }];

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm (273847 => 273848)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm	2021-03-03 23:00:40 UTC (rev 273847)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UserContentController.mm	2021-03-03 23:07:08 UTC (rev 273848)
@@ -132,7 +132,7 @@
         TestWebKitAPI::Util::run(&isDoneWithNavigation);
 
     __block bool isDoneEvaluatingScript = false;
-    __block NSString *resultValue = @"";
+    __block RetainPtr<NSString> resultValue = @"";
     [webView evaluateJavaScript:
         @"var result;"
          "if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.testHandler) {"
@@ -142,13 +142,13 @@
          "} " 
          "result;"
          completionHandler:^(id value, NSError *error) {
-            resultValue = [((NSDictionary *)value)[@"result"] copy];
+            resultValue = ((NSDictionary *)value)[@"result"];
             isDoneEvaluatingScript = true;
         }];
 
     TestWebKitAPI::Util::run(&isDoneEvaluatingScript);
 
-    EXPECT_WK_STREQ(@"PASS", resultValue);
+    EXPECT_WK_STREQ(@"PASS", resultValue.get());
 }
 
 TEST(WKUserContentController, ScriptMessageHandlerBasicRemove)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to