Cherry-pick 0d08a5fd7147. rdar://133862081
Use LazyNeverDestroyed in `static TextCheckerState& mutableState()`
https://bugs.webkit.org/show_bug.cgi?id=280209
rdar://133862081
Reviewed by Alex Christensen.
Speculative fix. Crash reports indicate that mutableState() can be corrupted such that it contains
non-bool values. Use LazyNeverDestroyed + dispatch_once to avoid issues when statically initializing this
object from multiple threads.
* Source/WebKit/UIProcess/mac/TextCheckerMac.mm:
(WebKit::mutableState):
Canonical link: https://commits.webkit.org/284120@main
Canonical link: https://commits.webkit.org/280938.373@safari-7619-branch
diff --git a/Source/WebKit/UIProcess/mac/TextCheckerMac.mm b/Source/WebKit/UIProcess/mac/TextCheckerMac.mm
index cb368a8..1cb4d59 100644
--- a/Source/WebKit/UIProcess/mac/TextCheckerMac.mm
+++ b/Source/WebKit/UIProcess/mac/TextCheckerMac.mm
@@ -97,7 +97,9 @@
static TextCheckerState& mutableState()
{
- static NeverDestroyed state = [] {
+ static LazyNeverDestroyed<TextCheckerState> state;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
TextCheckerState initialState;
initialState.isContinuousSpellCheckingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebContinuousSpellCheckingEnabled] && TextChecker::isContinuousSpellCheckingAllowed();
initialState.isGrammarCheckingEnabled = shouldGrammarCheckingBeEnabled();
@@ -106,8 +108,8 @@
initialState.isAutomaticQuoteSubstitutionEnabled = shouldAutomaticQuoteSubstitutionBeEnabled();
initialState.isAutomaticDashSubstitutionEnabled = shouldAutomaticDashSubstitutionBeEnabled();
initialState.isAutomaticLinkDetectionEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebAutomaticLinkDetectionEnabled];
- return initialState;
- }();
+ state.construct(WTFMove(initialState));
+ });
return state;
}