Title: [283225] trunk/Source/WebKitLegacy/mac
Revision
283225
Author
[email protected]
Date
2021-09-29 09:12:31 -0700 (Wed, 29 Sep 2021)

Log Message

Make WebLocalizedString() thread-safe
https://bugs.webkit.org/show_bug.cgi?id=230954

Reviewed by Alexey Proskuryakov.

Make WebLocalizedString() thread-safe. It takes minimal effort to make it thread-safe given
that the NSBundle API is thread-safe [1] and clients keep calling it on the background thread.

[1] https://developer.apple.com/documentation/foundation/nslocalizedstringwithdefaultvalue
"As of OS X 10.11 and iOS 9, NSBundle is thread-safe. As such, you can safely call
 NSLocalizedStringWithDefaultValue from any execution context."

* Misc/WebLocalizableStrings.mm:

Modified Paths

Diff

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (283224 => 283225)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-09-29 16:10:30 UTC (rev 283224)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-09-29 16:12:31 UTC (rev 283225)
@@ -1,3 +1,19 @@
+2021-09-29  Chris Dumez  <[email protected]>
+
+        Make WebLocalizedString() thread-safe
+        https://bugs.webkit.org/show_bug.cgi?id=230954
+
+        Reviewed by Alexey Proskuryakov.
+
+        Make WebLocalizedString() thread-safe. It takes minimal effort to make it thread-safe given
+        that the NSBundle API is thread-safe [1] and clients keep calling it on the background thread.
+
+        [1] https://developer.apple.com/documentation/foundation/nslocalizedstringwithdefaultvalue
+        "As of OS X 10.11 and iOS 9, NSBundle is thread-safe. As such, you can safely call
+         NSLocalizedStringWithDefaultValue from any execution context."
+
+        * Misc/WebLocalizableStrings.mm:
+
 2021-09-28  Chris Dumez  <[email protected]>
 
         Move Cross-Origin-Opener-Policy handling to the NetworkProcess

Modified: trunk/Source/WebKitLegacy/mac/Misc/WebLocalizableStrings.mm (283224 => 283225)


--- trunk/Source/WebKitLegacy/mac/Misc/WebLocalizableStrings.mm	2021-09-29 16:10:30 UTC (rev 283224)
+++ trunk/Source/WebKitLegacy/mac/Misc/WebLocalizableStrings.mm	2021-09-29 16:12:31 UTC (rev 283225)
@@ -37,17 +37,13 @@
 
 NSString *WebLocalizedString(WebLocalizableStringsBundle *stringsBundle, const char *key)
 {
-    // This function is not thread-safe due at least to its unguarded use of the mainBundle static variable
-    // and its use of [NSBundle localizedStringForKey:::], which is not guaranteed to be thread-safe. If
-    // we decide we need to use this on background threads, we'll need to add locking here and make sure
-    // it doesn't affect performance.
-#if !PLATFORM(IOS_FAMILY)
-    ASSERT(isMainThread());
-#endif
-
     NSBundle *bundle;
     if (stringsBundle == NULL) {
-        static NeverDestroyed<RetainPtr<NSBundle>> mainBundle = [NSBundle mainBundle];
+        static LazyNeverDestroyed<RetainPtr<NSBundle>> mainBundle;
+        static std::once_flag flag;
+        std::call_once(flag, [] () {
+            mainBundle.construct([NSBundle mainBundle]);
+        });
         ASSERT(mainBundle.get());
         bundle = mainBundle.get().get();
     } else {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to