Changeset 197261 in webkit


Ignore:
Timestamp:
Feb 27, 2016 4:36:01 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Intl.Collator uses POSIX locale (detected by js/intl-collator.html on iOS Simulator)
https://bugs.webkit.org/show_bug.cgi?id=152448

Patch by Andy VanWagoner <thetalecrafter@gmail.com> on 2016-02-27
Reviewed by Darin Adler.

Source/JavaScriptCore:

Add defaultLanguage to the globalObjectMethodTable and use it for the
default locale in Intl object initializations. Fall back to ICU default
locale only if the defaultLanguage function is null, or returns an
empty string.

  • jsc.cpp:
  • runtime/IntlCollator.cpp:

(JSC::IntlCollator::initializeCollator):

  • runtime/IntlDateTimeFormat.cpp:

(JSC::IntlDateTimeFormat::initializeDateTimeFormat):

  • runtime/IntlNumberFormat.cpp:

(JSC::IntlNumberFormat::initializeNumberFormat):

  • runtime/IntlObject.cpp:

(JSC::defaultLocale):
(JSC::lookupMatcher):
(JSC::bestFitMatcher):
(JSC::resolveLocale):

  • runtime/IntlObject.h:
  • runtime/JSGlobalObject.cpp:
  • runtime/JSGlobalObject.h:
  • runtime/StringPrototype.cpp:

(JSC::toLocaleCase):

Source/WebCore:

Pass defaultLanguage from Language.h to the globalObjectMethodTable to
ensure Intl objects can be initialized with the correct default locale.

  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSWorkerGlobalScopeBase.cpp:

LayoutTests:

Add tests for default locale in test runner to be en-US.

  • js/intl-collator-expected.txt:
  • js/intl-datetimeformat-expected.txt:
  • js/intl-numberformat-expected.txt:
  • js/script-tests/intl-collator.js:
  • js/script-tests/intl-datetimeformat.js:
  • js/script-tests/intl-numberformat.js:
Location:
trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r197260 r197261  
     12016-02-27  Andy VanWagoner  <thetalecrafter@gmail.com>
     2
     3        Intl.Collator uses POSIX locale (detected by js/intl-collator.html on iOS Simulator)
     4        https://bugs.webkit.org/show_bug.cgi?id=152448
     5
     6        Reviewed by Darin Adler.
     7
     8        Add tests for default locale in test runner to be en-US.
     9
     10        * js/intl-collator-expected.txt:
     11        * js/intl-datetimeformat-expected.txt:
     12        * js/intl-numberformat-expected.txt:
     13        * js/script-tests/intl-collator.js:
     14        * js/script-tests/intl-datetimeformat.js:
     15        * js/script-tests/intl-numberformat.js:
     16
    1172016-02-27  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/LayoutTests/js/intl-collator-expected.txt

    r194253 r197261  
    2020PASS class DerivedCollator extends Intl.Collator {};Object.getPrototypeOf(new DerivedCollator) === DerivedCollator.prototype is true
    2121PASS class DerivedCollator extends Intl.Collator {};Object.getPrototypeOf(Object.getPrototypeOf(new DerivedCollator)) === Intl.Collator.prototype is true
     22PASS testCollator(Intl.Collator(), [{locale: 'en-US'}]) is true
    2223PASS testCollator(Intl.Collator('en'), [{locale: 'en'}]) is true
    2324PASS testCollator(Intl.Collator('eN-uS'), [{locale: 'en-US'}]) is true
  • trunk/LayoutTests/js/intl-datetimeformat-expected.txt

    r195138 r197261  
    8484PASS Intl.DateTimeFormat('$') threw exception RangeError: invalid language tag: $.
    8585PASS Intl.DateTimeFormat('en', null) threw exception TypeError: null is not an object (evaluating 'Intl.DateTimeFormat('en', null)').
     86PASS Intl.DateTimeFormat().resolvedOptions().locale is 'en-US'
    8687PASS Intl.DateTimeFormat('en').resolvedOptions().weekday is undefined
    8788PASS Intl.DateTimeFormat('en').resolvedOptions().era is undefined
  • trunk/LayoutTests/js/intl-numberformat-expected.txt

    r196850 r197261  
    1313PASS class DerivedNumberFormat extends Intl.NumberFormat {};Object.getPrototypeOf(new DerivedNumberFormat) === DerivedNumberFormat.prototype is true
    1414PASS class DerivedNumberFormat extends Intl.NumberFormat {};Object.getPrototypeOf(Object.getPrototypeOf(new DerivedNumberFormat)) === Intl.NumberFormat.prototype is true
     15PASS testNumberFormat(Intl.NumberFormat(), [{locale: 'en-US'}]) is true
    1516PASS testNumberFormat(Intl.NumberFormat('en'), [{locale: 'en'}]) is true
    1617PASS testNumberFormat(Intl.NumberFormat('eN-uS'), [{locale: 'en-US'}]) is true
  • trunk/LayoutTests/js/script-tests/intl-collator.js

    r194253 r197261  
    4444
    4545// Locale is processed correctly.
     46shouldBeTrue("testCollator(Intl.Collator(), [{locale: 'en-US'}])");
    4647shouldBeTrue("testCollator(Intl.Collator('en'), [{locale: 'en'}])");
    4748shouldBeTrue("testCollator(Intl.Collator('eN-uS'), [{locale: 'en-US'}])");
  • trunk/LayoutTests/js/script-tests/intl-datetimeformat.js

    r195138 r197261  
    164164shouldThrow("Intl.DateTimeFormat('$')", "'RangeError: invalid language tag: $'");
    165165shouldThrow("Intl.DateTimeFormat('en', null)", '"TypeError: null is not an object (evaluating \'Intl.DateTimeFormat(\'en\', null)\')"');
     166
     167// Defaults to en-US locale in test runner
     168shouldBe("Intl.DateTimeFormat().resolvedOptions().locale", "'en-US'");
    166169
    167170// Defaults to month, day, year.
  • trunk/LayoutTests/js/script-tests/intl-numberformat.js

    r196850 r197261  
    4242
    4343// Locale is processed correctly.
     44shouldBeTrue("testNumberFormat(Intl.NumberFormat(), [{locale: 'en-US'}])");
    4445shouldBeTrue("testNumberFormat(Intl.NumberFormat('en'), [{locale: 'en'}])");
    4546shouldBeTrue("testNumberFormat(Intl.NumberFormat('eN-uS'), [{locale: 'en-US'}])");
  • trunk/Source/JavaScriptCore/ChangeLog

    r197256 r197261  
     12016-02-27  Andy VanWagoner  <thetalecrafter@gmail.com>
     2
     3        Intl.Collator uses POSIX locale (detected by js/intl-collator.html on iOS Simulator)
     4        https://bugs.webkit.org/show_bug.cgi?id=152448
     5
     6        Reviewed by Darin Adler.
     7
     8        Add defaultLanguage to the globalObjectMethodTable and use it for the
     9        default locale in Intl object initializations. Fall back to ICU default
     10        locale only if the defaultLanguage function is null, or returns an
     11        empty string.
     12
     13        * jsc.cpp:
     14        * runtime/IntlCollator.cpp:
     15        (JSC::IntlCollator::initializeCollator):
     16        * runtime/IntlDateTimeFormat.cpp:
     17        (JSC::IntlDateTimeFormat::initializeDateTimeFormat):
     18        * runtime/IntlNumberFormat.cpp:
     19        (JSC::IntlNumberFormat::initializeNumberFormat):
     20        * runtime/IntlObject.cpp:
     21        (JSC::defaultLocale):
     22        (JSC::lookupMatcher):
     23        (JSC::bestFitMatcher):
     24        (JSC::resolveLocale):
     25        * runtime/IntlObject.h:
     26        * runtime/JSGlobalObject.cpp:
     27        * runtime/JSGlobalObject.h:
     28        * runtime/StringPrototype.cpp:
     29        (JSC::toLocaleCase):
     30
    1312016-02-27  Oliver Hunt  <oliver@apple.com>
    232
  • trunk/Source/JavaScriptCore/jsc.cpp

    r196948 r197261  
    780780
    781781const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, nullptr, CREATE_METHOD_TABLE(GlobalObject) };
    782 const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, 0, &shouldInterruptScriptBeforeTimeout, &moduleLoaderResolve, &moduleLoaderFetch, nullptr, nullptr, nullptr };
     782const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, 0, &shouldInterruptScriptBeforeTimeout, &moduleLoaderResolve, &moduleLoaderFetch, nullptr, nullptr, nullptr, nullptr };
    783783
    784784
  • trunk/Source/JavaScriptCore/runtime/IntlCollator.cpp

    r196887 r197261  
    251251    // 18. Let r be ResolveLocale(%Collator%.[[availableLocales]], requestedLocales, opt, relevantExtensionKeys, localeData).
    252252    auto& availableLocales = state.callee()->globalObject()->intlCollatorAvailableLocales();
    253     auto result = resolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, WTF_ARRAY_LENGTH(relevantExtensionKeys), localeData);
     253    auto result = resolveLocale(state, availableLocales, requestedLocales, opt, relevantExtensionKeys, WTF_ARRAY_LENGTH(relevantExtensionKeys), localeData);
    254254
    255255    // 19. Set collator.[[locale]] to the value of r.[[locale]].
  • trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp

    r196887 r197261  
    450450    // 11. Let localeData be the value of %DateTimeFormat%.[[localeData]].
    451451    // 12. Let r be ResolveLocale( %DateTimeFormat%.[[availableLocales]], requestedLocales, opt, %DateTimeFormat%.[[relevantExtensionKeys]], localeData).
    452     const HashSet<String> availableLocales = exec.lexicalGlobalObject()->intlDateTimeFormatAvailableLocales();
    453     HashMap<String, String> resolved = resolveLocale(availableLocales, requestedLocales, localeOpt, relevantExtensionKeys, WTF_ARRAY_LENGTH(relevantExtensionKeys), localeData);
     452    const HashSet<String> availableLocales = exec.callee()->globalObject()->intlDateTimeFormatAvailableLocales();
     453    HashMap<String, String> resolved = resolveLocale(exec, availableLocales, requestedLocales, localeOpt, relevantExtensionKeys, WTF_ARRAY_LENGTH(relevantExtensionKeys), localeData);
    454454
    455455    // 13. Set dateTimeFormat.[[locale]] to the value of r.[[locale]].
  • trunk/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp

    r196850 r197261  
    197197    // 12. Let r be ResolveLocale(%NumberFormat%.[[availableLocales]], requestedLocales, opt, %NumberFormat%.[[relevantExtensionKeys]], localeData).
    198198    auto& availableLocales = state.callee()->globalObject()->intlNumberFormatAvailableLocales();
    199     auto result = resolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, WTF_ARRAY_LENGTH(relevantExtensionKeys), localeData);
     199    auto result = resolveLocale(state, availableLocales, requestedLocales, opt, relevantExtensionKeys, WTF_ARRAY_LENGTH(relevantExtensionKeys), localeData);
    200200
    201201    // 13. Set numberFormat.[[locale]] to the value of r.[[locale]].
  • trunk/Source/JavaScriptCore/runtime/IntlObject.cpp

    r196887 r197261  
    113113{
    114114    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
    115 }
    116 
    117 String defaultLocale()
    118 {
    119     // 6.2.4 DefaultLocale ()
    120     String locale = uloc_getDefault();
    121     convertICULocaleToBCP47LanguageTag(locale);
    122     return locale;
    123115}
    124116
     
    651643}
    652644
     645String defaultLocale(ExecState& state)
     646{
     647    // 6.2.4 DefaultLocale ()
     648    if (auto defaultLanguage = state.callee()->globalObject()->globalObjectMethodTable()->defaultLanguage) {
     649        String locale = defaultLanguage();
     650        if (!locale.isEmpty())
     651            return canonicalizeLanguageTag(locale);
     652    }
     653    String locale = uloc_getDefault();
     654    convertICULocaleToBCP47LanguageTag(locale);
     655    return locale;
     656}
     657
    653658String removeUnicodeLocaleExtension(const String& locale)
    654659{
     
    673678}
    674679
    675 static MatcherResult lookupMatcher(const HashSet<String>& availableLocales, const Vector<String>& requestedLocales)
     680static MatcherResult lookupMatcher(ExecState& state, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales)
    676681{
    677682    // 9.2.3 LookupMatcher (availableLocales, requestedLocales) (ECMA-402 2.0)
     
    710715        }
    711716    } else
    712         result.locale = defaultLocale();
     717        result.locale = defaultLocale(state);
    713718    return result;
    714719}
    715720
    716 static MatcherResult bestFitMatcher(const HashSet<String>& availableLocales, const Vector<String>& requestedLocales)
     721static MatcherResult bestFitMatcher(ExecState& state, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales)
    717722{
    718723    // 9.2.4 BestFitMatcher (availableLocales, requestedLocales) (ECMA-402 2.0)
    719724    // FIXME: Implement something better than lookup.
    720     return lookupMatcher(availableLocales, requestedLocales);
    721 }
    722 
    723 HashMap<String, String> resolveLocale(const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, const HashMap<String, String>& options, const char* const relevantExtensionKeys[], size_t relevantExtensionKeyCount, Vector<String> (*localeData)(const String&, size_t))
     725    return lookupMatcher(state, availableLocales, requestedLocales);
     726}
     727
     728HashMap<String, String> resolveLocale(ExecState& state, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, const HashMap<String, String>& options, const char* const relevantExtensionKeys[], size_t relevantExtensionKeyCount, Vector<String> (*localeData)(const String&, size_t))
    724729{
    725730    // 9.2.5 ResolveLocale (availableLocales, requestedLocales, options, relevantExtensionKeys, localeData) (ECMA-402 2.0)
     
    728733
    729734    // 2. If matcher is "lookup", then
    730     MatcherResult (*matcherOperation)(const HashSet<String>&, const Vector<String>&);
     735    MatcherResult (*matcherOperation)(ExecState&, const HashSet<String>&, const Vector<String>&);
    731736    if (matcher == "lookup") {
    732737        // a. Let MatcherOperation be the abstract operation LookupMatcher.
     
    738743
    739744    // 4. Let r be MatcherOperation(availableLocales, requestedLocales).
    740     MatcherResult matcherResult = matcherOperation(availableLocales, requestedLocales);
     745    MatcherResult matcherResult = matcherOperation(state, availableLocales, requestedLocales);
    741746
    742747    // 5. Let foundLocale be the value of r.[[locale]].
  • trunk/Source/JavaScriptCore/runtime/IntlObject.h

    r196434 r197261  
    5858};
    5959
    60 String defaultLocale();
     60String defaultLocale(ExecState&);
    6161void convertICULocaleToBCP47LanguageTag(String& locale);
    6262bool intlBooleanOption(ExecState&, JSValue options, PropertyName, bool& usesFallback);
     
    6464unsigned intlNumberOption(ExecState&, JSValue options, PropertyName, unsigned minimum, unsigned maximum, unsigned fallback);
    6565Vector<String> canonicalizeLocaleList(ExecState&, JSValue locales);
    66 HashMap<String, String> resolveLocale(const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, const HashMap<String, String>& options, const char* const relevantExtensionKeys[], size_t relevantExtensionKeyCount, Vector<String> (*localeData)(const String&, size_t));
     66HashMap<String, String> resolveLocale(ExecState&, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, const HashMap<String, String>& options, const char* const relevantExtensionKeys[], size_t relevantExtensionKeyCount, Vector<String> (*localeData)(const String&, size_t));
    6767JSValue supportedLocales(ExecState&, const HashSet<String>& availableLocales, const Vector<String>& requestedLocales, JSValue options);
    6868String removeUnicodeLocaleExtension(const String& locale);
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r196967 r197261  
    177177const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
    178178
    179 const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, nullptr, &shouldInterruptScriptBeforeTimeout, nullptr, nullptr, nullptr, nullptr, nullptr };
     179const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, nullptr, &shouldInterruptScriptBeforeTimeout, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
    180180
    181181/* Source for JSGlobalObject.lut.h
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r196966 r197261  
    174174    typedef JSValue (*ModuleLoaderEvaluatePtr)(JSGlobalObject*, ExecState*, JSValue, JSValue);
    175175    ModuleLoaderEvaluatePtr moduleLoaderEvaluate;
     176
     177    typedef String (*DefaultLanguageFunctionPtr)();
     178    DefaultLanguageFunctionPtr defaultLanguage;
    176179};
    177180
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp

    r196721 r197261  
    15011501    // 8. Else
    15021502    // a. Let requestedLocale be DefaultLocale().
    1503     String requestedLocale = len > 0 ? requestedLocales.first() : defaultLocale();
     1503    String requestedLocale = len > 0 ? requestedLocales.first() : defaultLocale(*state);
    15041504
    15051505    // 9. Let noExtensionsLocale be the String value that is requestedLocale with all Unicode locale extension sequences (6.2.1) removed.
  • trunk/Source/WebCore/ChangeLog

    r197260 r197261  
     12016-02-27  Andy VanWagoner  <thetalecrafter@gmail.com>
     2
     3        Intl.Collator uses POSIX locale (detected by js/intl-collator.html on iOS Simulator)
     4        https://bugs.webkit.org/show_bug.cgi?id=152448
     5
     6        Reviewed by Darin Adler.
     7
     8        Pass defaultLanguage from Language.h to the globalObjectMethodTable to
     9        ensure Intl objects can be initialized with the correct default locale.
     10
     11        * bindings/js/JSDOMWindowBase.cpp:
     12        * bindings/js/JSWorkerGlobalScopeBase.cpp:
     13
    1142016-02-27  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp

    r196165 r197261  
    3535#include "JSModuleLoader.h"
    3636#include "JSNode.h"
     37#include "Language.h"
    3738#include "Logging.h"
    3839#include "Page.h"
     
    6465const ClassInfo JSDOMWindowBase::s_info = { "Window", &JSDOMGlobalObject::s_info, 0, CREATE_METHOD_TABLE(JSDOMWindowBase) };
    6566
    66 const GlobalObjectMethodTable JSDOMWindowBase::s_globalObjectMethodTable = { &shouldAllowAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, &queueTaskToEventLoop, &shouldInterruptScriptBeforeTimeout, &moduleLoaderResolve, &moduleLoaderFetch, nullptr, nullptr, &moduleLoaderEvaluate };
     67const GlobalObjectMethodTable JSDOMWindowBase::s_globalObjectMethodTable = { &shouldAllowAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, &queueTaskToEventLoop, &shouldInterruptScriptBeforeTimeout, &moduleLoaderResolve, &moduleLoaderFetch, nullptr, nullptr, &moduleLoaderEvaluate, &defaultLanguage };
    6768
    6869JSDOMWindowBase::JSDOMWindowBase(VM& vm, Structure* structure, PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell)
  • trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp

    r196165 r197261  
    3434#include "JSDedicatedWorkerGlobalScope.h"
    3535#include "JSWorkerGlobalScope.h"
     36#include "Language.h"
    3637#include "WorkerGlobalScope.h"
    3738#include <runtime/JSCJSValueInlines.h>
     
    4445const ClassInfo JSWorkerGlobalScopeBase::s_info = { "WorkerGlobalScope", &JSDOMGlobalObject::s_info, 0, CREATE_METHOD_TABLE(JSWorkerGlobalScopeBase) };
    4546
    46 const GlobalObjectMethodTable JSWorkerGlobalScopeBase::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, &queueTaskToEventLoop, &shouldInterruptScriptBeforeTimeout, nullptr, nullptr, nullptr, nullptr, nullptr };
     47const GlobalObjectMethodTable JSWorkerGlobalScopeBase::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsLegacyProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, &queueTaskToEventLoop, &shouldInterruptScriptBeforeTimeout, nullptr, nullptr, nullptr, nullptr, nullptr, &defaultLanguage };
    4748
    4849JSWorkerGlobalScopeBase::JSWorkerGlobalScopeBase(JSC::VM& vm, JSC::Structure* structure, PassRefPtr<WorkerGlobalScope> impl)
Note: See TracChangeset for help on using the changeset viewer.