Bug 208969

Summary: REGRESSION(r254389): Cordova throws an exception because it expects a hyphen inside navigator.locale
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, benjamin, cdumez, cmarcelo, darin, dino, ews-watchlist, ggaren, jonlee, krollin, simon.fraser, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 209030    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
WIP
none
Patch
darin: review+
Patch for committing none

Description Myles C. Maxfield 2020-03-11 19:27:33 PDT
REGRESSION(r254389): Cordova throws an exception because it expects a hyphen inside navigator.locale
Comment 1 Myles C. Maxfield 2020-03-11 19:29:15 PDT
Created attachment 393329 [details]
Patch
Comment 2 Myles C. Maxfield 2020-03-11 19:29:18 PDT
<rdar://problem/59845517>
Comment 3 Keith Rollin 2020-03-11 20:52:42 PDT
Comment on attachment 393329 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393329&action=review

> Source/WTF/wtf/cocoa/LanguageCocoa.mm:40
> +#elif PLATFORM(IOS_FAMILY)
> +    static bool applicationVersionCheck = dyld_get_program_sdk_version() >= DYLD_IOS_VERSION_13_4;

I want to make sure this platform and version checking is correct. The PLATFORM(IOS_FAMILY) check will be True for tvOS and watchOS, as well as iOS. But that DYLD_IOS_VERSION_13_4 seems to be iOS-only. So should the pre-processor conditional actually be just PLATFORM(IOS)? And what should happen with macCatalyst? PLATFORM(IOS) will return False for macCatalyst, so if we want to support that platform, we'd also need a PLATFORM(MACCATALYST) check (I assume the iOS version number would be appropriate for that platform?).
Comment 4 Chris Dumez 2020-03-12 07:41:54 PDT
Comment on attachment 393329 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393329&action=review

> Source/WTF/wtf/cocoa/LanguageCocoa.mm:38
> +    static bool applicationVersionCheck = dyld_get_program_sdk_version() >= DYLD_MACOSX_VERSION_10_15_4;

I don't think calling dyld_get_program_sdk_version() in the WebKit2 WebContent process will do what you want. AFAIK, dyld_get_program_sdk_version() will only do what you want in the wK2 UIProcess or WK1.
Comment 5 Myles C. Maxfield 2020-03-12 18:04:27 PDT
Comment on attachment 393329 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393329&action=review

>> Source/WTF/wtf/cocoa/LanguageCocoa.mm:38
>> +    static bool applicationVersionCheck = dyld_get_program_sdk_version() >= DYLD_MACOSX_VERSION_10_15_4;
> 
> I don't think calling dyld_get_program_sdk_version() in the WebKit2 WebContent process will do what you want. AFAIK, dyld_get_program_sdk_version() will only do what you want in the wK2 UIProcess or WK1.

Good catch! I'm pursuing this in https://bugs.webkit.org/show_bug.cgi?id=209030.
Comment 6 Myles C. Maxfield 2020-03-13 13:52:21 PDT
Comment on attachment 393329 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393329&action=review

>> Source/WTF/wtf/cocoa/LanguageCocoa.mm:40
>> +    static bool applicationVersionCheck = dyld_get_program_sdk_version() >= DYLD_IOS_VERSION_13_4;
> 
> I want to make sure this platform and version checking is correct. The PLATFORM(IOS_FAMILY) check will be True for tvOS and watchOS, as well as iOS. But that DYLD_IOS_VERSION_13_4 seems to be iOS-only. So should the pre-processor conditional actually be just PLATFORM(IOS)? And what should happen with macCatalyst? PLATFORM(IOS) will return False for macCatalyst, so if we want to support that platform, we'd also need a PLATFORM(MACCATALYST) check (I assume the iOS version number would be appropriate for that platform?).

From my testing:

tvOS: 0xD0400
watchOS: 0xD0200
macOS: 0xA0F04
iOS: 0xD0400
Comment 7 Myles C. Maxfield 2020-03-13 16:49:00 PDT
Created attachment 393557 [details]
WIP
Comment 8 Myles C. Maxfield 2020-03-13 18:07:35 PDT
Created attachment 393565 [details]
Patch
Comment 9 Darin Adler 2020-03-15 17:31:24 PDT
Comment on attachment 393565 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393565&action=review

> Source/WTF/wtf/cocoa/LanguageCocoa.mm:44
> +#if PLATFORM(MAC)
> +    static bool applicationVersionCheck = applicationSDKVersion() >= DYLD_MACOSX_VERSION_10_15_4;
> +#elif PLATFORM(IOS)
> +    static bool applicationVersionCheck = applicationSDKVersion() >= DYLD_IOS_VERSION_13_4;
> +#elif
> +    static bool applicationVersionCheck = true;
> +#endif
> +    static bool result = applicationVersionCheck && [NSLocale respondsToSelector:@selector(minimizedLanguagesFromLanguages:)];

I suggest static const bool or static constexpr for all of these.

But also, not elegant to have two globals since the first is only used to compute the second. So write it like this:

    static const bool result = [] {
#if PLATFORM(MAC)
        if (applicationSDKVersion() < DYLD_MACOSX_VERSION_10_15_4)
            return false;
#endif
#if PLATFORM(IOS)
        if (applicationSDKVersion() < DYLD_IOS_VERSION_13_4)
            return false;
#elif
        return [NSLocale respondsToSelector:@selector(minimizedLanguagesFromLanguages:)];
    }();
Comment 10 Myles C. Maxfield 2020-03-17 19:17:08 PDT
Created attachment 393810 [details]
Patch for committing
Comment 11 EWS 2020-03-18 12:28:44 PDT
Committed r258658: <https://trac.webkit.org/changeset/258658>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 393810 [details].