Changeset 261182 in webkit


Ignore:
Timestamp:
May 5, 2020 11:21:32 AM (4 years ago)
Author:
Ross Kirsling
Message:

[Intl] Alphabetize extension keys and correctly mark const methods
https://bugs.webkit.org/show_bug.cgi?id=211359

Reviewed by Darin Adler.

JSTests:

  • stress/intl-collator.js:
  • stress/intl-datetimeformat.js:

Add tests.

Source/JavaScriptCore:

Two cleanup items for Intl classes:

  1. Ensure resolvedOptions().locale returns relevant extension keys in alphabetical order. ICU does this for us via Intl.getCanonicalLocales / Intl.*.supportedLocalesOf but not via ResolveLocale. However, we don't need to do any sorting in ResolveLocale; we can just pre-alphabetize relevantExtensionKeys. (See also https://github.com/tc39/ecma402/pull/433.)
  1. Ensure Intl classes are marking const methods correctly.
  • runtime/IntlCollator.cpp:

(JSC::IntlCollator::sortLocaleData):
(JSC::IntlCollator::searchLocaleData):
(JSC::IntlCollator::compareStrings const): Add const specifier.
(JSC::IntlCollator::resolvedOptions const): Add const specifier.

  • runtime/IntlCollator.h:
  • runtime/IntlDateTimeFormat.cpp:

(JSC::IntlDateTimeFormat::localeData):
(JSC::IntlDateTimeFormat::resolvedOptions const): Add const specifier.
(JSC::IntlDateTimeFormat::format const): Add const specifier.
(JSC::IntlDateTimeFormat::formatToParts const): Add const specifier.

  • runtime/IntlDateTimeFormat.h:
  • runtime/IntlNumberFormat.cpp:

(JSC::IntlNumberFormat::format const): Add const specifier.
(JSC::IntlNumberFormat::resolvedOptions const): Add const specifier.
(JSC::IntlNumberFormat::formatToParts const): Add const specifier.

  • runtime/IntlNumberFormat.h:
  • runtime/IntlPluralRules.cpp:

(JSC::IntlPluralRules::resolvedOptions const): Add const specifier.
(JSC::IntlPluralRules::select const): Add const specifier.

  • runtime/IntlPluralRules.h:
  • runtime/IntlRelativeTimeFormat.cpp:

(JSC::IntlRelativeTimeFormat::resolvedOptions const): Add const specifier.
(JSC::IntlRelativeTimeFormat::formatInternal const): Add const specifier.
(JSC::IntlRelativeTimeFormat::format const): Add const specifier.
(JSC::IntlRelativeTimeFormat::formatToParts const): Add const specifier.

  • runtime/IntlRelativeTimeFormat.h:
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r261175 r261182  
     12020-05-05  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        [Intl] Alphabetize extension keys and correctly mark const methods
     4        https://bugs.webkit.org/show_bug.cgi?id=211359
     5
     6        Reviewed by Darin Adler.
     7
     8        * stress/intl-collator.js:
     9        * stress/intl-datetimeformat.js:
     10        Add tests.
     11
    1122020-05-05  Keith Miller  <keith_miller@apple.com>
    213
  • trunk/JSTests/stress/intl-collator.js

    r260697 r261182  
    406406    shouldBe(JSON.stringify(options), '{"usage":"sort","sensitivity":"variant","ignorePunctuation":false,"collation":"default","numeric":false,"caseFirst":"false"}');
    407407}
     408
     409shouldBe(new Intl.Collator('de-u-kn-false-kf-upper-co-phonebk-hc-h12').resolvedOptions().locale, 'de-u-co-phonebk-kf-upper-kn-false');
  • trunk/JSTests/stress/intl-datetimeformat.js

    r260697 r261182  
    215215shouldThrow(() => Intl.DateTimeFormat('en', null), TypeError);
    216216
     217shouldBe(new Intl.DateTimeFormat('en-u-nu-latn-hc-h12-ca-gregory-kf-upper').resolvedOptions().locale, 'en-u-ca-gregory-hc-h12-nu-latn');
     218
    217219// Defaults to month, day, year.
    218220shouldBe(Intl.DateTimeFormat('en').resolvedOptions().weekday, undefined);
  • trunk/Source/JavaScriptCore/ChangeLog

    r261181 r261182  
     12020-05-05  Ross Kirsling  <ross.kirsling@sony.com>
     2
     3        [Intl] Alphabetize extension keys and correctly mark const methods
     4        https://bugs.webkit.org/show_bug.cgi?id=211359
     5
     6        Reviewed by Darin Adler.
     7
     8        Two cleanup items for Intl classes:
     9
     10        1. Ensure `resolvedOptions().locale` returns relevant extension keys in alphabetical order.
     11           ICU does this for us via Intl.getCanonicalLocales / Intl.*.supportedLocalesOf but not via ResolveLocale.
     12           However, we don't need to do any sorting in ResolveLocale; we can just pre-alphabetize relevantExtensionKeys.
     13           (See also https://github.com/tc39/ecma402/pull/433.)
     14
     15        2. Ensure Intl classes are marking const methods correctly.
     16
     17        * runtime/IntlCollator.cpp:
     18        (JSC::IntlCollator::sortLocaleData):
     19        (JSC::IntlCollator::searchLocaleData):
     20        (JSC::IntlCollator::compareStrings const): Add const specifier.
     21        (JSC::IntlCollator::resolvedOptions const): Add const specifier.
     22        * runtime/IntlCollator.h:
     23        * runtime/IntlDateTimeFormat.cpp:
     24        (JSC::IntlDateTimeFormat::localeData):
     25        (JSC::IntlDateTimeFormat::resolvedOptions const): Add const specifier.
     26        (JSC::IntlDateTimeFormat::format const): Add const specifier.
     27        (JSC::IntlDateTimeFormat::formatToParts const): Add const specifier.
     28        * runtime/IntlDateTimeFormat.h:
     29        * runtime/IntlNumberFormat.cpp:
     30        (JSC::IntlNumberFormat::format const): Add const specifier.
     31        (JSC::IntlNumberFormat::resolvedOptions const): Add const specifier.
     32        (JSC::IntlNumberFormat::formatToParts const): Add const specifier.
     33        * runtime/IntlNumberFormat.h:
     34        * runtime/IntlPluralRules.cpp:
     35        (JSC::IntlPluralRules::resolvedOptions const): Add const specifier.
     36        (JSC::IntlPluralRules::select const): Add const specifier.
     37        * runtime/IntlPluralRules.h:
     38        * runtime/IntlRelativeTimeFormat.cpp:
     39        (JSC::IntlRelativeTimeFormat::resolvedOptions const): Add const specifier.
     40        (JSC::IntlRelativeTimeFormat::formatInternal const): Add const specifier.
     41        (JSC::IntlRelativeTimeFormat::format const): Add const specifier.
     42        (JSC::IntlRelativeTimeFormat::formatToParts const): Add const specifier.
     43        * runtime/IntlRelativeTimeFormat.h:
     44
    1452020-05-05  Keith Miller  <keith_miller@apple.com>
    246
  • trunk/Source/JavaScriptCore/runtime/IntlCollator.cpp

    r260984 r261182  
    4545
    4646namespace IntlCollatorInternal {
    47 constexpr const char* const relevantExtensionKeys[3] = { "co", "kn", "kf" };
     47constexpr const char* relevantExtensionKeys[3] = { "co", "kf", "kn" };
    4848constexpr size_t collationIndex = 0;
    49 constexpr size_t numericIndex = 1;
    50 constexpr size_t caseFirstIndex = 2;
     49constexpr size_t caseFirstIndex = 1;
     50constexpr size_t numericIndex = 2;
    5151}
    5252
     
    124124        break;
    125125    }
    126     case IntlCollatorInternal::numericIndex:
    127         keyLocaleData.reserveInitialCapacity(2);
    128         keyLocaleData.uncheckedAppend("false"_s);
    129         keyLocaleData.uncheckedAppend("true"_s);
    130         break;
    131126    case IntlCollatorInternal::caseFirstIndex:
    132127        keyLocaleData.reserveInitialCapacity(3);
     
    134129        keyLocaleData.uncheckedAppend("lower"_s);
    135130        keyLocaleData.uncheckedAppend("upper"_s);
     131        break;
     132    case IntlCollatorInternal::numericIndex:
     133        keyLocaleData.reserveInitialCapacity(2);
     134        keyLocaleData.uncheckedAppend("false"_s);
     135        keyLocaleData.uncheckedAppend("true"_s);
    136136        break;
    137137    default:
     
    151151        keyLocaleData.append({ });
    152152        break;
    153     case IntlCollatorInternal::numericIndex:
    154         keyLocaleData.reserveInitialCapacity(2);
    155         keyLocaleData.uncheckedAppend("false"_s);
    156         keyLocaleData.uncheckedAppend("true"_s);
    157         break;
    158153    case IntlCollatorInternal::caseFirstIndex:
    159154        keyLocaleData.reserveInitialCapacity(3);
     
    161156        keyLocaleData.uncheckedAppend("lower"_s);
    162157        keyLocaleData.uncheckedAppend("upper"_s);
     158        break;
     159    case IntlCollatorInternal::numericIndex:
     160        keyLocaleData.reserveInitialCapacity(2);
     161        keyLocaleData.uncheckedAppend("false"_s);
     162        keyLocaleData.uncheckedAppend("true"_s);
    163163        break;
    164164    default:
     
    296296
    297297// https://tc39.es/ecma402/#sec-collator-comparestrings
    298 JSValue IntlCollator::compareStrings(JSGlobalObject* globalObject, StringView x, StringView y)
     298JSValue IntlCollator::compareStrings(JSGlobalObject* globalObject, StringView x, StringView y) const
    299299{
    300300    ASSERT(m_collator);
     
    370370
    371371// https://tc39.es/ecma402/#sec-intl.collator.prototype.resolvedoptions
    372 JSObject* IntlCollator::resolvedOptions(JSGlobalObject* globalObject)
     372JSObject* IntlCollator::resolvedOptions(JSGlobalObject* globalObject) const
    373373{
    374374    VM& vm = globalObject->vm();
  • trunk/Source/JavaScriptCore/runtime/IntlCollator.h

    r260931 r261182  
    5757
    5858    void initializeCollator(JSGlobalObject*, JSValue locales, JSValue optionsValue);
    59     JSValue compareStrings(JSGlobalObject*, StringView, StringView);
    60     JSObject* resolvedOptions(JSGlobalObject*);
     59    JSValue compareStrings(JSGlobalObject*, StringView, StringView) const;
     60    JSObject* resolvedOptions(JSGlobalObject*) const;
    6161
    6262    JSBoundFunction* boundCompare() const { return m_boundCompare.get(); }
  • trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp

    r260984 r261182  
    4848
    4949namespace IntlDateTimeFormatInternal {
    50 constexpr const char* relevantExtensionKeys[3] = { "ca", "nu", "hc" };
     50constexpr const char* relevantExtensionKeys[3] = { "ca", "hc", "nu" };
    5151constexpr size_t calendarIndex = 0;
    52 constexpr size_t numberingSystemIndex = 1;
    53 constexpr size_t hourCycleIndex = 2;
     52constexpr size_t hourCycleIndex = 1;
     53constexpr size_t numberingSystemIndex = 2;
    5454}
    5555
     
    210210        break;
    211211    }
    212     case IntlDateTimeFormatInternal::numberingSystemIndex:
    213         keyLocaleData = numberingSystemsForLocale(locale);
    214         break;
    215212    case IntlDateTimeFormatInternal::hourCycleIndex:
    216213        // Null default so we know to use 'j' in pattern.
     
    220217        keyLocaleData.append("h23"_s);
    221218        keyLocaleData.append("h24"_s);
     219        break;
     220    case IntlDateTimeFormatInternal::numberingSystemIndex:
     221        keyLocaleData = numberingSystemsForLocale(locale);
    222222        break;
    223223    default:
     
    839839
    840840// https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions
    841 JSObject* IntlDateTimeFormat::resolvedOptions(JSGlobalObject* globalObject)
     841JSObject* IntlDateTimeFormat::resolvedOptions(JSGlobalObject* globalObject) const
    842842{
    843843    VM& vm = globalObject->vm();
     
    885885
    886886// https://tc39.es/ecma402/#sec-formatdatetime
    887 JSValue IntlDateTimeFormat::format(JSGlobalObject* globalObject, double value)
     887JSValue IntlDateTimeFormat::format(JSGlobalObject* globalObject, double value) const
    888888{
    889889    ASSERT(m_dateFormat);
     
    972972
    973973// https://tc39.es/ecma402/#sec-formatdatetimetoparts
    974 JSValue IntlDateTimeFormat::formatToParts(JSGlobalObject* globalObject, double value)
     974JSValue IntlDateTimeFormat::formatToParts(JSGlobalObject* globalObject, double value) const
    975975{
    976976    ASSERT(m_dateFormat);
  • trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h

    r260931 r261182  
    5656
    5757    void initializeDateTimeFormat(JSGlobalObject*, JSValue locales, JSValue options);
    58     JSValue format(JSGlobalObject*, double value);
    59     JSValue formatToParts(JSGlobalObject*, double value);
    60     JSObject* resolvedOptions(JSGlobalObject*);
     58    JSValue format(JSGlobalObject*, double value) const;
     59    JSValue formatToParts(JSGlobalObject*, double value) const;
     60    JSObject* resolvedOptions(JSGlobalObject*) const;
    6161
    6262    JSBoundFunction* boundFormat() const { return m_boundFormat.get(); }
  • trunk/Source/JavaScriptCore/runtime/IntlNumberFormat.cpp

    r260984 r261182  
    341341
    342342// https://tc39.es/ecma402/#sec-formatnumber
    343 JSValue IntlNumberFormat::format(JSGlobalObject* globalObject, double value)
     343JSValue IntlNumberFormat::format(JSGlobalObject* globalObject, double value) const
    344344{
    345345    ASSERT(m_numberFormat);
     
    363363
    364364// https://tc39.es/ecma402/#sec-formatnumber
    365 JSValue IntlNumberFormat::format(JSGlobalObject* globalObject, JSBigInt* value)
     365JSValue IntlNumberFormat::format(JSGlobalObject* globalObject, JSBigInt* value) const
    366366{
    367367    ASSERT(m_numberFormat);
     
    419419
    420420// https://tc39.es/ecma402/#sec-intl.numberformat.prototype.resolvedoptions
    421 JSObject* IntlNumberFormat::resolvedOptions(JSGlobalObject* globalObject)
     421JSObject* IntlNumberFormat::resolvedOptions(JSGlobalObject* globalObject) const
    422422{
    423423    VM& vm = globalObject->vm();
     
    528528
    529529// https://tc39.github.io/ecma402/#sec-formatnumbertoparts
    530 JSValue IntlNumberFormat::formatToParts(JSGlobalObject* globalObject, double value)
     530JSValue IntlNumberFormat::formatToParts(JSGlobalObject* globalObject, double value) const
    531531{
    532532    ASSERT(m_numberFormat);
  • trunk/Source/JavaScriptCore/runtime/IntlNumberFormat.h

    r260931 r261182  
    5757
    5858    void initializeNumberFormat(JSGlobalObject*, JSValue locales, JSValue optionsValue);
    59     JSValue format(JSGlobalObject*, double);
    60     JSValue format(JSGlobalObject*, JSBigInt*);
    61     JSValue formatToParts(JSGlobalObject*, double);
    62     JSObject* resolvedOptions(JSGlobalObject*);
     59    JSValue format(JSGlobalObject*, double) const;
     60    JSValue format(JSGlobalObject*, JSBigInt*) const;
     61    JSValue formatToParts(JSGlobalObject*, double) const;
     62    JSObject* resolvedOptions(JSGlobalObject*) const;
    6363
    6464    JSBoundFunction* boundFormat() const { return m_boundFormat.get(); }
  • trunk/Source/JavaScriptCore/runtime/IntlPluralRules.cpp

    r260931 r261182  
    183183
    184184// https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions
    185 JSObject* IntlPluralRules::resolvedOptions(JSGlobalObject* globalObject)
     185JSObject* IntlPluralRules::resolvedOptions(JSGlobalObject* globalObject) const
    186186{
    187187    ASSERT(m_pluralRules);
     
    225225
    226226// https://tc39.es/ecma402/#sec-resolveplural
    227 JSValue IntlPluralRules::select(JSGlobalObject* globalObject, double value)
     227JSValue IntlPluralRules::select(JSGlobalObject* globalObject, double value) const
    228228{
    229229    ASSERT(m_pluralRules);
  • trunk/Source/JavaScriptCore/runtime/IntlPluralRules.h

    r260931 r261182  
    5555
    5656    void initializePluralRules(JSGlobalObject*, JSValue locales, JSValue options);
    57     JSValue select(JSGlobalObject*, double value);
    58     JSObject* resolvedOptions(JSGlobalObject*);
     57    JSValue select(JSGlobalObject*, double value) const;
     58    JSObject* resolvedOptions(JSGlobalObject*) const;
    5959
    6060private:
  • trunk/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.cpp

    r260931 r261182  
    184184
    185185// https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
    186 JSObject* IntlRelativeTimeFormat::resolvedOptions(JSGlobalObject* globalObject)
     186JSObject* IntlRelativeTimeFormat::resolvedOptions(JSGlobalObject* globalObject) const
    187187{
    188188    VM& vm = globalObject->vm();
     
    226226}
    227227
    228 String IntlRelativeTimeFormat::formatInternal(JSGlobalObject* globalObject, double value, StringView unit)
     228String IntlRelativeTimeFormat::formatInternal(JSGlobalObject* globalObject, double value, StringView unit) const
    229229{
    230230    ASSERT(m_relativeDateTimeFormatter);
     
    263263
    264264// https://tc39.es/ecma402/#sec-FormatRelativeTime
    265 JSValue IntlRelativeTimeFormat::format(JSGlobalObject* globalObject, double value, StringView unit)
     265JSValue IntlRelativeTimeFormat::format(JSGlobalObject* globalObject, double value, StringView unit) const
    266266{
    267267    VM& vm = globalObject->vm();
     
    275275
    276276// https://tc39.es/ecma402/#sec-FormatRelativeTimeToParts
    277 JSValue IntlRelativeTimeFormat::formatToParts(JSGlobalObject* globalObject, double value, StringView unit)
     277JSValue IntlRelativeTimeFormat::formatToParts(JSGlobalObject* globalObject, double value, StringView unit) const
    278278{
    279279    VM& vm = globalObject->vm();
  • trunk/Source/JavaScriptCore/runtime/IntlRelativeTimeFormat.h

    r260931 r261182  
    5454
    5555    void initializeRelativeTimeFormat(JSGlobalObject*, JSValue locales, JSValue options);
    56     JSValue format(JSGlobalObject*, double, StringView unitString);
    57     JSValue formatToParts(JSGlobalObject*, double, StringView unitString);
    58     JSObject* resolvedOptions(JSGlobalObject*);
     56    JSValue format(JSGlobalObject*, double, StringView unitString) const;
     57    JSValue formatToParts(JSGlobalObject*, double, StringView unitString) const;
     58    JSObject* resolvedOptions(JSGlobalObject*) const;
    5959
    6060private:
     
    6565    static Vector<String> localeData(const String&, size_t);
    6666
    67     String formatInternal(JSGlobalObject*, double, StringView unit);
     67    String formatInternal(JSGlobalObject*, double, StringView unit) const;
    6868
    6969    struct URelativeDateTimeFormatterDeleter {
Note: See TracChangeset for help on using the changeset viewer.