Changeset 201066 in webkit


Ignore:
Timestamp:
May 17, 2016 7:11:19 PM (8 years ago)
Author:
fpizlo@apple.com
Message:

JSC should detect the right default locale even when it's not embedded in WebCore
https://bugs.webkit.org/show_bug.cgi?id=157755
rdar://problem/24665424

Reviewed by Keith Miller.

This makes JSC try to use WTF's platform user preferred language detection if the DOM did
not register a defaultLanguage callback. The result is that when JSC runs standalone it
will detect the platform user preferred language almost the same way as when it's embedded
in WebCore. The only difference is that WebCore may have its own additional overrides via
the WK API. But in the absence of overrides, WebCore uses the same WTF logic that JSC falls
back to.

We first found this bug because on iOS, the intl tests would fail because ICU would report
a somewhat bogus locale on that platform. Prior to this change, standalone JSC would fall
back to ICU's locale detection. It turns out that the ICU default locale is also bogus on
OS X, just less so. For example, setting things to Poland did not result in the jsc shell
printing dates Polish-style. Now it will print them Polish-style if your system preferences
say so. Also, the tests don't fail on iOS anymore.

  • runtime/IntlObject.cpp:

(JSC::defaultLocale):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r201051 r201066  
     12016-05-17  Filip Pizlo  <fpizlo@apple.com>
     2
     3        JSC should detect the right default locale even when it's not embedded in WebCore
     4        https://bugs.webkit.org/show_bug.cgi?id=157755
     5        rdar://problem/24665424
     6
     7        Reviewed by Keith Miller.
     8       
     9        This makes JSC try to use WTF's platform user preferred language detection if the DOM did
     10        not register a defaultLanguage callback. The result is that when JSC runs standalone it
     11        will detect the platform user preferred language almost the same way as when it's embedded
     12        in WebCore. The only difference is that WebCore may have its own additional overrides via
     13        the WK API. But in the absence of overrides, WebCore uses the same WTF logic that JSC falls
     14        back to.
     15       
     16        We first found this bug because on iOS, the intl tests would fail because ICU would report
     17        a somewhat bogus locale on that platform. Prior to this change, standalone JSC would fall
     18        back to ICU's locale detection. It turns out that the ICU default locale is also bogus on
     19        OS X, just less so. For example, setting things to Poland did not result in the jsc shell
     20        printing dates Polish-style. Now it will print them Polish-style if your system preferences
     21        say so. Also, the tests don't fail on iOS anymore.
     22       
     23        * runtime/IntlObject.cpp:
     24        (JSC::defaultLocale):
     25
    1262016-05-17  Dean Jackson  <dino@apple.com>
    227
  • trunk/Source/JavaScriptCore/runtime/IntlObject.cpp

    r197539 r201066  
    22 * Copyright (C) 2015 Andy VanWagoner (thetalecrafter@gmail.com)
    33 * Copyright (C) 2015 Sukolsak Sakshuwong (sukolsak@gmail.com)
     4 * Copyright (C) 2016 Apple Inc. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    4950#include <wtf/Assertions.h>
    5051#include <wtf/NeverDestroyed.h>
     52#include <wtf/PlatformUserPreferredLanguages.h>
    5153
    5254namespace JSC {
     
    646648{
    647649    // 6.2.4 DefaultLocale ()
     650   
     651    // WebCore's global objects will have their own ideas of how to determine the language. It may
     652    // be determined by WebCore-specific logic like some WK settings. Usually this will return the
     653    // same thing as platformUserPreferredLanguages()[0].
    648654    if (auto defaultLanguage = state.callee()->globalObject()->globalObjectMethodTable()->defaultLanguage) {
    649655        String locale = defaultLanguage();
     
    651657            return canonicalizeLanguageTag(locale);
    652658    }
     659   
     660    // If WebCore isn't around to tell us how to get the language then fall back to our own way of
     661    // doing it, which mostly follows what WebCore would have done.
     662    Vector<String> languages = platformUserPreferredLanguages();
     663    if (!languages.isEmpty() && !languages[0].isEmpty())
     664        return canonicalizeLanguageTag(languages[0]);
     665   
     666    // If all else fails, ask ICU. It will probably say something bogus like en_us even if the user
     667    // has configured some other language, but being wrong is better than crashing.
    653668    String locale = uloc_getDefault();
    654669    convertICULocaleToBCP47LanguageTag(locale);
Note: See TracChangeset for help on using the changeset viewer.